1 unit ParseTreeNodeType;
2
3 {
4 This enumeration describes all of the types of parse tree nodes
5 that we are interested in
6 }
7
8 {(*}
9 (*------------------------------------------------------------------------------
10 Delphi Code formatter source code
11
12 The Original Code is ParseTreeNodeType, released May 2003.
13 The Initial Developer of the Original Code is Anthony Steele.
14 Portions created by Anthony Steele are Copyright (C) 1999-2008 Anthony Steele.
15 All Rights Reserved.
16 Contributor(s): Anthony Steele.
17
18 The contents of this file are subject to the Mozilla Public License Version 1.1
19 (the "License"). you may not use this file except in compliance with the License.
20 You may obtain a copy of the License at http://www.mozilla.org/NPL/
21
22 Software distributed under the License is distributed on an "AS IS" basis,
23 WITHOUT WARRANTY OF ANY KIND, either express or implied.
24 See the License for the specific language governing rights and limitations
25 under the License.
26
27 Alternatively, the contents of this file may be used under the terms of
28 the GNU General Public License Version 2 or later (the "GPL")
29 See http://www.gnu.org/licenses/gpl.html
30 ------------------------------------------------------------------------------*)
31 {*)}
32
33 {$I JcfGlobal.inc}
34
35 interface
36
37 type
38 { roles that the interior node can play }
39 TParseTreeNodeType = (
40 nUnknown,
41 nLeaf,
42 nProgram,
43 nUnit,
44 nUnitHeader,
45 nUnitName,
46 nPackage,
47 nLibrary,
48 nUses,
49 nUsesItem,
50 nRequires,
51 nContains,
52 nIdentList,
53 nIdentifier,
54 nInterfaceSection,
55 nImplementationSection,
56 nBlock,
57 nStatementList,
58 nDeclSection,
59 nLabelDeclSection,
60 nConstSection,
61 nConstDecl,
62 nTypeSection,
63 nTypeDecl,
64 nArrayConstant,
65 nRecordConstant,
66 nRecordFieldConstant,
67 nType,
68 nRestrictedType,
69 nSubrangeType,
70 nEnumeratedType,
71 nArrayType,
72 nRecordType,
73 nFieldDeclaration,
74 nRecordVariantSection,
75 nRecordVariant,
76 nSetType,
77 nProcedureType,
78 nVarSection,
79 nVarDecl,
80 nVarAbsolute,
81 nVariableInit,
82 nDesignator,
83 nExpression,
84 nTerm,
85 nUnaryOp,
86 nActualParams,
87 nStatement,
88 nAssignment,
89 nInline,
90 nInlineItem,
91 nStatementLabel,
92 nCompoundStatement,
93 nIfCondition,
94 nIfBlock,
95 nElseBlock,
96 nCaseStatement,
97 nCaseSelector,
98 nCaseLabels,
99 nCaseLabel,
100 nElseCase,
101 nRepeatStatement,
102 nWhileStatement,
103 nLoopHeaderExpr,
104 nBlockHeaderExpr,
105 nForStatement,
106 nWithStatement,
107 nTryAndHandlerBlock,
108 nTryBlock,
109 nFinallyBlock,
110 nExceptBlock,
111 nExceptionHandlers,
112 nOnExceptionHandler,
113 nProcedureDecl,
114 nFunctionDecl,
115 nConstructorDecl,
116 nDestructorDecl,
117 nFunctionHeading,
118 nProcedureHeading,
119 nConstructorHeading,
120 nDestructorHeading,
121 nFormalParams,
122 nFormalParam,
123 nFunctionReturnType,
124 nProcedureDirectives,
125 nExternalDirective,
126 nObjectType,
127 nInitSection,
128 nClassType,
129 nClassHeritage,
130 nClassBody,
131 nClassVisibility,
132 nClassDeclarations,
133 nProperty,
134 nPropertyParameterList,
135 nPropertySpecifier,
136 nInterfaceType,
137 nInterfaceHeritage,
138 nInterfaceTypeGuid,
139 nInterfaceBody,
140 nBracketedQual,
141 nAsm,
142 nAsmStatement,
143 nAsmIdent,
144 nAsmOpcode,
145 nAsmParam,
146 nAsmLabel,
147 nHintDirectives,
148 nPropertyDirective,
149 nExports,
150 nExportedProc,
151 nLiteralString,
152 nHashLiteralChar,
153 nHatLiteralChar,
154 nAttribute,
155 nClassVars,
156 nGeneric,
157 nAnonymousMethod,
158 nMethodReferenceType
159 );
160
161 TParseTreeNodeTypeSet = set of TParseTreeNodeType;
162
163 const
164 DirectiveNodes: TParseTreeNodeTypeSet =
165 [nProcedureDirectives, nExternalDirective, nHintDirectives, nPropertyDirective];
166 ProcedureNodes: TParseTreeNodeTypeSet =
167 [nProcedureDecl, nFunctionDecl, nConstructorDecl, nDestructorDecl];
168 ProcedureHeadings: TParseTreeNodeTypeSet =
169 [nFunctionHeading, nProcedureHeading, nConstructorHeading, nDestructorHeading];
170
171 ObjectTypes: TParseTreeNodeTypeSet = [nObjectType, nClassType, nInterfaceType];
172 ObjectBodies: TParseTreeNodeTypeSet = [nClassBody, nInterfaceBody];
173
174 { can declare these at the start of a procedure }
175 InProcedureDeclSections: TParseTreeNodeTypeSet =
176 [nVarSection, nConstSection, nLabelDeclSection, nTypeSection];
177
178 UsesClauses: TParseTreeNodeTypeSet = [nUses, nRequires, nContains];
179
180 TopOfProgramSections = [nProgram, nPackage, nLibrary];
181
182 TopOfFileSection = [nProgram, nPackage, nLibrary, nUnit];
183
184 { can find these blocks of def/dels outside of anything }
185 nTopLevelSections = [nTypeSection, nConstSection, nVarSection,
186 nLabelDeclSection, nExports];
187
188 MethodDeclarations: TParseTreeNodeTypeSet =
189 [nProcedureDecl, nFunctionDecl, nConstructorDecl, nDestructorDecl];
190 MethodHeadings: TParseTreeNodeTypeSet =
191 [nFunctionHeading, nProcedureHeading, nConstructorHeading, nDestructorHeading];
192
NodeTypeToStringnull193 function NodeTypeToString(const pe: TParseTreeNodeType): string; inline;
194
195 implementation
196
197 uses SysUtils;
198
199 const
200 TreeNodeTypeNames: array[TParseTreeNodeType] of string = (
201 'UnkNown', 'Leaf', 'Program', 'Unit', 'Unit header', 'Unit name', 'Package', 'Library', 'Uses',
202 'Uses Item', 'Requires', 'Contains', 'ident list', 'Identifier', 'Interface section',
203 'Implementation section', 'Block', 'Statement list', 'Decl section', 'Label decl section',
204 'const section', 'Const decl', 'type section', 'Type Decl', 'Array constant', 'Record Constant',
205 'Field constant', 'Type', 'Restricted type', 'Subrange type', 'Enumerated type', 'Array type',
206 'record type', 'Field declarations', 'Record variant section', 'Record variant', 'Set type',
207 'procedure type', 'Var section', 'Var decl', 'Absolute var', 'Variable init', 'Designator',
208 'Expression', 'Term', 'Unary op', 'Actual params', 'Statement', 'Assignment', 'Inline',
209 'Inline item', 'Statement label', 'Compound statement', 'If Condition', 'If Block', 'Else block',
210 'Case statement', 'Case selector', 'Case labels', 'Case label', 'else case', 'Repeat statement',
211 'While Statement', 'Loop header expr', 'Block header expr', 'For statement', 'With statement',
212 'try and handler block', 'try block', 'finally block', 'except block', 'Exception handlers',
213 'On exception handler', 'Procedure decl', 'Function Decl', 'Constructor decl', 'Destructor decl',
214 'Function heading', 'Procedure Heading', 'Constructor Heading', 'Destructor heading',
215 'Formal params', 'formal param', 'Function Return type', 'Procedure directives',
216 'external directive', 'object type', 'init section', 'class type', 'class heritage',
217 'class body', 'class visiblity', 'class declarations', 'property', 'property param list',
218 'property specifier', 'interface type', 'interface heritage', 'interface type guid',
219 'interface body', 'bracketed qual', 'asm', 'asm statement', 'asm ident',
220 'asm opcode', 'asm param', 'asm label', 'hint directives', 'property directive',
221 'exports', 'exported proc', 'literal string', 'hash literal char', 'hat literal char',
222 'Attribute', 'Class vars', 'Generic', 'Anonymous method', 'Method reference type'
223 );
224
NodeTypeToStringnull225 function NodeTypeToString(const pe: TParseTreeNodeType): string;
226 begin
227 Result := TreeNodeTypeNames[pe];
228 end;
229
230 end.
231