]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/d/dmd/parse.h
Merge dmd upstream 6243fa6d2
[thirdparty/gcc.git] / gcc / d / dmd / parse.h
CommitLineData
b4c522fa
IB
1
2/* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved
4 * written by Walter Bright
5 * http://www.digitalmars.com
6 * Distributed under the Boost Software License, Version 1.0.
7 * http://www.boost.org/LICENSE_1_0.txt
8 * https://github.com/D-Programming-Language/dmd/blob/master/src/parse.h
9 */
10
11#pragma once
12
13#include "arraytypes.h"
14#include "lexer.h"
15#include "enum.h"
16
17class Type;
18class TypeQualified;
19class Expression;
20class Declaration;
21class Statement;
22class Import;
23class Initializer;
24class FuncDeclaration;
25class CtorDeclaration;
26class PostBlitDeclaration;
27class DtorDeclaration;
28class StaticCtorDeclaration;
29class StaticDtorDeclaration;
30class SharedStaticCtorDeclaration;
31class SharedStaticDtorDeclaration;
32class ConditionalDeclaration;
33class InvariantDeclaration;
34class UnitTestDeclaration;
35class NewDeclaration;
36class DeleteDeclaration;
37class Condition;
38class Module;
39struct ModuleDeclaration;
40class TemplateDeclaration;
41class TemplateInstance;
42class StaticAssert;
43struct PrefixAttributes;
44
45/************************************
46 * These control how parseStatement() works.
47 */
48
49enum ParseStatementFlags
50{
51 PSsemi = 1, // empty ';' statements are allowed, but deprecated
52 PSscope = 2, // start a new scope
53 PScurly = 4, // { } statement is required
54 PScurlyscope = 8, // { } starts a new scope
f9ab59ff 55 PSsemi_ok = 0x10 // empty ';' are really ok
b4c522fa
IB
56};
57
58
59class Parser : public Lexer
60{
61public:
62 Module *mod;
63 ModuleDeclaration *md;
64 LINK linkage;
65 CPPMANGLE cppmangle;
66 Loc endloc; // set to location of last right curly
67 int inBrackets; // inside [] of array index or slice
68 Loc lookingForElse; // location of lonely if looking for an else
69
70 Parser(Loc loc, Module *module, const utf8_t *base, size_t length, bool doDocComment);
71 Parser(Module *module, const utf8_t *base, size_t length, bool doDocComment);
72
73 Dsymbols *parseModule();
74 Dsymbols *parseDeclDefs(int once, Dsymbol **pLastDecl = NULL, PrefixAttributes *pAttrs = NULL);
75 Dsymbols *parseAutoDeclarations(StorageClass storageClass, const utf8_t *comment);
76 Dsymbols *parseBlock(Dsymbol **pLastDecl, PrefixAttributes *pAttrs = NULL);
77 StorageClass appendStorageClass(StorageClass storageClass, StorageClass stc, bool deprec = false);
78 StorageClass parseAttribute(Expressions **pexps);
79 StorageClass parsePostfix(StorageClass storageClass, Expressions **pudas);
80 StorageClass parseTypeCtor();
81 Expression *parseConstraint();
82 TemplateDeclaration *parseTemplateDeclaration(bool ismixin = false);
83 TemplateParameters *parseTemplateParameterList(int flag = 0);
84 Dsymbol *parseMixin();
85 Objects *parseTemplateArguments();
86 Objects *parseTemplateArgumentList();
87 Objects *parseTemplateSingleArgument();
88 StaticAssert *parseStaticAssert();
89 TypeQualified *parseTypeof();
90 Type *parseVector();
91 LINK parseLinkage(Identifiers **, CPPMANGLE *);
92 Identifiers *parseQualifiedIdentifier(const char *entity);
93 Condition *parseDebugCondition();
94 Condition *parseVersionCondition();
95 Condition *parseStaticIfCondition();
96 Dsymbol *parseCtor(PrefixAttributes *pAttrs);
97 Dsymbol *parseDtor(PrefixAttributes *pAttrs);
98 Dsymbol *parseStaticCtor(PrefixAttributes *pAttrs);
99 Dsymbol *parseStaticDtor(PrefixAttributes *pAttrs);
100 Dsymbol *parseSharedStaticCtor(PrefixAttributes *pAttrs);
101 Dsymbol *parseSharedStaticDtor(PrefixAttributes *pAttrs);
102 Dsymbol *parseInvariant(PrefixAttributes *pAttrs);
103 Dsymbol *parseUnitTest(PrefixAttributes *pAttrs);
104 Dsymbol *parseNew(PrefixAttributes *pAttrs);
105 Dsymbol *parseDelete(PrefixAttributes *pAttrs);
106 Parameters *parseParameters(int *pvarargs, TemplateParameters **tpl = NULL);
107 EnumDeclaration *parseEnum();
108 Dsymbol *parseAggregate();
109 BaseClasses *parseBaseClasses();
110 Dsymbols *parseImport();
111 Type *parseType(Identifier **pident = NULL, TemplateParameters **ptpl = NULL);
112 Type *parseBasicType(bool dontLookDotIdents = false);
113 Type *parseBasicTypeStartingAt(TypeQualified *tid, bool dontLookDotIdents);
114 Type *parseBasicType2(Type *t);
115 Type *parseDeclarator(Type *t, int *alt, Identifier **pident,
116 TemplateParameters **tpl = NULL, StorageClass storage_class = 0, int *pdisable = NULL, Expressions **pudas = NULL);
117 void parseStorageClasses(StorageClass &storage_class, LINK &link, bool &setAlignment, Expression *&ealign, Expressions *&udas);
118 Dsymbols *parseDeclarations(bool autodecl, PrefixAttributes *pAttrs, const utf8_t *comment);
119 Dsymbol *parseFunctionLiteral();
120 FuncDeclaration *parseContracts(FuncDeclaration *f);
121 void checkDanglingElse(Loc elseloc);
122 void checkCstyleTypeSyntax(Loc loc, Type *t, int alt, Identifier *ident);
123 /** endPtr used for documented unittests */
124 Statement *parseStatement(int flags, const utf8_t** endPtr = NULL, Loc *pEndloc = NULL);
125 Initializer *parseInitializer();
126 Expression *parseDefaultInitExp();
127 void check(Loc loc, TOK value);
128 void check(TOK value);
129 void check(TOK value, const char *string);
130 void checkParens(TOK value, Expression *e);
131 bool isDeclaration(Token *t, int needId, TOK endtok, Token **pt);
132 bool isBasicType(Token **pt);
133 bool isDeclarator(Token **pt, int *haveId, int *haveTpl, TOK endtok, bool allowAltSyntax = true);
134 bool isParameters(Token **pt);
135 bool isExpression(Token **pt);
136 bool skipParens(Token *t, Token **pt);
137 bool skipParensIf(Token *t, Token **pt);
138 bool skipAttributes(Token *t, Token **pt);
139
140 Expression *parseExpression();
141 Expression *parsePrimaryExp();
142 Expression *parseUnaryExp();
143 Expression *parsePostExp(Expression *e);
144 Expression *parseMulExp();
145 Expression *parseAddExp();
146 Expression *parseShiftExp();
147 Expression *parseCmpExp();
148 Expression *parseAndExp();
149 Expression *parseXorExp();
150 Expression *parseOrExp();
151 Expression *parseAndAndExp();
152 Expression *parseOrOrExp();
153 Expression *parseCondExp();
154 Expression *parseAssignExp();
155
156 Expressions *parseArguments();
157
158 Expression *parseNewExp(Expression *thisexp);
159
160 void addComment(Dsymbol *s, const utf8_t *blockComment);
161};
162
163// Operator precedence - greater values are higher precedence
164
165enum PREC
166{
167 PREC_zero,
168 PREC_expr,
169 PREC_assign,
170 PREC_cond,
171 PREC_oror,
172 PREC_andand,
173 PREC_or,
174 PREC_xor,
175 PREC_and,
176 PREC_equal,
177 PREC_rel,
178 PREC_shift,
179 PREC_add,
180 PREC_mul,
181 PREC_pow,
182 PREC_unary,
f9ab59ff 183 PREC_primary
b4c522fa
IB
184};
185
186extern PREC precedence[TOKMAX];
187
188void initPrecedence();