| [b87a5ed] | 1 | // | 
|---|
|  | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
|  | 5 | // file "LICENCE" distributed with Cforall. | 
|---|
|  | 6 | // | 
|---|
| [974906e2] | 7 | // ParseNode.h -- | 
|---|
| [b87a5ed] | 8 | // | 
|---|
|  | 9 | // Author           : Rodolfo G. Esteves | 
|---|
|  | 10 | // Created On       : Sat May 16 13:28:16 2015 | 
|---|
| [e04ef3a] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [7d05e7e] | 12 | // Last Modified On : Thu Sep  8 21:58:06 2016 | 
|---|
|  | 13 | // Update Count     : 587 | 
|---|
| [b87a5ed] | 14 | // | 
|---|
|  | 15 |  | 
|---|
| [51b73452] | 16 | #ifndef PARSENODE_H | 
|---|
|  | 17 | #define PARSENODE_H | 
|---|
|  | 18 |  | 
|---|
|  | 19 | #include <string> | 
|---|
|  | 20 | #include <list> | 
|---|
|  | 21 | #include <iterator> | 
|---|
| [e04ef3a] | 22 | #include <memory> | 
|---|
| [51b73452] | 23 |  | 
|---|
| [68cd1ce] | 24 | #include "Parser/LinkageSpec.h" | 
|---|
| [59db689] | 25 | #include "SynTree/Type.h" | 
|---|
| [e04ef3a] | 26 | #include "SynTree/Expression.h" | 
|---|
| [2f22cc4] | 27 | #include "SynTree/Statement.h" | 
|---|
| [0f8e4ac] | 28 | #include "SynTree/Label.h" | 
|---|
| [7880579] | 29 | #include "Common/utility.h" | 
|---|
|  | 30 | #include "Common/UniqueName.h" | 
|---|
| [51b73452] | 31 |  | 
|---|
|  | 32 | class StatementNode; | 
|---|
|  | 33 | class CompoundStmtNode; | 
|---|
|  | 34 | class DeclarationNode; | 
|---|
| [d1625f8] | 35 | class ExpressionNode; | 
|---|
| [51b73452] | 36 | class InitializerNode; | 
|---|
|  | 37 |  | 
|---|
| [7880579] | 38 | //############################################################################## | 
|---|
|  | 39 |  | 
|---|
| [51b73452] | 40 | class ParseNode { | 
|---|
| [bdd516a] | 41 | public: | 
|---|
| [99cad3aa] | 42 | ParseNode() {}; | 
|---|
|  | 43 | ParseNode( const std::string *name ) : name( *name ) { assert( false ); delete name; } | 
|---|
|  | 44 | ParseNode( const std::string &name ) : name( name ) { assert( false ); } | 
|---|
|  | 45 | virtual ~ParseNode() { delete next; }; | 
|---|
| [0da3e2c] | 46 | virtual ParseNode *clone() const = 0; | 
|---|
| [51b73452] | 47 |  | 
|---|
| [1d4580a] | 48 | ParseNode *get_next() const { return next; } | 
|---|
|  | 49 | ParseNode *set_next( ParseNode *newlink ) { next = newlink; return this; } | 
|---|
| [99cad3aa] | 50 | ParseNode *get_last() { | 
|---|
|  | 51 | ParseNode *current; | 
|---|
|  | 52 | for ( current = this; current->get_next() != 0; current = current->get_next() ); | 
|---|
|  | 53 | return current; | 
|---|
|  | 54 | } | 
|---|
|  | 55 | ParseNode *set_last( ParseNode *newlast ) { | 
|---|
|  | 56 | if ( newlast != 0 ) get_last()->set_next( newlast ); | 
|---|
|  | 57 | return this; | 
|---|
|  | 58 | } | 
|---|
| [51b73452] | 59 |  | 
|---|
| [e869d663] | 60 | const std::string &get_name() const { return name; } | 
|---|
|  | 61 | void set_name( const std::string &newValue ) { name = newValue; } | 
|---|
|  | 62 |  | 
|---|
| [7880579] | 63 | virtual void print( std::ostream &os, int indent = 0 ) const {} | 
|---|
| [0da3e2c] | 64 | virtual void printList( std::ostream &os, int indent = 0 ) const {} | 
|---|
| [7880579] | 65 | private: | 
|---|
| [b87a5ed] | 66 | static int indent_by; | 
|---|
| [7880579] | 67 |  | 
|---|
| [0da3e2c] | 68 | ParseNode *next = nullptr; | 
|---|
| [7880579] | 69 | std::string name; | 
|---|
|  | 70 | }; // ParseNode | 
|---|
| [51b73452] | 71 |  | 
|---|
| [7bf7fb9] | 72 | //############################################################################## | 
|---|
|  | 73 |  | 
|---|
| [d1625f8] | 74 | class InitializerNode : public ParseNode { | 
|---|
|  | 75 | public: | 
|---|
|  | 76 | InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode *des = 0 ); | 
|---|
|  | 77 | InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); | 
|---|
|  | 78 | ~InitializerNode(); | 
|---|
| [0da3e2c] | 79 | virtual InitializerNode *clone() const { assert( false ); return nullptr; } | 
|---|
| [d1625f8] | 80 |  | 
|---|
|  | 81 | ExpressionNode *get_expression() const { return expr; } | 
|---|
|  | 82 |  | 
|---|
|  | 83 | InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } | 
|---|
|  | 84 | ExpressionNode *get_designators() const { return designator; } | 
|---|
|  | 85 |  | 
|---|
|  | 86 | InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; } | 
|---|
|  | 87 | bool get_maybeConstructed() const { return maybeConstructed; } | 
|---|
|  | 88 |  | 
|---|
|  | 89 | InitializerNode *next_init() const { return kids; } | 
|---|
|  | 90 |  | 
|---|
|  | 91 | void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 92 | void printOneLine( std::ostream & ) const; | 
|---|
|  | 93 |  | 
|---|
|  | 94 | virtual Initializer *build() const; | 
|---|
|  | 95 | private: | 
|---|
|  | 96 | ExpressionNode *expr; | 
|---|
|  | 97 | bool aggregate; | 
|---|
| [777bfcf] | 98 | ExpressionNode *designator;                                                     // may be list | 
|---|
| [d1625f8] | 99 | InitializerNode *kids; | 
|---|
|  | 100 | bool maybeConstructed; | 
|---|
| [c1c1112] | 101 | }; // InitializerNode | 
|---|
| [d1625f8] | 102 |  | 
|---|
|  | 103 | //############################################################################## | 
|---|
|  | 104 |  | 
|---|
| [ac71a86] | 105 | class ExpressionNode final : public ParseNode { | 
|---|
| [bdd516a] | 106 | public: | 
|---|
| [d1625f8] | 107 | ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {} | 
|---|
|  | 108 | ExpressionNode( Expression * expr, const std::string *name ) : ParseNode( name ), expr( expr ) {} | 
|---|
| [b87a5ed] | 109 | ExpressionNode( const ExpressionNode &other ); | 
|---|
| [d1625f8] | 110 | virtual ~ExpressionNode() {} | 
|---|
| [f39096c] | 111 | virtual ExpressionNode *clone() const { return expr ? new ExpressionNode( expr->clone() ) : nullptr; } | 
|---|
| [51b73452] | 112 |  | 
|---|
| [e04ef3a] | 113 | bool get_extension() const { return extension; } | 
|---|
|  | 114 | ExpressionNode *set_extension( bool exten ) { extension = exten; return this; } | 
|---|
| [51b73452] | 115 |  | 
|---|
| [ac71a86] | 116 | void print( std::ostream &os, int indent = 0 ) const {} | 
|---|
|  | 117 | void printOneLine( std::ostream &os, int indent = 0 ) const {} | 
|---|
|  | 118 |  | 
|---|
|  | 119 | template<typename T> | 
|---|
|  | 120 | bool isExpressionType() const { | 
|---|
|  | 121 | return nullptr != dynamic_cast<T>(expr.get()); | 
|---|
|  | 122 | } | 
|---|
| [51b73452] | 123 |  | 
|---|
| [ac71a86] | 124 | Expression *build() const { return const_cast<ExpressionNode*>(this)->expr.release(); } | 
|---|
| [bdd516a] | 125 | private: | 
|---|
| [e04ef3a] | 126 | bool extension = false; | 
|---|
| [ac71a86] | 127 | std::unique_ptr<Expression> expr; | 
|---|
| [c1c1112] | 128 | }; // ExpressionNode | 
|---|
| [e04ef3a] | 129 |  | 
|---|
|  | 130 | template< typename T > | 
|---|
| [7880579] | 131 | struct maybeBuild_t< Expression, T > { | 
|---|
| [e04ef3a] | 132 | static inline Expression * doit( const T *orig ) { | 
|---|
|  | 133 | if ( orig ) { | 
|---|
|  | 134 | Expression *p = orig->build(); | 
|---|
|  | 135 | p->set_extension( orig->get_extension() ); | 
|---|
|  | 136 | return p; | 
|---|
|  | 137 | } else { | 
|---|
| [7880579] | 138 | return nullptr; | 
|---|
| [e04ef3a] | 139 | } // if | 
|---|
|  | 140 | } | 
|---|
| [51b73452] | 141 | }; | 
|---|
|  | 142 |  | 
|---|
| [d9e2280] | 143 | enum class OperKinds { | 
|---|
|  | 144 | // diadic | 
|---|
| [7bf7fb9] | 145 | SizeOf, AlignOf, OffsetOf, Plus, Minus, Mul, Div, Mod, Or, And, | 
|---|
| [d9e2280] | 146 | BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, | 
|---|
| [a839867] | 147 | Assign, AtAssn, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn, | 
|---|
| [d9e2280] | 148 | Index, Range, | 
|---|
|  | 149 | // monadic | 
|---|
|  | 150 | UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress, | 
|---|
|  | 151 | Ctor, Dtor, | 
|---|
| [c1c1112] | 152 | }; // OperKinds | 
|---|
| [51b73452] | 153 |  | 
|---|
| [e82aa9df] | 154 | struct LabelNode { | 
|---|
|  | 155 | std::list< Label > labels; | 
|---|
|  | 156 | }; | 
|---|
|  | 157 |  | 
|---|
| [ac71a86] | 158 | Expression *build_constantInteger( const std::string &str ); | 
|---|
|  | 159 | Expression *build_constantFloat( const std::string &str ); | 
|---|
|  | 160 | Expression *build_constantChar( const std::string &str ); | 
|---|
|  | 161 | ConstantExpr *build_constantStr( const std::string &str ); | 
|---|
| [e82aa9df] | 162 |  | 
|---|
|  | 163 | NameExpr *build_varref( const std::string *name, bool labelp = false ); | 
|---|
|  | 164 | Expression *build_typevalue( DeclarationNode *decl ); | 
|---|
|  | 165 |  | 
|---|
| [d1625f8] | 166 | Expression *build_cast( DeclarationNode * decl_node, ExpressionNode *expr_node ); | 
|---|
| [3b58d91] | 167 | Expression *build_fieldSel( ExpressionNode *expr_node, Expression *member ); | 
|---|
|  | 168 | Expression *build_pfieldSel( ExpressionNode *expr_node, Expression *member ); | 
|---|
| [064e3ff] | 169 | Expression *build_addressOf( ExpressionNode *expr_node ); | 
|---|
| [d1625f8] | 170 | Expression *build_sizeOfexpr( ExpressionNode *expr_node ); | 
|---|
|  | 171 | Expression *build_sizeOftype( DeclarationNode *decl_node ); | 
|---|
|  | 172 | Expression *build_alignOfexpr( ExpressionNode *expr_node ); | 
|---|
|  | 173 | Expression *build_alignOftype( DeclarationNode *decl_node ); | 
|---|
|  | 174 | Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ); | 
|---|
| [51e076e] | 175 | Expression *build_and( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); | 
|---|
|  | 176 | Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ); | 
|---|
| [d9e2280] | 177 | Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ); | 
|---|
|  | 178 | Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ); | 
|---|
|  | 179 | Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); | 
|---|
|  | 180 | Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); | 
|---|
| [51e076e] | 181 | Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ); | 
|---|
|  | 182 | Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); | 
|---|
| [d1625f8] | 183 | Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ); | 
|---|
|  | 184 | Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ); | 
|---|
|  | 185 | Expression *build_tuple( ExpressionNode * expr_node = 0 ); | 
|---|
|  | 186 | Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ); | 
|---|
| [d9e2280] | 187 | Expression *build_range( ExpressionNode * low, ExpressionNode *high ); | 
|---|
| [e82aa9df] | 188 | Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ); | 
|---|
| [d1625f8] | 189 | Expression *build_valexpr( StatementNode *s ); | 
|---|
|  | 190 | Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ); | 
|---|
| [51b73452] | 191 |  | 
|---|
| [7bf7fb9] | 192 | //############################################################################## | 
|---|
|  | 193 |  | 
|---|
| [51b73452] | 194 | class TypeData; | 
|---|
|  | 195 |  | 
|---|
| [bdd516a] | 196 | class DeclarationNode : public ParseNode { | 
|---|
|  | 197 | public: | 
|---|
| [c1c1112] | 198 | enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic, NoOfQualifier }; | 
|---|
| [68cd1ce] | 199 | enum StorageClass { Extern, Static, Auto, Register, Inline, Fortran, Noreturn, Threadlocal, NoStorageClass, }; | 
|---|
| [b87a5ed] | 200 | enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary }; | 
|---|
| [68cd1ce] | 201 | enum Modifier  { Signed, Unsigned, Short, Long }; | 
|---|
| [4040425] | 202 | enum Aggregate { Struct, Union, Trait }; | 
|---|
| [b87a5ed] | 203 | enum TypeClass { Type, Dtype, Ftype }; | 
|---|
| [90c3b1c] | 204 | enum BuiltinType { Valist }; | 
|---|
| [b87a5ed] | 205 |  | 
|---|
|  | 206 | static const char *qualifierName[]; | 
|---|
| [c1c1112] | 207 | static const char *storageName[]; | 
|---|
| [b87a5ed] | 208 | static const char *basicTypeName[]; | 
|---|
|  | 209 | static const char *modifierName[]; | 
|---|
| [68cd1ce] | 210 | static const char *aggregateName[]; | 
|---|
| [b87a5ed] | 211 | static const char *typeClassName[]; | 
|---|
| [90c3b1c] | 212 | static const char *builtinTypeName[]; | 
|---|
| [b87a5ed] | 213 |  | 
|---|
| [7f5566b] | 214 | static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle = false ); | 
|---|
| [b87a5ed] | 215 | static DeclarationNode *newQualifier( Qualifier ); | 
|---|
| [c1c1112] | 216 | static DeclarationNode *newForall( DeclarationNode *); | 
|---|
| [b87a5ed] | 217 | static DeclarationNode *newStorageClass( StorageClass ); | 
|---|
|  | 218 | static DeclarationNode *newBasicType( BasicType ); | 
|---|
|  | 219 | static DeclarationNode *newModifier( Modifier ); | 
|---|
| [c1c1112] | 220 | static DeclarationNode *newBuiltinType( BuiltinType ); | 
|---|
| [b87a5ed] | 221 | static DeclarationNode *newFromTypedef( std::string *); | 
|---|
| [5d125e4] | 222 | static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ); | 
|---|
| [b87a5ed] | 223 | static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants ); | 
|---|
|  | 224 | static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant ); | 
|---|
|  | 225 | static DeclarationNode *newName( std::string *); | 
|---|
| [59db689] | 226 | static DeclarationNode *newFromTypeGen( std::string *, ExpressionNode *params ); | 
|---|
| [b87a5ed] | 227 | static DeclarationNode *newTypeParam( TypeClass, std::string *); | 
|---|
| [4040425] | 228 | static DeclarationNode *newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ); | 
|---|
|  | 229 | static DeclarationNode *newTraitUse( std::string *name, ExpressionNode *params ); | 
|---|
| [b87a5ed] | 230 | static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams ); | 
|---|
|  | 231 | static DeclarationNode *newPointer( DeclarationNode *qualifiers ); | 
|---|
|  | 232 | static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ); | 
|---|
|  | 233 | static DeclarationNode *newVarArray( DeclarationNode *qualifiers ); | 
|---|
|  | 234 | static DeclarationNode *newBitfield( ExpressionNode *size ); | 
|---|
|  | 235 | static DeclarationNode *newTuple( DeclarationNode *members ); | 
|---|
|  | 236 | static DeclarationNode *newTypeof( ExpressionNode *expr ); | 
|---|
| [59db689] | 237 | static DeclarationNode *newAttr( std::string *, ExpressionNode *expr ); | 
|---|
|  | 238 | static DeclarationNode *newAttr( std::string *, DeclarationNode *type ); | 
|---|
| [b87a5ed] | 239 |  | 
|---|
| [7880579] | 240 | DeclarationNode(); | 
|---|
|  | 241 | ~DeclarationNode(); | 
|---|
|  | 242 | DeclarationNode *clone() const; | 
|---|
|  | 243 |  | 
|---|
| [b87a5ed] | 244 | DeclarationNode *addQualifiers( DeclarationNode *); | 
|---|
| [413ad05] | 245 | void checkQualifiers( const TypeData *, const TypeData * ); | 
|---|
| [b87a5ed] | 246 | DeclarationNode *copyStorageClasses( DeclarationNode *); | 
|---|
|  | 247 | DeclarationNode *addType( DeclarationNode *); | 
|---|
|  | 248 | DeclarationNode *addTypedef(); | 
|---|
|  | 249 | DeclarationNode *addAssertions( DeclarationNode *); | 
|---|
|  | 250 | DeclarationNode *addName( std::string *); | 
|---|
|  | 251 | DeclarationNode *addBitfield( ExpressionNode *size ); | 
|---|
|  | 252 | DeclarationNode *addVarArgs(); | 
|---|
|  | 253 | DeclarationNode *addFunctionBody( StatementNode *body ); | 
|---|
|  | 254 | DeclarationNode *addOldDeclList( DeclarationNode *list ); | 
|---|
|  | 255 | DeclarationNode *addPointer( DeclarationNode *qualifiers ); | 
|---|
|  | 256 | DeclarationNode *addArray( DeclarationNode *array ); | 
|---|
|  | 257 | DeclarationNode *addNewPointer( DeclarationNode *pointer ); | 
|---|
|  | 258 | DeclarationNode *addNewArray( DeclarationNode *array ); | 
|---|
|  | 259 | DeclarationNode *addParamList( DeclarationNode *list ); | 
|---|
| [e82aa9df] | 260 | DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions | 
|---|
| [b87a5ed] | 261 | DeclarationNode *addInitializer( InitializerNode *init ); | 
|---|
|  | 262 |  | 
|---|
|  | 263 | DeclarationNode *cloneType( std::string *newName ); | 
|---|
|  | 264 | DeclarationNode *cloneType( DeclarationNode *existing ); | 
|---|
|  | 265 | DeclarationNode *cloneType( int ) { return cloneType( ( std::string *)0 ); } | 
|---|
|  | 266 | DeclarationNode *cloneBaseType( std::string *newName ); | 
|---|
|  | 267 | DeclarationNode *cloneBaseType( DeclarationNode *newdecl ); | 
|---|
|  | 268 |  | 
|---|
| [99cad3aa] | 269 | DeclarationNode *appendList( DeclarationNode *node ) { | 
|---|
|  | 270 | return (DeclarationNode *)set_last( node ); | 
|---|
|  | 271 | } | 
|---|
| [b87a5ed] | 272 |  | 
|---|
| [7bf7fb9] | 273 | void print( std::ostream &os, int indent = 0 ) const; | 
|---|
|  | 274 | void printList( std::ostream &os, int indent = 0 ) const; | 
|---|
| [b87a5ed] | 275 |  | 
|---|
|  | 276 | Declaration *build() const; | 
|---|
|  | 277 | ::Type *buildType() const; | 
|---|
|  | 278 |  | 
|---|
|  | 279 | bool get_hasEllipsis() const; | 
|---|
| [5f2f2d7] | 280 | const std::string &get_name() const { return name; } | 
|---|
| [8b7ee09] | 281 | LinkageSpec::Spec get_linkage() const { return linkage; } | 
|---|
| [b87a5ed] | 282 | DeclarationNode *extractAggregate() const; | 
|---|
| [4f147cc] | 283 | bool has_enumeratorValue() const { return (bool)enumeratorValue; } | 
|---|
|  | 284 | ExpressionNode *consume_enumeratorValue() const { return const_cast<DeclarationNode*>(this)->enumeratorValue.release(); } | 
|---|
| [b87a5ed] | 285 |  | 
|---|
| [7305915] | 286 | bool get_extension() const { return extension; } | 
|---|
|  | 287 | DeclarationNode *set_extension( bool exten ) { extension = exten; return this; } | 
|---|
| [c1c1112] | 288 | public: | 
|---|
| [13e3b50] | 289 | // StorageClass buildStorageClass() const; | 
|---|
|  | 290 | // bool buildFuncSpecifier( StorageClass key ) const; | 
|---|
| [b87a5ed] | 291 |  | 
|---|
| [28307be] | 292 | struct Variable_t { | 
|---|
|  | 293 | DeclarationNode::TypeClass tyClass; | 
|---|
|  | 294 | std::string name; | 
|---|
|  | 295 | DeclarationNode * assertions; | 
|---|
|  | 296 | }; | 
|---|
|  | 297 | Variable_t variable; | 
|---|
|  | 298 |  | 
|---|
|  | 299 | struct Attr_t { | 
|---|
|  | 300 | std::string name; | 
|---|
|  | 301 | ExpressionNode * expr; | 
|---|
|  | 302 | DeclarationNode * type; | 
|---|
|  | 303 | }; | 
|---|
|  | 304 | Attr_t attr; | 
|---|
|  | 305 |  | 
|---|
| [8f6f47d7] | 306 | BuiltinType builtin; | 
|---|
|  | 307 |  | 
|---|
| [b87a5ed] | 308 | TypeData *type; | 
|---|
|  | 309 | std::string name; | 
|---|
| [13e3b50] | 310 | // std::list< StorageClass > storageClasses; | 
|---|
|  | 311 | StorageClass storageClass; | 
|---|
|  | 312 | bool isInline, isNoreturn; | 
|---|
| [1db21619] | 313 | std::list< std::string > attributes; | 
|---|
| [b87a5ed] | 314 | ExpressionNode *bitfieldWidth; | 
|---|
| [4f147cc] | 315 | std::unique_ptr<ExpressionNode> enumeratorValue; | 
|---|
| [b87a5ed] | 316 | InitializerNode *initializer; | 
|---|
|  | 317 | bool hasEllipsis; | 
|---|
| [8b7ee09] | 318 | LinkageSpec::Spec linkage; | 
|---|
| [7305915] | 319 | bool extension = false; | 
|---|
| [13e3b50] | 320 | std::string error; | 
|---|
| [b87a5ed] | 321 |  | 
|---|
|  | 322 | static UniqueName anonymous; | 
|---|
| [1db21619] | 323 | }; // DeclarationNode | 
|---|
| [51b73452] | 324 |  | 
|---|
| [d1625f8] | 325 | Type *buildType( TypeData *type ); | 
|---|
| [413ad05] | 326 | //Type::Qualifiers buildQualifiers( const TypeData::Qualifiers & qualifiers ); | 
|---|
| [d1625f8] | 327 |  | 
|---|
| [4f147cc] | 328 | static inline Type * maybeMoveBuildType( const DeclarationNode *orig ) { | 
|---|
|  | 329 | Type* ret = orig ? orig->buildType() : nullptr; | 
|---|
|  | 330 | delete orig; | 
|---|
|  | 331 | return ret; | 
|---|
|  | 332 | } | 
|---|
|  | 333 |  | 
|---|
| [7bf7fb9] | 334 | //############################################################################## | 
|---|
|  | 335 |  | 
|---|
| [ac71a86] | 336 | class StatementNode final : public ParseNode { | 
|---|
| [bdd516a] | 337 | public: | 
|---|
| [e82aa9df] | 338 | StatementNode() { stmt = nullptr; } | 
|---|
|  | 339 | StatementNode( Statement *stmt ) : stmt( stmt ) {} | 
|---|
| [b87a5ed] | 340 | StatementNode( DeclarationNode *decl ); | 
|---|
| [e82aa9df] | 341 | virtual ~StatementNode() {} | 
|---|
| [51b73452] | 342 |  | 
|---|
| [ac71a86] | 343 | virtual StatementNode *clone() const final { assert( false ); return nullptr; } | 
|---|
|  | 344 | Statement *build() const { return const_cast<StatementNode*>(this)->stmt.release(); } | 
|---|
| [2f22cc4] | 345 |  | 
|---|
| [e82aa9df] | 346 | virtual StatementNode *add_label( const std::string * name ) { | 
|---|
| [2f22cc4] | 347 | stmt->get_labels().emplace_back( *name ); | 
|---|
| [ac71a86] | 348 | delete name; | 
|---|
| [2f22cc4] | 349 | return this; | 
|---|
|  | 350 | } | 
|---|
|  | 351 |  | 
|---|
| [1d4580a] | 352 | virtual StatementNode *append_last_case( StatementNode * ); | 
|---|
|  | 353 |  | 
|---|
| [2f22cc4] | 354 | virtual void print( std::ostream &os, int indent = 0 ) {} | 
|---|
|  | 355 | virtual void printList( std::ostream &os, int indent = 0 ) {} | 
|---|
|  | 356 | private: | 
|---|
| [ac71a86] | 357 | std::unique_ptr<Statement> stmt; | 
|---|
| [2f22cc4] | 358 | }; // StatementNode | 
|---|
|  | 359 |  | 
|---|
| [1d4580a] | 360 | Statement *build_expr( ExpressionNode *ctl ); | 
|---|
|  | 361 |  | 
|---|
| [2f22cc4] | 362 | struct ForCtl { | 
|---|
|  | 363 | ForCtl( ExpressionNode *expr, ExpressionNode *condition, ExpressionNode *change ) : | 
|---|
| [e82aa9df] | 364 | init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {} | 
|---|
| [2f22cc4] | 365 | ForCtl( DeclarationNode *decl, ExpressionNode *condition, ExpressionNode *change ) : | 
|---|
| [e82aa9df] | 366 | init( new StatementNode( decl ) ), condition( condition ), change( change ) {} | 
|---|
| [2f22cc4] | 367 |  | 
|---|
|  | 368 | StatementNode *init; | 
|---|
|  | 369 | ExpressionNode *condition; | 
|---|
|  | 370 | ExpressionNode *change; | 
|---|
|  | 371 | }; | 
|---|
|  | 372 |  | 
|---|
|  | 373 | Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ); | 
|---|
|  | 374 | Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ); | 
|---|
| [8cc5cb0] | 375 | Statement *build_case( ExpressionNode *ctl ); | 
|---|
|  | 376 | Statement *build_default(); | 
|---|
| [2f22cc4] | 377 | Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind = false ); | 
|---|
|  | 378 | Statement *build_for( ForCtl *forctl, StatementNode *stmt ); | 
|---|
| [ab57786] | 379 | Statement *build_branch( BranchStmt::Type kind ); | 
|---|
|  | 380 | Statement *build_branch( std::string *identifier, BranchStmt::Type kind ); | 
|---|
| [8cc5cb0] | 381 | Statement *build_computedgoto( ExpressionNode *ctl ); | 
|---|
|  | 382 | Statement *build_return( ExpressionNode *ctl ); | 
|---|
|  | 383 | Statement *build_throw( ExpressionNode *ctl ); | 
|---|
| [1d4580a] | 384 | Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ); | 
|---|
|  | 385 | Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny = false ); | 
|---|
|  | 386 | Statement *build_finally( StatementNode *stmt ); | 
|---|
| [e82aa9df] | 387 | Statement *build_compound( StatementNode *first ); | 
|---|
|  | 388 | Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ExpressionNode *clobber = 0, LabelNode *gotolabels = 0 ); | 
|---|
| [7f5566b] | 389 |  | 
|---|
| [7bf7fb9] | 390 | //############################################################################## | 
|---|
|  | 391 |  | 
|---|
| [51b73452] | 392 | template< typename SynTreeType, typename NodeType > | 
|---|
| [2f22cc4] | 393 | void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) { | 
|---|
| [b87a5ed] | 394 | SemanticError errors; | 
|---|
| [7880579] | 395 | std::back_insert_iterator< std::list< SynTreeType * > > out( outputList ); | 
|---|
| [b87a5ed] | 396 | const NodeType *cur = firstNode; | 
|---|
|  | 397 |  | 
|---|
|  | 398 | while ( cur ) { | 
|---|
|  | 399 | try { | 
|---|
| [7880579] | 400 | //                      SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) ); | 
|---|
|  | 401 | SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) ); | 
|---|
| [b87a5ed] | 402 | if ( result ) { | 
|---|
|  | 403 | *out++ = result; | 
|---|
|  | 404 | } // if | 
|---|
|  | 405 | } catch( SemanticError &e ) { | 
|---|
|  | 406 | errors.append( e ); | 
|---|
|  | 407 | } // try | 
|---|
| [7880579] | 408 | cur = dynamic_cast< NodeType * >( cur->get_next() ); | 
|---|
| [b87a5ed] | 409 | } // while | 
|---|
| [a32b204] | 410 | if ( ! errors.isEmpty() ) { | 
|---|
| [b87a5ed] | 411 | throw errors; | 
|---|
|  | 412 | } // if | 
|---|
| [51b73452] | 413 | } | 
|---|
|  | 414 |  | 
|---|
|  | 415 | // in DeclarationNode.cc | 
|---|
| [59db689] | 416 | void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ); | 
|---|
| [7880579] | 417 | void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ); | 
|---|
| [59db689] | 418 | void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ); | 
|---|
| [51b73452] | 419 |  | 
|---|
| [7ecbb7e] | 420 | template< typename SynTreeType, typename NodeType > | 
|---|
|  | 421 | void buildMoveList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) { | 
|---|
|  | 422 | buildList(firstNode, outputList); | 
|---|
|  | 423 | delete firstNode; | 
|---|
|  | 424 | } | 
|---|
|  | 425 |  | 
|---|
| [c8dfcd3] | 426 | // in ParseNode.cc | 
|---|
|  | 427 | std::ostream & operator<<( std::ostream & out, const ParseNode * node ); | 
|---|
| [7ecbb7e] | 428 |  | 
|---|
| [bdd516a] | 429 | #endif // PARSENODE_H | 
|---|
| [51b73452] | 430 |  | 
|---|
|  | 431 | // Local Variables: // | 
|---|
| [b87a5ed] | 432 | // tab-width: 4 // | 
|---|
|  | 433 | // mode: c++ // | 
|---|
|  | 434 | // compile-command: "make install" // | 
|---|
| [51b73452] | 435 | // End: // | 
|---|