Verified Commit 3592e224 authored by Camil Staps's avatar Camil Staps 🚀

Resolve clean-cloogle/cloogle.org#140: documentation of constructors passed on...

Resolve clean-cloogle/cloogle.org#140: documentation of constructors passed on in constructor_functions
parent a2be92b3
......@@ -64,13 +64,14 @@ from CloogleDB import :: Location(Location), filterLocations,
:: FunctionEntry{fe_type,fe_kind,fe_generic_vars,fe_priority,fe_representation,fe_documentation},
instance zero FunctionEntry, instance zero ModuleEntry
from Doc import :: Documentation(FunctionDoc), :: ResultDoc, :: VarDoc,
:: ParamDoc, :: Description, :: TypeRhsDoc(RecordDoc), :: RecordFieldDoc,
:: ClassMemberDoc,
:: ParamDoc, :: Description, :: TypeRhsDoc(ADTDoc,RecordDoc),
:: RecordFieldDoc, :: ClassMemberDoc,
:: ParseWarning(UsedReturn,IllegalField), :: ParseError(IllegalState),
parseFunctionDoc, parseConstructorDoc, parseADTypeDoc, parseRecordTypeDoc,
parseSynonymTypeDoc, parseAbstractTypeDoc, parseFieldDoc, parseClassDoc,
parseModuleDoc, traceParseError, traceParseWarnings, getTypeRhsDoc,
getTypeDoc, functionToClassMemberDoc, addClassMemberDoc
getTypeDoc, constructorToFunctionDoc, functionToClassMemberDoc,
addClassMemberDoc
:: TemporaryDB
= { temp_functions :: ![[(!'DB'.Location, !'DB'.FunctionEntry)]]
......@@ -506,13 +507,19 @@ constructor_functions etd
, fe_type=Just f
, fe_representation=Just $ concat $ [c] ++ print_prio p ++ [" :: "] ++ print False f
, fe_priority=p
, fe_documentation=constructorToFunctionDoc <$> doc
})
\\ (c,f,p) <- 'T'.constructorsToFunctions ('DB'.getTypeDef etd)]
\\ (c,f,p) <- 'T'.constructorsToFunctions ('DB'.getTypeDef etd)
& doc <- cons_doc]
where
print_prio :: (Maybe 'T'.Priority) -> [String]
print_prio Nothing = []
print_prio (Just p) = [" "] ++ print False p
cons_doc = case getTypeRhsDoc =<< 'DB'.getTypeDefDoc etd of
Just (ADTDoc conses) -> conses ++ repeat Nothing
_ -> repeat Nothing
record_functions :: 'DB'.TypeDefEntry -> [('DB'.Name, 'DB'.FunctionEntry)]
record_functions etd
= [(f,
......@@ -526,8 +533,8 @@ record_functions etd
& doc <- field_doc]
where
field_doc = case getTypeRhsDoc =<< 'DB'.getTypeDefDoc etd of
Just (RecordDoc fields) = fields ++ repeat Nothing
_ = repeat Nothing
Just (RecordDoc fields) -> fields ++ repeat Nothing
_ -> repeat Nothing
instance == (a,b,c,d) | == a & == b & == c & == d
where == (a,b,c,d) (p,q,r,s) = a == p && b == q && c == r && d == s
......@@ -152,6 +152,12 @@ getConstructorDoc :: Documentation -> Maybe [Maybe Documentation]
*/
getRepresentationDoc :: Documentation -> Maybe Description
/**
* Convert a ConstructorDoc to a FunctionDoc.
* This gives a run-time error if the first parameter is not a ConstructorDoc.
*/
constructorToFunctionDoc :: Documentation -> Documentation
/**
* Convert a FunctionDoc to a ClassMemberDoc.
* This gives a run-time error if the first parameter is not a FunctionDoc.
......
......@@ -81,6 +81,9 @@ getRepresentationDoc doc = case getTypeRhsDoc doc of
Just (SynonymDoc d) = d
_ = Nothing
constructorToFunctionDoc :: Documentation -> Documentation
constructorToFunctionDoc (ConstructorDoc d ps) = FunctionDoc d ps [] Nothing Nothing
functionToClassMemberDoc :: Documentation -> ClassMemberDoc
functionToClassMemberDoc (FunctionDoc d ps _ r _) = ClassMemberDoc d ps r
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment