www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - dmd AST class hierarchy as dot file

reply Guillaume Chatelet <chatelet.guillaume gmail.com> writes:
Not sure if it can be useful to someone else but I extracted the 
dmd's class hierarchy as a DOT file:

digraph dlang_ast {
     AddAssignExp -> BinAssignExp;
     AddExp -> BinExp;
     AddrExp -> UnaExp;
     AggregateDeclaration -> ScopeDsymbol;
     AliasDeclaration -> Declaration;
     AliasThis -> Dsymbol;
     AlignDeclaration -> AttribDeclaration;
     AndAndExp -> BinExp;
     AndAssignExp -> BinAssignExp;
     AndExp -> BinExp;
     AnonDeclaration -> AttribDeclaration;
     ArrayExp -> UnaExp;
     ArrayInitializer -> Initializer;
     ArrayLengthExp -> UnaExp;
     ArrayLiteralExp -> Expression;
     ArrayScopeSymbol -> ScopeDsymbol;
     AsmStatement -> Statement;
     AssertExp -> UnaExp;
     AssignExp -> BinExp;
     AssocArrayLiteralExp -> Expression;
     AttribDeclaration -> Dsymbol;
     BinAssignExp -> BinExp;
     BinExp -> Expression;
     BlitExp -> AssignExp;
     BoolExp -> UnaExp;
     BreakStatement -> Statement;
     CallExp -> UnaExp;
     CaseRangeStatement -> Statement;
     CaseStatement -> Statement;
     CastExp -> UnaExp;
     CatAssignExp -> BinAssignExp;
     CatExp -> BinExp;
     ClassDeclaration -> AggregateDeclaration;
     ClassReferenceExp -> Expression;
     CmpExp -> BinExp;
     ComExp -> UnaExp;
     CommaExp -> BinExp;
     CompileDeclaration -> AttribDeclaration;
     CompileExp -> UnaExp;
     CompileStatement -> Statement;
     ComplexExp -> Expression;
     CompoundAsmStatement -> CompoundStatement;
     CompoundDeclarationStatement -> CompoundStatement;
     CompoundStatement -> Statement;
     CondExp -> BinExp;
     ConditionalDeclaration -> AttribDeclaration;
     ConditionalStatement -> Statement;
     ConstructExp -> AssignExp;
     ContinueStatement -> Statement;
     CtorDeclaration -> FuncDeclaration;
     DVCondition -> Condition;
     DebugCondition -> DVCondition;
     DebugStatement -> Statement;
     DebugSymbol -> Dsymbol;
     Declaration -> Dsymbol;
     DeclarationExp -> Expression;
     DefaultInitExp -> Expression;
     DefaultStatement -> Statement;
     DelegateExp -> UnaExp;
     DelegateFuncptrExp -> UnaExp;
     DelegatePtrExp -> UnaExp;
     DeleteDeclaration -> FuncDeclaration;
     DeleteExp -> UnaExp;
     DeprecatedDeclaration -> StorageClassDeclaration;
     DivAssignExp -> BinAssignExp;
     DivExp -> BinExp;
     DoStatement -> Statement;
     DollarExp -> IdentifierExp;
     DotExp -> BinExp;
     DotIdExp -> UnaExp;
     DotTemplateExp -> UnaExp;
     DotTemplateInstanceExp -> UnaExp;
     DotTypeExp -> UnaExp;
     DotVarExp -> UnaExp;
     DsymbolExp -> Expression;
     DtorDeclaration -> FuncDeclaration;
     DtorExpStatement -> ExpStatement;
     EnumDeclaration -> ScopeDsymbol;
     EnumMember -> Dsymbol;
     EqualExp -> BinExp;
     ErrorExp -> Expression;
     ErrorInitializer -> Initializer;
     ErrorStatement -> Statement;
     ExpInitializer -> Initializer;
     ExpStatement -> Statement;
     FileExp -> UnaExp;
     FileInitExp -> DefaultInitExp;
     ForStatement -> Statement;
     ForeachRangeStatement -> Statement;
     ForeachStatement -> Statement;
     FuncAliasDeclaration -> FuncDeclaration;
     FuncDeclaration -> Declaration;
     FuncExp -> Expression;
     FuncInitExp -> DefaultInitExp;
     FuncLiteralDeclaration -> FuncDeclaration;
     GotoCaseStatement -> Statement;
     GotoDefaultStatement -> Statement;
     GotoStatement -> Statement;
     HaltExp -> Expression;
     IdentifierExp -> Expression;
     IdentityExp -> BinExp;
     IfStatement -> Statement;
     Import -> Dsymbol;
     ImportStatement -> Statement;
     InExp -> BinExp;
     IndexExp -> BinExp;
     IntegerExp -> Expression;
     InterfaceDeclaration -> ClassDeclaration;
     IntervalExp -> Expression;
     InvariantDeclaration -> FuncDeclaration;
     IsExp -> Expression;
     LabelDsymbol -> Dsymbol;
     LabelStatement -> Statement;
     LineInitExp -> DefaultInitExp;
     LinkDeclaration -> AttribDeclaration;
     MinAssignExp -> BinAssignExp;
     MinExp -> BinExp;
     ModAssignExp -> BinAssignExp;
     ModExp -> BinExp;
     Module -> Package;
     ModuleInitExp -> DefaultInitExp;
     MulAssignExp -> BinAssignExp;
     MulExp -> BinExp;
     NegExp -> UnaExp;
     NewAnonClassExp -> Expression;
     NewDeclaration -> FuncDeclaration;
     NewExp -> Expression;
     NotExp -> UnaExp;
     Nspace -> ScopeDsymbol;
     NullExp -> Expression;
     OnScopeStatement -> Statement;
     OrAssignExp -> BinAssignExp;
     OrExp -> BinExp;
     OrOrExp -> BinExp;
     OverDeclaration -> Declaration;
     OverExp -> Expression;
     OverloadSet -> Dsymbol;
     Package -> ScopeDsymbol;
     PeelStatement -> Statement;
     PostBlitDeclaration -> FuncDeclaration;
     PostExp -> BinExp;
     PowAssignExp -> BinAssignExp;
     PowExp -> BinExp;
     PragmaDeclaration -> AttribDeclaration;
     PragmaStatement -> Statement;
     PreExp -> UnaExp;
     PrettyFuncInitExp -> DefaultInitExp;
     ProtDeclaration -> AttribDeclaration;
     PtrExp -> UnaExp;
     RealExp -> Expression;
     RemoveExp -> BinExp;
     ReturnStatement -> Statement;
     ScopeDsymbol -> Dsymbol;
     ScopeExp -> Expression;
     ScopeStatement -> Statement;
     SharedStaticCtorDeclaration -> StaticCtorDeclaration;
     SharedStaticDtorDeclaration -> StaticDtorDeclaration;
     ShlAssignExp -> BinAssignExp;
     ShlExp -> BinExp;
     ShrAssignExp -> BinAssignExp;
     ShrExp -> BinExp;
     SliceExp -> UnaExp;
     StaticAssert -> Dsymbol;
     StaticAssertStatement -> Statement;
     StaticCtorDeclaration -> FuncDeclaration;
     StaticDtorDeclaration -> FuncDeclaration;
     StaticIfCondition -> Condition;
     StaticIfDeclaration -> ConditionalDeclaration;
     StorageClassDeclaration -> AttribDeclaration;
     StringExp -> Expression;
     StructDeclaration -> AggregateDeclaration;
     StructInitializer -> Initializer;
     StructLiteralExp -> Expression;
     SuperExp -> ThisExp;
     SwitchErrorStatement -> Statement;
     SwitchStatement -> Statement;
     SymOffExp -> SymbolExp;
     SymbolDeclaration -> Declaration;
     SymbolExp -> Expression;
     SynchronizedStatement -> Statement;
     TemplateAliasParameter -> TemplateParameter;
     TemplateDeclaration -> ScopeDsymbol;
     TemplateExp -> Expression;
     TemplateInstance -> ScopeDsymbol;
     TemplateMixin -> TemplateInstance;
     TemplateThisParameter -> TemplateTypeParameter;
     TemplateTupleParameter -> TemplateParameter;
     TemplateTypeParameter -> TemplateParameter;
     TemplateValueParameter -> TemplateParameter;
     ThisDeclaration -> VarDeclaration;
     ThisExp -> Expression;
     ThrowStatement -> Statement;
     ThrownExceptionExp -> Expression;
     TraitsExp -> Expression;
     TryCatchStatement -> Statement;
     TryFinallyStatement -> Statement;
     TupleDeclaration -> Declaration;
     TupleExp -> Expression;
     TypeAArray -> TypeArray;
     TypeArray -> TypeNext;
     TypeBasic -> Type;
     TypeClass -> Type;
     TypeDArray -> TypeArray;
     TypeDelegate -> TypeNext;
     TypeEnum -> Type;
     TypeError -> Type;
     TypeExp -> Expression;
     TypeFunction -> TypeNext;
     TypeIdentifier -> TypeQualified;
     TypeInfoArrayDeclaration -> TypeInfoDeclaration;
     TypeInfoAssociativeArrayDeclaration -> TypeInfoDeclaration;
     TypeInfoClassDeclaration -> TypeInfoDeclaration;
     TypeInfoConstDeclaration -> TypeInfoDeclaration;
     TypeInfoDeclaration -> VarDeclaration;
     TypeInfoDelegateDeclaration -> TypeInfoDeclaration;
     TypeInfoEnumDeclaration -> TypeInfoDeclaration;
     TypeInfoFunctionDeclaration -> TypeInfoDeclaration;
     TypeInfoInterfaceDeclaration -> TypeInfoDeclaration;
     TypeInfoInvariantDeclaration -> TypeInfoDeclaration;
     TypeInfoPointerDeclaration -> TypeInfoDeclaration;
     TypeInfoSharedDeclaration -> TypeInfoDeclaration;
     TypeInfoStaticArrayDeclaration -> TypeInfoDeclaration;
     TypeInfoStructDeclaration -> TypeInfoDeclaration;
     TypeInfoTupleDeclaration -> TypeInfoDeclaration;
     TypeInfoVectorDeclaration -> TypeInfoDeclaration;
     TypeInfoWildDeclaration -> TypeInfoDeclaration;
     TypeInstance -> TypeQualified;
     TypeNext -> Type;
     TypeNull -> Type;
     TypePointer -> TypeNext;
     TypeQualified -> Type;
     TypeReference -> TypeNext;
     TypeReturn -> TypeQualified;
     TypeSArray -> TypeArray;
     TypeSlice -> TypeNext;
     TypeStruct -> Type;
     TypeTuple -> Type;
     TypeTypeof -> TypeQualified;
     TypeVector -> Type;
     TypeidExp -> Expression;
     UAddExp -> UnaExp;
     UnaExp -> Expression;
     UnionDeclaration -> StructDeclaration;
     UnitTestDeclaration -> FuncDeclaration;
     UnrolledLoopStatement -> Statement;
     UserAttributeDeclaration -> AttribDeclaration;
     UshrAssignExp -> BinAssignExp;
     UshrExp -> BinExp;
     VarDeclaration -> Declaration;
     VarExp -> SymbolExp;
     VectorExp -> UnaExp;
     VersionCondition -> DVCondition;
     VersionSymbol -> Dsymbol;
     VoidInitExp -> Expression;
     VoidInitializer -> Initializer;
     WhileStatement -> Statement;
     WithScopeSymbol -> ScopeDsymbol;
     WithStatement -> Statement;
     XorAssignExp -> BinAssignExp;
     XorExp -> BinExp;
}
Sep 20 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 09/20/2015 05:26 AM, Guillaume Chatelet wrote:
 Not sure if it can be useful to someone else but I extracted the dmd's
 class hierarchy as a DOT file:
[snip] That's great. I haven't used dot in a long time, any particular flags to invoke it etc? It would be great to include the grammar graph build as an optional target in the dlang.org makefile so we can publish the resulting .gif on the site. Guillaume, could you put a PR together? Thanks, Andrei
Sep 20 2015
next sibling parent reply David Nadlinger <code klickverbot.at> writes:
On Sunday, 20 September 2015 at 17:26:22 UTC, Andrei Alexandrescu 
wrote:
 It would be great to include the grammar graph build as an 
 optional target in the dlang.org makefile so we can publish the 
 resulting .gif on the site. Guillaume, could you put a PR 
 together?
Not sure how helpful this would be for users as it merely describes the DMD internals. For example, AggregateDeclarations are not Declarations. — David
Sep 20 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 09/20/2015 01:33 PM, David Nadlinger wrote:
 On Sunday, 20 September 2015 at 17:26:22 UTC, Andrei Alexandrescu wrote:
 It would be great to include the grammar graph build as an optional
 target in the dlang.org makefile so we can publish the resulting .gif
 on the site. Guillaume, could you put a PR together?
Not sure how helpful this would be for users as it merely describes the DMD internals. For example, AggregateDeclarations are not Declarations.
Aren't all those nonterminals part of the grammar spec? -- Andrei
Sep 20 2015
parent reply David Nadlinger <code klickverbot.at> writes:
On Sunday, 20 September 2015 at 17:38:18 UTC, Andrei Alexandrescu 
wrote:
 Aren't all those nonterminals part of the grammar spec? --
From http://dlang.org/declaration.html: --- Declaration: FuncDeclaration VarDeclarations AliasDeclaration AggregateDeclaration ImportDeclaration --- which is not how the AST class hierarchy in the compiler looks. This is not to say that having pretty pictures for both of them can't be useful. However, you seemed to assume that the GraphViz file by Guillaume represented the grammar structure, and I wanted to point out that it does not (at least not directly). — David
Sep 20 2015
next sibling parent Guillaume Chatelet <chatelet.guillaume gmail.com> writes:
On Sunday, 20 September 2015 at 17:46:33 UTC, David Nadlinger 
wrote:
 which is not how the AST class hierarchy in the compiler looks.

 This is not to say that having pretty pictures for both of them 
 can't be useful. However, you seemed to assume that the 
 GraphViz file by Guillaume represented the grammar structure, 
 and I wanted to point out that it does not (at least not 
 directly).

  — David
Yes this is pretty dmd specific but since I'm trying (again) to fix linux/OSX CPP name mangling I need a comprehensive description of dmd's internals. I'm also not convinced this is currently achievable. eg. template<typename A, typename B> void foo(A, B) {}; template void foo<int, int>(int, int); // mangled as _Z3fooIiiEvT_T0_ This template instantiation is mangled as `_Z3fooIiiEvT_T0_`. First argument type is substituted with T_ (ie. first int which is encoded i in the function). Second argument type is substituted with T0_ (ie. second int which is encoded i in the function). dmd's internal will not create two different objects to represent the type int. So when encoding the argument types you have int and you can't know which one it is. Walter, if you have any idea :) I'm still struggling to understand the semantic of the fields of all the AST types. This is important because is you reverse the arguments, then the type is mangled as `_Z3fooIiiEvT0_T_` (Note the inversion of T_ and T0_). template<typename A, typename B> void foo(B, A) {}; template void foo<int, int>(int, int); // mangled as _Z3fooIiiEvT0_T_
Sep 20 2015
prev sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 09/20/2015 01:46 PM, David Nadlinger wrote:
 you seemed to assume that the GraphViz file by Guillaume represented the
 grammar structure, and I wanted to point out that it does not (at least
 not directly).
Thanks, yah, so I assumed. I guess both would be useful! -- Andrei
Sep 20 2015
parent Guillaume Chatelet <chatelet.guillaume gmail.com> writes:
On Sunday, 20 September 2015 at 18:52:40 UTC, Andrei Alexandrescu 
wrote:
 On 09/20/2015 01:46 PM, David Nadlinger wrote:
 you seemed to assume that the GraphViz file by Guillaume 
 represented the
 grammar structure, and I wanted to point out that it does not 
 (at least
 not directly).
Thanks, yah, so I assumed. I guess both would be useful! -- Andrei
Added the rendered image to http://wiki.dlang.org/DMD_Source_Guide#Class_hierarchy
Sep 20 2015
prev sibling parent Guillaume Chatelet <chatelet.guillaume gmail.com> writes:
On Sunday, 20 September 2015 at 17:26:22 UTC, Andrei Alexandrescu 
wrote:
 On 09/20/2015 05:26 AM, Guillaume Chatelet wrote:
 Not sure if it can be useful to someone else but I extracted 
 the dmd's
 class hierarchy as a DOT file:
[snip] That's great. I haven't used dot in a long time, any particular flags to invoke it etc?
dot -Tpng dlang_ast.dot > dlang_ast.png dot -Tsvg dlang_ast.dot > dlang_ast.svg // great because `find` works in a browser
 It would be great to include the grammar graph build as an 
 optional target in the dlang.org makefile so we can publish the 
 resulting .gif on the site. Guillaume, could you put a PR 
 together?
As David mentioned I'm not sure it will be that useful. Probably only to people working directly in dmd. Interestingly enough, with ddmd I'm almost sure it can now be automatically generated at compile time by class introspection :)
Sep 20 2015