1
2
3
4
5
6 #ifndef GENDOC_HTML_SOURCE_CODE_GENERATOR_INCLUDED
7 #define GENDOC_HTML_SOURCE_CODE_GENERATOR_INCLUDED
8 #include <gendoc/html/HtmlSourceCodeWriter.hpp>
9 #include <gendoc/html/HtmlContentFilePathResolver.hpp>
10 #include <sngcpp/symbols/SymbolTable.hpp>
11 #include <sngcpp/ast/Visitor.hpp>
12 #include <sngcpp/ast/SourceFile.hpp>
13
14 namespace gendoc { namespace html {
15
16 using namespace sngcpp::symbols;
17
18 class HtmlSourceCodeGenerator : public sngcpp::ast::Visitor
19 {
20 public:
21 HtmlSourceCodeGenerator(const std::u32string& projectName_, const std::std::vector<std::u32string>&inputLines_, intnumDigits_, conststd::string&styleDirName_, conststd::string& styleFileName_,
22 SymbolTable& symbolTable_, int inlineCodeLimit_, std::std::unordered_map<std::u32string, std::std::unique_ptr<sngxml::dom::Element>>&inlineCodeMap_,
23 HtmlContentFilePathResolver* contentFilePathResolver_);
24 std::u32string MakeSymbolRef(Symbol* symbol);
25 std::u32string MakeInlineSymbolRef(Symbol* symbol);
26 void WriteId(IdentifierNode* id, Symbol* symbol, bool writeType);
27 void WriteIdSequence(bool writeType, Symbol* terminalSymbol);
28 void WriteType(TypeSymbol* type, const std::std::vector<IdentifierNode*>&idNodeSequence, TemplateIdNode*templateIdNode);
29 void WriteDocument();
30 void MoveTo(const Span& span);
31 void OpenLine();
32 void OpenInlineLine();
33 void CloseLine();
34 void UseInputLine();
35 void WriteRestOfInput();
36 void WriteSpecifiers(Specifier specifiers);
37 void WriteAccess(const Span& span, Specifier access);
38 void Visit(SourceFileNode& sourceFileNode) override;
39 void Visit(NamespaceNode& namespaceNode) override;
40 void Visit(SimpleDeclarationNode& simpleDeclarationNode) override;
41 void Visit(AliasDeclarationNode& aliasDeclarationNode) override;
42 void Visit(DeclarationSequenceNode& declarationSequenceNode) override;
43 void Visit(ForwardClassDeclarationNode& forwardClassDeclarationNode) override;
44 void Visit(ElaborateClassNameNode& elaborateClassNameNode) override;
45 void Visit(ClassNode& classNode) override;
46 void Visit(BaseClassSpecifierNode& baseClassSpecifierNode) override;
47 void Visit(BaseClassSpecifierSequenceNode& baseClassSpecifierSequenceNode) override;
48 void Visit(MemberAccessDeclarationNode& memberAccessDeclarationNode) override;
49 void Visit(MemberDeclarationNode& memberDeclarationNode) override;
50 void Visit(FloatingLiteralNode& floatingLiteralNode) override;
51 void Visit(IntegerLiteralNode& integerLiteralNode) override;
52 void Visit(CharacterLiteralNode& characterLiteralNode) override;
53 void Visit(StringLiteralNode& stringLiteralNode) override;
54 void Visit(BooleanLiteralNode& booleanLiteralNode) override;
55 void Visit(NullPtrLiteralNode& nullPtrLiteralNode) override;
56 void Visit(FunctionNode& functionNode) override;
57 void Visit(SpecialMemberFunctionNode& specialMemberFunctionNode) override;
58 void Visit(LabeledStatementNode& labeledStatementNode) override;
59 void Visit(CaseStatementNode& caseStatementNode) override;
60 void Visit(DefaultStatementNode& defaultStatementNode) override;
61 void Visit(ExpressionStatementNode& expressionStatementNode) override;
62 void Visit(CompoundStatementNode& compoundStatementNode) override;
63 void Visit(StatementSequenceNode& statementSequenceNode) override;
64 void Visit(IfStatementNode& ifStatementNode) override;
65 void Visit(SwitchStatementNode& switchStatementNode) override;
66 void Visit(WhileStatementNode& whileStatementNode) override;
67 void Visit(DoStatementNode& doStatementNode) override;
68 void Visit(RangeForStatementNode& rangeForStatementNode) override;
69 void Visit(ForStatementNode& forStatementNode) override;
70 void Visit(BreakStatementNode& breakStatementNode) override;
71 void Visit(ContinueStatementNode& continueStatementNode) override;
72 void Visit(ReturnStatementNode& returnStatementNode) override;
73 void Visit(GotoStatementNode& gotoStatementNode) override;
74 void Visit(DeclarationStatementNode& declarationStatementNode) override;
75 void Visit(TryStatementNode& tryStatementNode) override;
76 void Visit(HandlerNode& handlerNode) override;
77 void Visit(HandlerSequenceNode& handlerSequenceNode) override;
78 void Visit(CatchAllNode& catchAllNode) override;
79 void Visit(CtorInitializerNode& ctorInitializerNode) override;
80 void Visit(ExpressionListInitializerNode& expressionListInitializer) override;
81 void Visit(AssignmentInitializerNode& assignmentInitializerNode) override;
82 void Visit(ExpressionInitializerNode& expressionInitializerNode) override;
83 void Visit(EnumTypeNode& enumTypeNode) override;
84 void Visit(EnumeratorNode& enumeratorNode) override;
85 void Visit(EnumeratorSequenceNode& enumeratorSequenceNode) override;
86 void Visit(ExpressionSequenceNode& expressionSequenceNode) override;
87 void Visit(CommaExpressionNode& commaExpressionNode) override;
88 void Visit(AssignmentExpressionNode& assignmentExpressionNode) override;
89 void Visit(ConditionalExpressionNode& conditionalExpressionNode) override;
90 void Visit(ThrowExpressionNode& throwExpressionNode) override;
91 void Visit(LogicalOrExpressionNode& logicalOrExpressionNode) override;
92 void Visit(LogicalAndExpressionNode& logicalAndExpressionNode) override;
93 void Visit(InclusiveOrExpressionNode& inclusiveOrExpressionNode) override;
94 void Visit(ExclusiveOrExpressionNode& exclusiveOrExpressionNode) override;
95 void Visit(AndExpressionNode& andExpressionNode) override;
96 void Visit(EqualityExpressionNode& equalityExpressionNode) override;
97 void Visit(RelationalExpressionNode& relationalExpressionNode) override;
98 void Visit(ShiftExpressionNode& shiftExpressionNode) override;
99 void Visit(AdditiveExpressionNode& additiveExpressionNode) override;
100 void Visit(MultiplicativeExpressionNode& multiplicativeExpressionNode) override;
101 void Visit(PMExpressionNode& pmExpressionNode) override;
102 void Visit(CastExpressionNode& castExpressionNode) override;
103 void Visit(UnaryExpressionNode& unaryExpressionNode) override;
104 void Visit(NewExpressionNode& newExpressionNode) override;
105 void Visit(DeleteExpressionNode& deleteExpressionNode) override;
106 void Visit(SubscriptExpressionNode& subscriptExpressionNode) override;
107 void Visit(InvokeExpressionNode& invokeExpressionNode) override;
108 void Visit(DotNode& dotNode) override;
109 void Visit(ArrowNode& arrowNode) override;
110 void Visit(PostfixIncNode& postfixIncNode) override;
111 void Visit(PostfixDecNode& postfixDecNode) override;
112 void Visit(CppCastExpressionNode& cppCastExpressionNode) override;
113 void Visit(TypeIdExpressionNode& typeIdExpressionNode) override;
114 void Visit(ThisNode& thisNode) override;
115 void Visit(ParenthesizedExprNode& parenthesizedExprNode) override;
116 void Visit(BracedInitializerListNode& bracedInitializerListNode) override;
117 void Visit(MemberInitializerNode& memberInitializerNode) override;
118 void Visit(MemberInitializerSequenceNode& memberInitializerSequenceNode) override;
119 void Visit(FunctionDeclaratorNode& functionDeclaratorNode) override;
120 void Visit(FunctionPtrIdNode& functionPtrIdNode) override;
121 void Visit(MemberFunctionPtrIdNode& memberFunctionPtrIdNode) override;
122 void Visit(ArrayDeclaratorNode& arrayDeclaratorNode) override;
123 void Visit(InitDeclaratorNode& initDeclaratorNode) override;
124 void Visit(IdDeclaratorNode& idDeclaratorNode) override;
125 void Visit(ParameterNode& parameterNode) override;
126 void Visit(ParameterSequenceNode& parameterSequenceNode) override;
127 void Visit(SimpleTypeNode& simpleTypeNode) override;
128 void Visit(TypeParameterNode& typeParameterNode) override;
129 void Visit(TemplateParameterSequenceNode& templateParameterSequenceNode) override;
130 void Visit(TemplateDeclarationNode& templateDeclarationNode) override;
131 void Visit(TemplateArgumentSequenceNode& templateArgumentSequenceNode) override;
132 void Visit(TemplateIdNode& templateIdNode) override;
133 void Visit(TemplateArgumentNode& templateArgumentNode) override;
134 void Visit(IdentifierNode& identifierNode) override;
135 void Visit(NestedIdNode& nestedIdNode) override;
136 void Visit(OperatorFunctionIdNode& operatorFunctionIdNode) override;
137 void Visit(ConversionFunctionIdNode& conversionFunctionIdNode) override;
138 void Visit(DtorIdNode& dtorIdNode) override;
139 void Visit(LambdaExpressionNode& lambdaExpressionNode) override;
140 void Visit(CaptureSequenceNode& captureSequenceNode) override;
141 void Visit(AssignCaptureNode& assignCaptureNode) override;
142 void Visit(RefCaptureNode& refCaptureNode) override;
143 void Visit(ThisCaptureNode& thisCaptureNode) override;
144 void Visit(IdentifierCaptureNode& identifierCaptureNode) override;
145 void Visit(ConstNode& constNode) override;
146 void Visit(VolatileNode& volatileNode) override;
147 void Visit(PointerNode& pointerNode) override;
148 void Visit(RValueRefNode& rValueRefNode) override;
149 void Visit(LValueRefNode& lValueRefNode) override;
150 private:
151 std::u32string projectName;
152 SymbolTable& symbolTable;
153 FunctionSymbol* currentFunction;
154 Symbol* invokeSymbol;
155 HtmlSourceCodeWriter writer;
156 const std::std::vector<std::u32string>&inputLines;
157 int numDigits;
158 std::string styleFilePath;
159 std::string contentDirPath;
160 int currentSourceLineNumber;
161 std::string htmlFilePath;
162 sngxml::dom::Document htmlSourceFileDocument;
163 std::unique_ptr<sngxml::dom::Element> htmlElement;
164 std::unique_ptr<sngxml::dom::Element> bodyElement;
165 std::unique_ptr<sngxml::dom::Element> lineElement;
166 std::unique_ptr<sngxml::dom::Element> inlineLineElement;
167 std::unique_ptr<sngxml::dom::Element> inlineCodeElement;
168 std::vector<std::std::pair<IdentifierNode*, Symbol*>>idSequence;
169 std::std::vector<int>*lineStarts;
170 bool firstBaseClass;
171 bool firstParam;
172 bool firstTemplateParameter;
173 bool firstTemplateArgument;
174 bool firstMemberInitializer;
175 bool firstInitializer;
176 bool firstEnumerator;
177 bool rangeForDeclaration;
178 int blockLevel;
179 Specifier currentAccess;
180 int inlineCodeLimit;
181 int inlineCodeOffset;
182 bool skip;
183 bool inBlockComment;
184 std::std::unordered_map<std::u32string, std::std::unique_ptr<sngxml::dom::Element>>&inlineCodeMap;
185 HtmlContentFilePathResolver* contentFilePathResolver;
186 };
187
188 } }
189
190 #endif // GENDOC_HTML_SOURCE_CODE_GENERATOR_INCLUDED