feat: Rudamentary class support
parent
989e7bce2b
commit
a6979dd3d4
|
@ -48,6 +48,9 @@ structure StructureInfo extends Info where
|
||||||
ctor : (Name × Syntax)
|
ctor : (Name × Syntax)
|
||||||
deriving Repr
|
deriving Repr
|
||||||
|
|
||||||
|
structure ClassInfo extends StructureInfo where
|
||||||
|
hasOutParam : Bool
|
||||||
|
|
||||||
inductive DocInfo where
|
inductive DocInfo where
|
||||||
| axiomInfo (info : AxiomInfo) : DocInfo
|
| axiomInfo (info : AxiomInfo) : DocInfo
|
||||||
| theoremInfo (info : TheoremInfo) : DocInfo
|
| theoremInfo (info : TheoremInfo) : DocInfo
|
||||||
|
@ -55,7 +58,7 @@ inductive DocInfo where
|
||||||
| definitionInfo (info : DefinitionInfo) : DocInfo
|
| definitionInfo (info : DefinitionInfo) : DocInfo
|
||||||
| inductiveInfo (info : InductiveInfo) : DocInfo
|
| inductiveInfo (info : InductiveInfo) : DocInfo
|
||||||
| structureInfo (info : StructureInfo) : DocInfo
|
| structureInfo (info : StructureInfo) : DocInfo
|
||||||
| classInfo : DocInfo
|
| classInfo (info : ClassInfo) : DocInfo
|
||||||
| classInductiveInfo : DocInfo
|
| classInductiveInfo : DocInfo
|
||||||
|
|
||||||
structure Module where
|
structure Module where
|
||||||
|
@ -114,6 +117,10 @@ def StructureInfo.ofInductiveVal (v : InductiveVal) : MetaM StructureInfo := do
|
||||||
| some i => return StructureInfo.mk info i.fieldInfo parents (ctor, ctorType)
|
| some i => return StructureInfo.mk info i.fieldInfo parents (ctor, ctorType)
|
||||||
| none => panic! s!"{v.name} is not a structure"
|
| none => panic! s!"{v.name} is not a structure"
|
||||||
|
|
||||||
|
def ClassInfo.ofInductiveVal (v : InductiveVal) : MetaM ClassInfo := do
|
||||||
|
let sinfo ← StructureInfo.ofInductiveVal v
|
||||||
|
return ClassInfo.mk sinfo $ hasOutParams (←getEnv) v.name
|
||||||
|
|
||||||
namespace DocInfo
|
namespace DocInfo
|
||||||
|
|
||||||
def isBlackListed (declName : Name) : MetaM Bool := do
|
def isBlackListed (declName : Name) : MetaM Bool := do
|
||||||
|
@ -159,8 +166,12 @@ def ofConstant : (Name × ConstantInfo) → MetaM (Option DocInfo) := λ (name,
|
||||||
some $ definitionInfo (←DefinitionInfo.ofDefinitionVal i)
|
some $ definitionInfo (←DefinitionInfo.ofDefinitionVal i)
|
||||||
-- TODO: Differentiate between all the different types of inductives (structures, classes etc.)
|
-- TODO: Differentiate between all the different types of inductives (structures, classes etc.)
|
||||||
| ConstantInfo.inductInfo i =>
|
| ConstantInfo.inductInfo i =>
|
||||||
if isStructure (←getEnv) i.name then
|
let env ← getEnv
|
||||||
some $ structureInfo (←StructureInfo.ofInductiveVal i)
|
if isStructure env i.name then
|
||||||
|
if isClass env i.name then
|
||||||
|
some $ classInfo (←ClassInfo.ofInductiveVal i)
|
||||||
|
else
|
||||||
|
some $ structureInfo (←StructureInfo.ofInductiveVal i)
|
||||||
else
|
else
|
||||||
some $ inductiveInfo (←InductiveInfo.ofInductiveVal i)
|
some $ inductiveInfo (←InductiveInfo.ofInductiveVal i)
|
||||||
-- we ignore these for now
|
-- we ignore these for now
|
||||||
|
@ -181,6 +192,9 @@ def prettyPrint (i : DocInfo) : CoreM String := do
|
||||||
| structureInfo i =>
|
| structureInfo i =>
|
||||||
let ctorString ← s!"{i.ctor.fst} : {←PrettyPrinter.formatTerm i.ctor.snd}"
|
let ctorString ← s!"{i.ctor.fst} : {←PrettyPrinter.formatTerm i.ctor.snd}"
|
||||||
s!"structure {i.name} : {←PrettyPrinter.formatTerm i.type}, ctor: {ctorString}, doc string: {i.doc}"
|
s!"structure {i.name} : {←PrettyPrinter.formatTerm i.type}, ctor: {ctorString}, doc string: {i.doc}"
|
||||||
|
| classInfo i =>
|
||||||
|
let ctorString ← s!"{i.ctor.fst} : {←PrettyPrinter.formatTerm i.ctor.snd}"
|
||||||
|
s!"class {i.name} : {←PrettyPrinter.formatTerm i.type}, ctor: {ctorString}, doc string: {i.doc}"
|
||||||
| _ => ""
|
| _ => ""
|
||||||
|
|
||||||
end DocInfo
|
end DocInfo
|
||||||
|
|
Loading…
Reference in New Issue