1
|
1
|
|
2 // Compiler implementation of the D programming language
|
336
|
3 // Copyright (c) 1999-2008 by Digital Mars
|
1
|
4 // All Rights Reserved
|
|
5 // written by Walter Bright
|
|
6 // http://www.digitalmars.com
|
|
7 // License for redistribution is by either the Artistic License
|
|
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
|
|
9 // See the included readme.txt for details.
|
|
10
|
|
11 #ifndef DMD_PARSE_H
|
|
12 #define DMD_PARSE_H
|
|
13
|
|
14 #ifdef __DMC__
|
|
15 #pragma once
|
|
16 #endif /* __DMC__ */
|
|
17
|
|
18 #include "arraytypes.h"
|
|
19 #include "lexer.h"
|
|
20 #include "enum.h"
|
|
21
|
|
22 struct Type;
|
336
|
23 struct TypeQualified;
|
1
|
24 struct Expression;
|
|
25 struct Declaration;
|
|
26 struct Statement;
|
|
27 struct Import;
|
|
28 struct Initializer;
|
|
29 struct FuncDeclaration;
|
|
30 struct CtorDeclaration;
|
336
|
31 struct PostBlitDeclaration;
|
1
|
32 struct DtorDeclaration;
|
|
33 struct StaticCtorDeclaration;
|
|
34 struct StaticDtorDeclaration;
|
|
35 struct ConditionalDeclaration;
|
|
36 struct InvariantDeclaration;
|
|
37 struct UnitTestDeclaration;
|
|
38 struct NewDeclaration;
|
|
39 struct DeleteDeclaration;
|
|
40 struct Condition;
|
|
41 struct Module;
|
|
42 struct ModuleDeclaration;
|
|
43 struct TemplateDeclaration;
|
|
44 struct TemplateInstance;
|
|
45 struct StaticAssert;
|
|
46
|
|
47 /************************************
|
|
48 * These control how parseStatement() works.
|
|
49 */
|
|
50
|
|
51 enum ParseStatementFlags
|
|
52 {
|
|
53 PSsemi = 1, // empty ';' statements are allowed
|
|
54 PSscope = 2, // start a new scope
|
|
55 PScurly = 4, // { } statement is required
|
|
56 PScurlyscope = 8, // { } starts a new scope
|
|
57 };
|
|
58
|
|
59
|
|
60 struct Parser : Lexer
|
|
61 {
|
|
62 ModuleDeclaration *md;
|
|
63 enum LINK linkage;
|
|
64 Loc endloc; // set to location of last right curly
|
|
65 int inBrackets; // inside [] of array index or slice
|
|
66
|
|
67 Parser(Module *module, unsigned char *base, unsigned length, int doDocComment);
|
|
68
|
|
69 Array *parseModule();
|
|
70 Array *parseDeclDefs(int once);
|
|
71 Array *parseBlock();
|
|
72 TemplateDeclaration *parseTemplateDeclaration();
|
|
73 TemplateParameters *parseTemplateParameterList();
|
|
74 Dsymbol *parseMixin();
|
|
75 Objects *parseTemplateArgumentList();
|
|
76 StaticAssert *parseStaticAssert();
|
|
77 enum LINK parseLinkage();
|
|
78 Condition *parseDebugCondition();
|
|
79 Condition *parseVersionCondition();
|
|
80 Condition *parseStaticIfCondition();
|
|
81 CtorDeclaration *parseCtor();
|
|
82 DtorDeclaration *parseDtor();
|
|
83 StaticCtorDeclaration *parseStaticCtor();
|
|
84 StaticDtorDeclaration *parseStaticDtor();
|
|
85 InvariantDeclaration *parseInvariant();
|
|
86 UnitTestDeclaration *parseUnitTest();
|
|
87 NewDeclaration *parseNew();
|
|
88 DeleteDeclaration *parseDelete();
|
|
89 Arguments *parseParameters(int *pvarargs);
|
|
90 EnumDeclaration *parseEnum();
|
|
91 Dsymbol *parseAggregate();
|
|
92 BaseClasses *parseBaseClasses();
|
|
93 Import *parseImport(Array *decldefs, int isstatic);
|
|
94 Type *parseBasicType();
|
|
95 Type *parseBasicType2(Type *t);
|
|
96 Type *parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl = NULL);
|
|
97 Array *parseDeclarations();
|
|
98 void parseContracts(FuncDeclaration *f);
|
|
99 Statement *parseStatement(int flags);
|
|
100 Initializer *parseInitializer();
|
|
101 void check(Loc loc, enum TOK value);
|
|
102 void check(enum TOK value);
|
|
103 void check(enum TOK value, char *string);
|
|
104 int isDeclaration(Token *t, int needId, enum TOK endtok, Token **pt);
|
|
105 int isBasicType(Token **pt);
|
|
106 int isDeclarator(Token **pt, int *haveId, enum TOK endtok);
|
|
107 int isParameters(Token **pt);
|
|
108 int isExpression(Token **pt);
|
|
109 int isTemplateInstance(Token *t, Token **pt);
|
|
110 int skipParens(Token *t, Token **pt);
|
|
111
|
|
112 Expression *parseExpression();
|
|
113 Expression *parsePrimaryExp();
|
|
114 Expression *parseUnaryExp();
|
|
115 Expression *parsePostExp(Expression *e);
|
|
116 Expression *parseMulExp();
|
|
117 Expression *parseAddExp();
|
|
118 Expression *parseShiftExp();
|
|
119 Expression *parseRelExp();
|
|
120 Expression *parseEqualExp();
|
|
121 Expression *parseCmpExp();
|
|
122 Expression *parseAndExp();
|
|
123 Expression *parseXorExp();
|
|
124 Expression *parseOrExp();
|
|
125 Expression *parseAndAndExp();
|
|
126 Expression *parseOrOrExp();
|
|
127 Expression *parseCondExp();
|
|
128 Expression *parseAssignExp();
|
|
129
|
|
130 Expressions *parseArguments();
|
|
131
|
|
132 Expression *parseNewExp(Expression *thisexp);
|
|
133
|
|
134 void addComment(Dsymbol *s, unsigned char *blockComment);
|
|
135 };
|
|
136
|
|
137 #endif /* DMD_PARSE_H */
|