Merged Delight changes to D1 into D2
[delight/core.git] / dmd2 / parse.h
blobd1d9c85a0c4672d52a21685ec44345b812f0b5a3
2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2007 by Digital Mars
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.
11 #ifndef DMD_PARSE_H
12 #define DMD_PARSE_H
14 #ifdef __DMC__
15 #pragma once
16 #endif /* __DMC__ */
18 #include "arraytypes.h"
19 #include "lexer.h"
20 #include "enum.h"
22 struct Type;
23 struct TypeQualified;
24 struct Expression;
25 struct Declaration;
26 struct Statement;
27 struct Import;
28 struct Initializer;
29 struct FuncDeclaration;
30 struct CtorDeclaration;
31 struct PostBlitDeclaration;
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;
47 /************************************
48 * These control how parseStatement() works.
51 enum ParseStatementFlags
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 PScolon = 16, // in Delight, : is required
61 struct Parser : Lexer
63 ModuleDeclaration *md;
64 enum LINK linkage;
65 Loc endloc; // set to location of last right curly
66 int inBrackets; // inside [] of array index or slice
67 TOK startBlockTok;
68 bool dltNormalMode; // disallow various dangerous features
70 Parser(Module *module, unsigned char *base, unsigned length, int doDocComment);
72 Array *parseModule();
73 Array *parseDeclDefs(int once);
74 virtual Array *parseBlock();
75 TemplateDeclaration *parseTemplateDeclaration();
76 TemplateParameters *parseTemplateParameterList(int flag = 0);
77 Dsymbol *parseMixin();
78 Objects *parseTemplateArgumentList();
79 Objects *parseTemplateArgumentList2();
80 StaticAssert *parseStaticAssert();
81 TypeQualified *parseTypeof();
82 enum LINK parseLinkage();
83 Condition *parseDebugCondition();
84 Condition *parseVersionCondition();
85 Condition *parseStaticIfCondition();
86 FuncDeclaration *parseCtor();
87 PostBlitDeclaration *parsePostBlit();
88 DtorDeclaration *parseDtor();
89 StaticCtorDeclaration *parseStaticCtor();
90 StaticDtorDeclaration *parseStaticDtor();
91 InvariantDeclaration *parseInvariant();
92 UnitTestDeclaration *parseUnitTest();
93 NewDeclaration *parseNew();
94 DeleteDeclaration *parseDelete();
95 Arguments *parseParameters(int *pvarargs);
96 EnumDeclaration *parseEnum();
97 Dsymbol *parseAggregate();
98 BaseClasses *parseBaseClasses();
99 Import *parseImport(Array *decldefs, int isstatic);
100 Type *parseType(Identifier **pident = NULL, TemplateParameters **tpl = NULL);
101 Type *parseBasicType();
102 Type *parseBasicType2(Type *t);
103 Type *parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl = NULL);
104 Array *parseDeclarations();
105 void parseContracts(FuncDeclaration *f);
106 virtual Statement *parseStatement(int flags);
107 Statement *parseExtAsm(int expect_rparen);
108 Initializer *parseInitializer();
109 Expression *parseDefaultInitExp();
110 void optionalEndline();
111 void check(Loc loc, enum TOK value);
112 void check(enum TOK value);
113 void check(enum TOK value, char *string);
114 virtual void checkLParen();
115 virtual void checkRParen();
116 virtual char *endToken(); // for error messages
117 int isDeclaration(Token *t, int needId, enum TOK endtok, Token **pt);
118 int isBasicType(Token **pt);
119 int isDeclarator(Token **pt, int *haveId, enum TOK endtok);
120 int isParameters(Token **pt);
121 int isExpression(Token **pt);
122 int isTemplateInstance(Token *t, Token **pt);
123 int skipParens(Token *t, Token **pt);
125 Expression *parseExpression();
126 Expression *parsePrimaryExp();
127 Expression *parseUnaryExp();
128 Expression *parsePostExp(Expression *e);
129 Expression *parseMulExp();
130 Expression *parseAddExp();
131 Expression *parseShiftExp();
132 Expression *parseRelExp();
133 Expression *parseEqualExp();
134 Expression *parseCmpExp();
135 Expression *parseAndExp();
136 Expression *parseXorExp();
137 Expression *parseOrExp();
138 Expression *parseAndAndExp();
139 Expression *parseOrOrExp();
140 virtual Expression *parseCondExp();
141 Expression *parseAssignExp();
143 Expressions *parseArguments();
145 Expression *parseNewExp(Expression *thisexp);
146 Statement *logStatement(int level);
148 void addComment(Dsymbol *s, unsigned char *blockComment);
151 /************************************
152 * Delight
155 struct DltParser : Parser {
156 DltParser(Module *module, unsigned char *base, unsigned length, int doDocComment);
158 Statement *parseStatement(int flags);
159 Array *parseBlock();
160 Expression *parseCondExp();
161 char *endToken();
162 void checkLParen();
163 void checkRParen();
166 #endif /* DMD_PARSE_H */