| [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
|
|---|
| [08d5507b] | 12 | // Last Modified On : Tue Mar 14 11:05:05 2017
|
|---|
| 13 | // Update Count : 752
|
|---|
| [b87a5ed] | 14 | //
|
|---|
| 15 |
|
|---|
| [51b73452] | 16 | #ifndef PARSENODE_H
|
|---|
| 17 | #define PARSENODE_H
|
|---|
| 18 |
|
|---|
| 19 | #include <string>
|
|---|
| 20 | #include <list>
|
|---|
| [dd020c0] | 21 | #include <bitset>
|
|---|
| [51b73452] | 22 | #include <iterator>
|
|---|
| [e04ef3a] | 23 | #include <memory>
|
|---|
| [51b73452] | 24 |
|
|---|
| [68cd1ce] | 25 | #include "Parser/LinkageSpec.h"
|
|---|
| [59db689] | 26 | #include "SynTree/Type.h"
|
|---|
| [e04ef3a] | 27 | #include "SynTree/Expression.h"
|
|---|
| [2f22cc4] | 28 | #include "SynTree/Statement.h"
|
|---|
| [0f8e4ac] | 29 | #include "SynTree/Label.h"
|
|---|
| [7880579] | 30 | #include "Common/utility.h"
|
|---|
| 31 | #include "Common/UniqueName.h"
|
|---|
| [51b73452] | 32 |
|
|---|
| 33 | class StatementNode;
|
|---|
| 34 | class CompoundStmtNode;
|
|---|
| 35 | class DeclarationNode;
|
|---|
| [d1625f8] | 36 | class ExpressionNode;
|
|---|
| [51b73452] | 37 | class InitializerNode;
|
|---|
| [44a81853] | 38 | class Attribute;
|
|---|
| [51b73452] | 39 |
|
|---|
| [7880579] | 40 | //##############################################################################
|
|---|
| 41 |
|
|---|
| [a7c90d4] | 42 | extern char * yyfilename;
|
|---|
| [294647b] | 43 | extern int yylineno;
|
|---|
| 44 |
|
|---|
| [51b73452] | 45 | class ParseNode {
|
|---|
| [bdd516a] | 46 | public:
|
|---|
| [99cad3aa] | 47 | ParseNode() {};
|
|---|
| [2298f728] | 48 | virtual ~ParseNode() { delete next; delete name; };
|
|---|
| [b6424d9] | 49 | virtual ParseNode * clone() const = 0;
|
|---|
| [51b73452] | 50 |
|
|---|
| [b6424d9] | 51 | ParseNode * get_next() const { return next; }
|
|---|
| 52 | ParseNode * set_next( ParseNode * newlink ) { next = newlink; return this; }
|
|---|
| [1b772749] | 53 |
|
|---|
| [b6424d9] | 54 | ParseNode * get_last() {
|
|---|
| 55 | ParseNode * current;
|
|---|
| [2298f728] | 56 | for ( current = this; current->get_next() != nullptr; current = current->get_next() );
|
|---|
| [99cad3aa] | 57 | return current;
|
|---|
| 58 | }
|
|---|
| [b6424d9] | 59 | ParseNode * set_last( ParseNode * newlast ) {
|
|---|
| [2298f728] | 60 | if ( newlast != nullptr ) get_last()->set_next( newlast );
|
|---|
| [99cad3aa] | 61 | return this;
|
|---|
| 62 | }
|
|---|
| [51b73452] | 63 |
|
|---|
| [7880579] | 64 | virtual void print( std::ostream &os, int indent = 0 ) const {}
|
|---|
| [0da3e2c] | 65 | virtual void printList( std::ostream &os, int indent = 0 ) const {}
|
|---|
| [1b772749] | 66 |
|
|---|
| [b87a5ed] | 67 | static int indent_by;
|
|---|
| [7880579] | 68 |
|
|---|
| [b6424d9] | 69 | ParseNode * next = nullptr;
|
|---|
| [2298f728] | 70 | std::string * name = nullptr;
|
|---|
| [294647b] | 71 | CodeLocation location = { yyfilename, yylineno };
|
|---|
| [7880579] | 72 | }; // ParseNode
|
|---|
| [51b73452] | 73 |
|
|---|
| [7bf7fb9] | 74 | //##############################################################################
|
|---|
| 75 |
|
|---|
| [d1625f8] | 76 | class InitializerNode : public ParseNode {
|
|---|
| 77 | public:
|
|---|
| [2298f728] | 78 | InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = nullptr );
|
|---|
| 79 | InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = nullptr );
|
|---|
| [d1625f8] | 80 | ~InitializerNode();
|
|---|
| [a7741435] | 81 | virtual InitializerNode * clone() const { assert( false ); return nullptr; }
|
|---|
| [d1625f8] | 82 |
|
|---|
| [b6424d9] | 83 | ExpressionNode * get_expression() const { return expr; }
|
|---|
| [d1625f8] | 84 |
|
|---|
| [b6424d9] | 85 | InitializerNode * set_designators( ExpressionNode * des ) { designator = des; return this; }
|
|---|
| 86 | ExpressionNode * get_designators() const { return designator; }
|
|---|
| [d1625f8] | 87 |
|
|---|
| [b6424d9] | 88 | InitializerNode * set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }
|
|---|
| [d1625f8] | 89 | bool get_maybeConstructed() const { return maybeConstructed; }
|
|---|
| 90 |
|
|---|
| [b6424d9] | 91 | InitializerNode * next_init() const { return kids; }
|
|---|
| [d1625f8] | 92 |
|
|---|
| 93 | void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 94 | void printOneLine( std::ostream & ) const;
|
|---|
| 95 |
|
|---|
| [b6424d9] | 96 | virtual Initializer * build() const;
|
|---|
| [d1625f8] | 97 | private:
|
|---|
| [b6424d9] | 98 | ExpressionNode * expr;
|
|---|
| [d1625f8] | 99 | bool aggregate;
|
|---|
| [b6424d9] | 100 | ExpressionNode * designator; // may be list
|
|---|
| 101 | InitializerNode * kids;
|
|---|
| [d1625f8] | 102 | bool maybeConstructed;
|
|---|
| [c1c1112] | 103 | }; // InitializerNode
|
|---|
| [d1625f8] | 104 |
|
|---|
| 105 | //##############################################################################
|
|---|
| 106 |
|
|---|
| [ac71a86] | 107 | class ExpressionNode final : public ParseNode {
|
|---|
| [bdd516a] | 108 | public:
|
|---|
| [d1625f8] | 109 | ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {}
|
|---|
| [b87a5ed] | 110 | ExpressionNode( const ExpressionNode &other );
|
|---|
| [d1625f8] | 111 | virtual ~ExpressionNode() {}
|
|---|
| [6a0d4d61] | 112 | virtual ExpressionNode * clone() const override { return expr ? new ExpressionNode( expr->clone() ) : nullptr; }
|
|---|
| [51b73452] | 113 |
|
|---|
| [e04ef3a] | 114 | bool get_extension() const { return extension; }
|
|---|
| [b6424d9] | 115 | ExpressionNode * set_extension( bool exten ) { extension = exten; return this; }
|
|---|
| [51b73452] | 116 |
|
|---|
| [62e5546] | 117 | virtual void print( std::ostream &os, int indent = 0 ) const override {}
|
|---|
| [ac71a86] | 118 | void printOneLine( std::ostream &os, int indent = 0 ) const {}
|
|---|
| 119 |
|
|---|
| 120 | template<typename T>
|
|---|
| 121 | bool isExpressionType() const {
|
|---|
| 122 | return nullptr != dynamic_cast<T>(expr.get());
|
|---|
| 123 | }
|
|---|
| [51b73452] | 124 |
|
|---|
| [a7c90d4] | 125 | Expression * build() const { return const_cast<ExpressionNode *>(this)->expr.release(); }
|
|---|
| [bdd516a] | 126 | private:
|
|---|
| [e04ef3a] | 127 | bool extension = false;
|
|---|
| [ac71a86] | 128 | std::unique_ptr<Expression> expr;
|
|---|
| [c1c1112] | 129 | }; // ExpressionNode
|
|---|
| [e04ef3a] | 130 |
|
|---|
| 131 | template< typename T >
|
|---|
| [7880579] | 132 | struct maybeBuild_t< Expression, T > {
|
|---|
| [b6424d9] | 133 | static inline Expression * doit( const T * orig ) {
|
|---|
| [e04ef3a] | 134 | if ( orig ) {
|
|---|
| [b6424d9] | 135 | Expression * p = orig->build();
|
|---|
| [e04ef3a] | 136 | p->set_extension( orig->get_extension() );
|
|---|
| 137 | return p;
|
|---|
| 138 | } else {
|
|---|
| [7880579] | 139 | return nullptr;
|
|---|
| [e04ef3a] | 140 | } // if
|
|---|
| 141 | }
|
|---|
| [51b73452] | 142 | };
|
|---|
| 143 |
|
|---|
| [d9e2280] | 144 | enum class OperKinds {
|
|---|
| 145 | // diadic
|
|---|
| [7bf7fb9] | 146 | SizeOf, AlignOf, OffsetOf, Plus, Minus, Mul, Div, Mod, Or, And,
|
|---|
| [d9e2280] | 147 | BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
|
|---|
| [a839867] | 148 | Assign, AtAssn, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn,
|
|---|
| [d9e2280] | 149 | Index, Range,
|
|---|
| 150 | // monadic
|
|---|
| 151 | UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress,
|
|---|
| 152 | Ctor, Dtor,
|
|---|
| [c1c1112] | 153 | }; // OperKinds
|
|---|
| [51b73452] | 154 |
|
|---|
| [e82aa9df] | 155 | struct LabelNode {
|
|---|
| 156 | std::list< Label > labels;
|
|---|
| 157 | };
|
|---|
| 158 |
|
|---|
| [b6424d9] | 159 | Expression * build_constantInteger( const std::string &str );
|
|---|
| 160 | Expression * build_constantFloat( const std::string &str );
|
|---|
| 161 | Expression * build_constantChar( const std::string &str );
|
|---|
| [4cb935e] | 162 | Expression * build_constantZeroOne( const std::string &str );
|
|---|
| [b6424d9] | 163 | ConstantExpr * build_constantStr( const std::string &str );
|
|---|
| [8780e30] | 164 | Expression * build_field_name_FLOATINGconstant( const std::string & str );
|
|---|
| 165 | Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts );
|
|---|
| 166 | Expression * build_field_name_REALFRACTIONconstant( const std::string & str );
|
|---|
| 167 | Expression * build_field_name_REALDECIMALconstant( const std::string & str );
|
|---|
| [b6424d9] | 168 |
|
|---|
| 169 | NameExpr * build_varref( const std::string * name, bool labelp = false );
|
|---|
| 170 | Expression * build_typevalue( DeclarationNode * decl );
|
|---|
| 171 |
|
|---|
| 172 | Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
|
|---|
| [fd782b2] | 173 | Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member );
|
|---|
| 174 | Expression * build_pfieldSel( ExpressionNode * expr_node, Expression * member );
|
|---|
| [b6424d9] | 175 | Expression * build_addressOf( ExpressionNode * expr_node );
|
|---|
| 176 | Expression * build_sizeOfexpr( ExpressionNode * expr_node );
|
|---|
| 177 | Expression * build_sizeOftype( DeclarationNode * decl_node );
|
|---|
| 178 | Expression * build_alignOfexpr( ExpressionNode * expr_node );
|
|---|
| 179 | Expression * build_alignOftype( DeclarationNode * decl_node );
|
|---|
| 180 | Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member );
|
|---|
| 181 | Expression * build_and( ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
|
|---|
| 182 | Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind );
|
|---|
| 183 | Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node );
|
|---|
| 184 | Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node );
|
|---|
| 185 | Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
|
|---|
| 186 | Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
|
|---|
| 187 | Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 );
|
|---|
| 188 | Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
|
|---|
| 189 | Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node );
|
|---|
| 190 | Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node );
|
|---|
| [2298f728] | 191 | Expression * build_tuple( ExpressionNode * expr_node = nullptr );
|
|---|
| [b6424d9] | 192 | Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node );
|
|---|
| 193 | Expression * build_range( ExpressionNode * low, ExpressionNode * high );
|
|---|
| 194 | Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand );
|
|---|
| 195 | Expression * build_valexpr( StatementNode * s );
|
|---|
| 196 | Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids );
|
|---|
| [51b73452] | 197 |
|
|---|
| [7bf7fb9] | 198 | //##############################################################################
|
|---|
| 199 |
|
|---|
| [62e5546] | 200 | struct TypeData;
|
|---|
| [51b73452] | 201 |
|
|---|
| [bdd516a] | 202 | class DeclarationNode : public ParseNode {
|
|---|
| 203 | public:
|
|---|
| [5b639ee] | 204 | // These must remain in the same order as the corresponding DeclarationNode names.
|
|---|
| [c0aa336] | 205 |
|
|---|
| [08d5507b] | 206 | enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, Threadlocal = 1 << 4, NoStorageClass = 5 };
|
|---|
| 207 | union StorageClasses {
|
|---|
| 208 | unsigned int val;
|
|---|
| 209 | struct {
|
|---|
| 210 | bool is_extern : 1;
|
|---|
| 211 | bool is_static : 1;
|
|---|
| 212 | bool is_auto : 1;
|
|---|
| 213 | bool is_register : 1;
|
|---|
| 214 | bool is_threadlocal : 1;
|
|---|
| 215 | };
|
|---|
| 216 | StorageClasses() : val( 0 ) {}
|
|---|
| 217 | StorageClasses( unsigned int val ) : val( val ) {}
|
|---|
| 218 | bool operator[]( unsigned int i ) const { return val & (1 << i); }
|
|---|
| 219 | }; // StorageClasses
|
|---|
| 220 |
|
|---|
| 221 | enum { Inline = 1 << 0, Noreturn = 1 << 1, Fortran = 1 << 2, NoFuncSpecifier = 3 };
|
|---|
| 222 | union FuncSpecifiers {
|
|---|
| 223 | unsigned int val;
|
|---|
| 224 | struct {
|
|---|
| 225 | bool is_inline : 1;
|
|---|
| 226 | bool is_noreturn : 1;
|
|---|
| 227 | bool is_fortran : 1;
|
|---|
| 228 | };
|
|---|
| 229 | FuncSpecifiers() : val( 0 ) {}
|
|---|
| 230 | FuncSpecifiers( unsigned int val ) : val( val ) {}
|
|---|
| 231 | bool operator[]( unsigned int i ) const { return val & (1 << i); }
|
|---|
| 232 | }; // FuncSpecifiers
|
|---|
| 233 |
|
|---|
| [a7c90d4] | 234 | enum TypeQualifier { Const, Restrict, Volatile, Lvalue, Mutex, Atomic, NoTypeQualifier };
|
|---|
| [5b639ee] | 235 | enum BasicType { Void, Bool, Char, Int, Float, Double, LongDouble, NoBasicType };
|
|---|
| 236 | enum ComplexType { Complex, Imaginary, NoComplexType };
|
|---|
| 237 | enum Signedness { Signed, Unsigned, NoSignedness };
|
|---|
| 238 | enum Length { Short, Long, LongLong, NoLength };
|
|---|
| [faddbd8] | 239 | enum Aggregate { Struct, Union, Trait, NoAggregate };
|
|---|
| [8f60f0b] | 240 | enum TypeClass { Otype, Dtype, Ftype, Ttype, NoTypeClass };
|
|---|
| [148f7290] | 241 | enum BuiltinType { Valist, Zero, One, NoBuiltinType };
|
|---|
| [b87a5ed] | 242 |
|
|---|
| [dd020c0] | 243 | static const char * storageClassNames[];
|
|---|
| 244 | static const char * funcSpecifierNames[];
|
|---|
| 245 | static const char * typeQualifierNames[];
|
|---|
| 246 | static const char * basicTypeNames[];
|
|---|
| 247 | static const char * complexTypeNames[];
|
|---|
| 248 | static const char * signednessNames[];
|
|---|
| 249 | static const char * lengthNames[];
|
|---|
| 250 | static const char * aggregateNames[];
|
|---|
| 251 | static const char * typeClassNames[];
|
|---|
| 252 | static const char * builtinTypeNames[];
|
|---|
| [b6424d9] | 253 |
|
|---|
| [08d5507b] | 254 | static DeclarationNode * newStorageClass( StorageClasses );
|
|---|
| 255 | static DeclarationNode * newFuncSpecifier( FuncSpecifiers );
|
|---|
| [dd020c0] | 256 | static DeclarationNode * newTypeQualifier( TypeQualifier );
|
|---|
| [b6424d9] | 257 | static DeclarationNode * newBasicType( BasicType );
|
|---|
| [5b639ee] | 258 | static DeclarationNode * newComplexType( ComplexType );
|
|---|
| [dd020c0] | 259 | static DeclarationNode * newSignedNess( Signedness );
|
|---|
| 260 | static DeclarationNode * newLength( Length );
|
|---|
| [b6424d9] | 261 | static DeclarationNode * newBuiltinType( BuiltinType );
|
|---|
| [dd020c0] | 262 | static DeclarationNode * newForall( DeclarationNode * );
|
|---|
| [2298f728] | 263 | static DeclarationNode * newFromTypedef( std::string * );
|
|---|
| [dd020c0] | 264 | static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle = false );
|
|---|
| [b6424d9] | 265 | static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
|
|---|
| [ca1a547] | 266 | static DeclarationNode * newEnum( std::string * name, DeclarationNode * constants, bool body );
|
|---|
| [b6424d9] | 267 | static DeclarationNode * newEnumConstant( std::string * name, ExpressionNode * constant );
|
|---|
| [2298f728] | 268 | static DeclarationNode * newName( std::string * );
|
|---|
| [b6424d9] | 269 | static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode * params );
|
|---|
| [2298f728] | 270 | static DeclarationNode * newTypeParam( TypeClass, std::string * );
|
|---|
| 271 | static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts );
|
|---|
| 272 | static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params );
|
|---|
| [b6424d9] | 273 | static DeclarationNode * newTypeDecl( std::string * name, DeclarationNode * typeParams );
|
|---|
| 274 | static DeclarationNode * newPointer( DeclarationNode * qualifiers );
|
|---|
| 275 | static DeclarationNode * newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic );
|
|---|
| 276 | static DeclarationNode * newVarArray( DeclarationNode * qualifiers );
|
|---|
| 277 | static DeclarationNode * newBitfield( ExpressionNode * size );
|
|---|
| 278 | static DeclarationNode * newTuple( DeclarationNode * members );
|
|---|
| 279 | static DeclarationNode * newTypeof( ExpressionNode * expr );
|
|---|
| [44a81853] | 280 | static DeclarationNode * newAttr( std::string *, ExpressionNode * expr ); // @ attributes
|
|---|
| 281 | static DeclarationNode * newAttr( std::string *, DeclarationNode * type ); // @ attributes
|
|---|
| 282 | static DeclarationNode * newAttribute( std::string *, ExpressionNode * expr = nullptr ); // gcc attributes
|
|---|
| [e994912] | 283 | static DeclarationNode * newAsmStmt( StatementNode * stmt ); // gcc external asm statement
|
|---|
| [b87a5ed] | 284 |
|
|---|
| [7880579] | 285 | DeclarationNode();
|
|---|
| 286 | ~DeclarationNode();
|
|---|
| [6a0d4d61] | 287 | DeclarationNode * clone() const override;
|
|---|
| [7880579] | 288 |
|
|---|
| [2298f728] | 289 | DeclarationNode * addQualifiers( DeclarationNode * );
|
|---|
| [413ad05] | 290 | void checkQualifiers( const TypeData *, const TypeData * );
|
|---|
| [a7c90d4] | 291 | void checkSpecifiers( DeclarationNode * );
|
|---|
| 292 | DeclarationNode * copySpecifiers( DeclarationNode * );
|
|---|
| [2298f728] | 293 | DeclarationNode * addType( DeclarationNode * );
|
|---|
| [b6424d9] | 294 | DeclarationNode * addTypedef();
|
|---|
| [2298f728] | 295 | DeclarationNode * addAssertions( DeclarationNode * );
|
|---|
| 296 | DeclarationNode * addName( std::string * );
|
|---|
| [c0aa336] | 297 | DeclarationNode * addAsmName( DeclarationNode * );
|
|---|
| [b6424d9] | 298 | DeclarationNode * addBitfield( ExpressionNode * size );
|
|---|
| 299 | DeclarationNode * addVarArgs();
|
|---|
| 300 | DeclarationNode * addFunctionBody( StatementNode * body );
|
|---|
| 301 | DeclarationNode * addOldDeclList( DeclarationNode * list );
|
|---|
| [c0aa336] | 302 | DeclarationNode * setBase( TypeData * newType );
|
|---|
| 303 | DeclarationNode * copyAttribute( DeclarationNode * attr );
|
|---|
| [b6424d9] | 304 | DeclarationNode * addPointer( DeclarationNode * qualifiers );
|
|---|
| 305 | DeclarationNode * addArray( DeclarationNode * array );
|
|---|
| 306 | DeclarationNode * addNewPointer( DeclarationNode * pointer );
|
|---|
| 307 | DeclarationNode * addNewArray( DeclarationNode * array );
|
|---|
| 308 | DeclarationNode * addParamList( DeclarationNode * list );
|
|---|
| 309 | DeclarationNode * addIdList( DeclarationNode * list ); // old-style functions
|
|---|
| 310 | DeclarationNode * addInitializer( InitializerNode * init );
|
|---|
| 311 |
|
|---|
| 312 | DeclarationNode * cloneType( std::string * newName );
|
|---|
| 313 | DeclarationNode * cloneBaseType( DeclarationNode * newdecl );
|
|---|
| 314 |
|
|---|
| 315 | DeclarationNode * appendList( DeclarationNode * node ) {
|
|---|
| [99cad3aa] | 316 | return (DeclarationNode *)set_last( node );
|
|---|
| 317 | }
|
|---|
| [b87a5ed] | 318 |
|
|---|
| [62e5546] | 319 | virtual void print( std::ostream &os, int indent = 0 ) const override;
|
|---|
| 320 | virtual void printList( std::ostream &os, int indent = 0 ) const override;
|
|---|
| [b87a5ed] | 321 |
|
|---|
| [b6424d9] | 322 | Declaration * build() const;
|
|---|
| [a7c90d4] | 323 | Type * buildType() const;
|
|---|
| [b87a5ed] | 324 |
|
|---|
| 325 | bool get_hasEllipsis() const;
|
|---|
| [8b7ee09] | 326 | LinkageSpec::Spec get_linkage() const { return linkage; }
|
|---|
| [b6424d9] | 327 | DeclarationNode * extractAggregate() const;
|
|---|
| [4f147cc] | 328 | bool has_enumeratorValue() const { return (bool)enumeratorValue; }
|
|---|
| [a7c90d4] | 329 | ExpressionNode * consume_enumeratorValue() const { return const_cast<DeclarationNode *>(this)->enumeratorValue.release(); }
|
|---|
| [b87a5ed] | 330 |
|
|---|
| [7305915] | 331 | bool get_extension() const { return extension; }
|
|---|
| [b6424d9] | 332 | DeclarationNode * set_extension( bool exten ) { extension = exten; return this; }
|
|---|
| [c1c1112] | 333 | public:
|
|---|
| [28307be] | 334 | struct Variable_t {
|
|---|
| [faddbd8] | 335 | // const std::string * name;
|
|---|
| [28307be] | 336 | DeclarationNode::TypeClass tyClass;
|
|---|
| 337 | DeclarationNode * assertions;
|
|---|
| 338 | };
|
|---|
| 339 | Variable_t variable;
|
|---|
| 340 |
|
|---|
| 341 | struct Attr_t {
|
|---|
| [faddbd8] | 342 | // const std::string * name;
|
|---|
| [28307be] | 343 | ExpressionNode * expr;
|
|---|
| 344 | DeclarationNode * type;
|
|---|
| 345 | };
|
|---|
| 346 | Attr_t attr;
|
|---|
| 347 |
|
|---|
| [8f6f47d7] | 348 | BuiltinType builtin;
|
|---|
| 349 |
|
|---|
| [b6424d9] | 350 | TypeData * type;
|
|---|
| [dd020c0] | 351 |
|
|---|
| [a7c90d4] | 352 | StorageClasses storageClasses;
|
|---|
| 353 | static void print_StorageClass( std::ostream & output, StorageClasses storageClasses );
|
|---|
| 354 |
|
|---|
| 355 | FuncSpecifiers funcSpecs;
|
|---|
| 356 | static void print_FuncSpec( std::ostream & output, FuncSpecifiers funcSpecs );
|
|---|
| [dd020c0] | 357 |
|
|---|
| [b6424d9] | 358 | ExpressionNode * bitfieldWidth;
|
|---|
| [4f147cc] | 359 | std::unique_ptr<ExpressionNode> enumeratorValue;
|
|---|
| [b87a5ed] | 360 | bool hasEllipsis;
|
|---|
| [8b7ee09] | 361 | LinkageSpec::Spec linkage;
|
|---|
| [58dd019] | 362 | ConstantExpr *asmName;
|
|---|
| [44a81853] | 363 | std::list< Attribute * > attributes;
|
|---|
| [58dd019] | 364 | InitializerNode * initializer;
|
|---|
| [7305915] | 365 | bool extension = false;
|
|---|
| [13e3b50] | 366 | std::string error;
|
|---|
| [e994912] | 367 | StatementNode * asmStmt;
|
|---|
| [b87a5ed] | 368 |
|
|---|
| 369 | static UniqueName anonymous;
|
|---|
| [1db21619] | 370 | }; // DeclarationNode
|
|---|
| [51b73452] | 371 |
|
|---|
| [b6424d9] | 372 | Type * buildType( TypeData * type );
|
|---|
| [d1625f8] | 373 |
|
|---|
| [b6424d9] | 374 | static inline Type * maybeMoveBuildType( const DeclarationNode * orig ) {
|
|---|
| [a7c90d4] | 375 | Type * ret = orig ? orig->buildType() : nullptr;
|
|---|
| [4f147cc] | 376 | delete orig;
|
|---|
| 377 | return ret;
|
|---|
| 378 | }
|
|---|
| 379 |
|
|---|
| [7bf7fb9] | 380 | //##############################################################################
|
|---|
| 381 |
|
|---|
| [ac71a86] | 382 | class StatementNode final : public ParseNode {
|
|---|
| [bdd516a] | 383 | public:
|
|---|
| [e82aa9df] | 384 | StatementNode() { stmt = nullptr; }
|
|---|
| [b6424d9] | 385 | StatementNode( Statement * stmt ) : stmt( stmt ) {}
|
|---|
| 386 | StatementNode( DeclarationNode * decl );
|
|---|
| [e82aa9df] | 387 | virtual ~StatementNode() {}
|
|---|
| [51b73452] | 388 |
|
|---|
| [b6424d9] | 389 | virtual StatementNode * clone() const final { assert( false ); return nullptr; }
|
|---|
| [a7c90d4] | 390 | Statement * build() const { return const_cast<StatementNode *>(this)->stmt.release(); }
|
|---|
| [2f22cc4] | 391 |
|
|---|
| [44a81853] | 392 | virtual StatementNode * add_label( const std::string * name, DeclarationNode * attr = nullptr ) {
|
|---|
| 393 | stmt->get_labels().emplace_back( * name, nullptr, attr ? std::move( attr->attributes ) : std::list< Attribute * > {} );
|
|---|
| 394 | delete attr;
|
|---|
| [ac71a86] | 395 | delete name;
|
|---|
| [2f22cc4] | 396 | return this;
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| [b6424d9] | 399 | virtual StatementNode * append_last_case( StatementNode * );
|
|---|
| [1d4580a] | 400 |
|
|---|
| [62e5546] | 401 | virtual void print( std::ostream &os, int indent = 0 ) const override {}
|
|---|
| 402 | virtual void printList( std::ostream &os, int indent = 0 ) const override {}
|
|---|
| [2f22cc4] | 403 | private:
|
|---|
| [ac71a86] | 404 | std::unique_ptr<Statement> stmt;
|
|---|
| [2f22cc4] | 405 | }; // StatementNode
|
|---|
| 406 |
|
|---|
| [b6424d9] | 407 | Statement * build_expr( ExpressionNode * ctl );
|
|---|
| [1d4580a] | 408 |
|
|---|
| [2f22cc4] | 409 | struct ForCtl {
|
|---|
| [b6424d9] | 410 | ForCtl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :
|
|---|
| [e82aa9df] | 411 | init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {}
|
|---|
| [b6424d9] | 412 | ForCtl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :
|
|---|
| [e82aa9df] | 413 | init( new StatementNode( decl ) ), condition( condition ), change( change ) {}
|
|---|
| [2f22cc4] | 414 |
|
|---|
| [b6424d9] | 415 | StatementNode * init;
|
|---|
| 416 | ExpressionNode * condition;
|
|---|
| 417 | ExpressionNode * change;
|
|---|
| [2f22cc4] | 418 | };
|
|---|
| 419 |
|
|---|
| [b6424d9] | 420 | Statement * build_if( ExpressionNode * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
|
|---|
| 421 | Statement * build_switch( ExpressionNode * ctl, StatementNode * stmt );
|
|---|
| 422 | Statement * build_case( ExpressionNode * ctl );
|
|---|
| 423 | Statement * build_default();
|
|---|
| 424 | Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind = false );
|
|---|
| 425 | Statement * build_for( ForCtl * forctl, StatementNode * stmt );
|
|---|
| 426 | Statement * build_branch( BranchStmt::Type kind );
|
|---|
| 427 | Statement * build_branch( std::string * identifier, BranchStmt::Type kind );
|
|---|
| 428 | Statement * build_computedgoto( ExpressionNode * ctl );
|
|---|
| 429 | Statement * build_return( ExpressionNode * ctl );
|
|---|
| 430 | Statement * build_throw( ExpressionNode * ctl );
|
|---|
| 431 | Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt );
|
|---|
| 432 | Statement * build_catch( DeclarationNode * decl, StatementNode * stmt, bool catchAny = false );
|
|---|
| 433 | Statement * build_finally( StatementNode * stmt );
|
|---|
| 434 | Statement * build_compound( StatementNode * first );
|
|---|
| [2298f728] | 435 | Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
|
|---|
| [7f5566b] | 436 |
|
|---|
| [7bf7fb9] | 437 | //##############################################################################
|
|---|
| 438 |
|
|---|
| [aefcc3b] | 439 | template< typename SynTreeType, typename NodeType, template< typename, typename...> class Container, typename... Args >
|
|---|
| 440 | void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > &outputList ) {
|
|---|
| [b87a5ed] | 441 | SemanticError errors;
|
|---|
| [aefcc3b] | 442 | std::back_insert_iterator< Container< SynTreeType *, Args... > > out( outputList );
|
|---|
| [b6424d9] | 443 | const NodeType * cur = firstNode;
|
|---|
| [b87a5ed] | 444 |
|
|---|
| 445 | while ( cur ) {
|
|---|
| 446 | try {
|
|---|
| [b6424d9] | 447 | SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) );
|
|---|
| [b87a5ed] | 448 | if ( result ) {
|
|---|
| [294647b] | 449 | result->location = cur->location;
|
|---|
| [b6424d9] | 450 | * out++ = result;
|
|---|
| [b87a5ed] | 451 | } // if
|
|---|
| 452 | } catch( SemanticError &e ) {
|
|---|
| [294647b] | 453 | e.set_location( cur->location );
|
|---|
| [b87a5ed] | 454 | errors.append( e );
|
|---|
| 455 | } // try
|
|---|
| [7880579] | 456 | cur = dynamic_cast< NodeType * >( cur->get_next() );
|
|---|
| [b87a5ed] | 457 | } // while
|
|---|
| [a32b204] | 458 | if ( ! errors.isEmpty() ) {
|
|---|
| [b87a5ed] | 459 | throw errors;
|
|---|
| 460 | } // if
|
|---|
| [51b73452] | 461 | }
|
|---|
| 462 |
|
|---|
| 463 | // in DeclarationNode.cc
|
|---|
| [b6424d9] | 464 | void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList );
|
|---|
| 465 | void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList );
|
|---|
| 466 | void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList );
|
|---|
| [51b73452] | 467 |
|
|---|
| [7ecbb7e] | 468 | template< typename SynTreeType, typename NodeType >
|
|---|
| [b6424d9] | 469 | void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {
|
|---|
| [3a5131ed] | 470 | buildList( firstNode, outputList );
|
|---|
| [7ecbb7e] | 471 | delete firstNode;
|
|---|
| 472 | }
|
|---|
| 473 |
|
|---|
| [c8dfcd3] | 474 | // in ParseNode.cc
|
|---|
| 475 | std::ostream & operator<<( std::ostream & out, const ParseNode * node );
|
|---|
| [7ecbb7e] | 476 |
|
|---|
| [bdd516a] | 477 | #endif // PARSENODE_H
|
|---|
| [51b73452] | 478 |
|
|---|
| 479 | // Local Variables: //
|
|---|
| [b87a5ed] | 480 | // tab-width: 4 //
|
|---|
| 481 | // mode: c++ //
|
|---|
| 482 | // compile-command: "make install" //
|
|---|
| [51b73452] | 483 | // End: //
|
|---|