Changeset b6424d9
- Timestamp:
- Sep 11, 2016, 9:28:20 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 5b639ee, cb2b15c, d88f256a, ddcfb88
- Parents:
- 126e54f
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r126e54f rb6424d9 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 9 23:21:47201613 // Update Count : 4 0212 // Last Modified On : Sun Sep 11 09:24:11 2016 13 // Update Count : 438 14 14 // 15 15 … … 31 31 32 32 // These must remain in the same order as the corresponding DeclarationNode enumerations. 33 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", " " };33 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" }; 34 34 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" }; 35 35 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary", }; … … 389 389 390 390 void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) { 391 TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; 392 393 if ( (qsrc & qdst).any() ) { // common bits between qualifier masks?391 TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization 392 393 if ( (qsrc & qdst).any() ) { // common qualifier ? 394 394 for ( int i = 0; i < NoOfQualifier; i += 1 ) { // find common qualifiers 395 395 if ( qsrc[i] & qdst[i] ) { 396 error += string(error.empty() ? "" : ", ") + "duplicate " + DeclarationNode::qualifierName[i]; 396 if ( ! error.empty() ) error += ", "; // separator 397 error += string( "duplicate " ) + DeclarationNode::qualifierName[i]; 397 398 } // if 398 399 } // for 399 400 } // if 400 401 } // DeclarationNode::checkQualifiers 402 403 void DeclarationNode::checkStorageClasses( DeclarationNode *q ) { 404 if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) { 405 if ( ! error.empty() ) error += ", "; // separator 406 if ( storageClass == q->storageClass ) { // duplicate qualifier 407 error += string( "duplicate " ) + storageName[ storageClass ]; 408 } else { // only one storage class 409 error += string( "conflicting " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ]; 410 q->storageClass = storageClass; // FIX ERROR 411 } // if 412 if ( ! q->error.empty() ) error += ", " + q->error; // separator 413 } else { 414 if ( ! error.empty() ) { 415 if ( ! q->error.empty() ) error += ", " + q->error; // separator 416 } else if ( ! q->error.empty() ) error += q->error; 417 } // if 418 } // DeclarationNode::copyStorageClasses 419 420 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 421 isInline = isInline | q->isInline; 422 isNoreturn = isNoreturn | q->isNoreturn; 423 // do not overwrite an existing value with NoStorageClass 424 if ( q->storageClass != NoStorageClass ) { 425 assert( storageClass == NoStorageClass || storageClass == q->storageClass ); 426 storageClass = q->storageClass; 427 } // if 428 return this; 429 } // DeclarationNode::copyStorageClasses 401 430 402 431 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 403 432 if ( q ) { 404 copyStorageClasses(q); 433 checkStorageClasses( q ); 434 copyStorageClasses( q ); 405 435 if ( q->type ) { 406 436 if ( ! type ) { … … 429 459 return this; 430 460 } 431 432 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {433 isInline = isInline || q->isInline;434 isNoreturn = isNoreturn || q->isNoreturn;435 if ( storageClass == NoStorageClass ) {436 storageClass = q->storageClass;437 } else if ( q->storageClass != NoStorageClass ) {438 if ( storageClass == q->storageClass ) {439 q->error += string( "duplicate " ) + storageName[ storageClass ];440 } else { // can only have one storage class441 q->error += string( "multiple " ) + storageName[ storageClass ] + " & " + storageName[ q->storageClass ];442 } // if443 } // if444 if ( ! q->error.empty() ) {445 error += (! error.empty() ? ", " : "") + q->error;446 } // if447 return this;448 } // DeclarationNode::copyStorageClasses449 461 450 462 static void addTypeToType( TypeData *&src, TypeData *&dst ) { … … 504 516 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) { 505 517 if ( o ) { 518 checkStorageClasses( o ); 506 519 copyStorageClasses( o ); 507 520 if ( o->type ) { … … 751 764 } // if 752 765 newnode->type->forall = maybeClone( type->forall ); 766 assert( storageClass == NoStorageClass ); 753 767 newnode->copyStorageClasses( this ); 754 768 newnode->name = assign_strptr( newName ); … … 791 805 DeclarationNode *newnode = new DeclarationNode; 792 806 newnode->type = maybeClone( type ); 807 assert( storageClass == NoStorageClass ); 793 808 newnode->copyStorageClasses( this ); 794 809 newnode->name = assign_strptr( newName ); … … 798 813 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 799 814 if ( o ) { 815 assert( storageClass == NoStorageClass ); 800 816 o->copyStorageClasses( this ); 801 817 if ( type ) { -
src/Parser/ParseNode.h
r126e54f rb6424d9 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Sep 8 21:58:06201613 // Update Count : 58 712 // Last Modified On : Sat Sep 10 17:14:37 2016 13 // Update Count : 589 14 14 // 15 15 … … 41 41 public: 42 42 ParseNode() {}; 43 ParseNode( const std::string * name ) : name( *name ) { assert( false ); delete name; }43 ParseNode( const std::string * name ) : name( * name ) { assert( false ); delete name; } 44 44 ParseNode( const std::string &name ) : name( name ) { assert( false ); } 45 45 virtual ~ParseNode() { delete next; }; 46 virtual ParseNode * clone() const = 0;47 48 ParseNode * get_next() const { return next; }49 ParseNode * set_next( ParseNode *newlink ) { next = newlink; return this; }50 ParseNode * get_last() {51 ParseNode * current;46 virtual ParseNode * clone() const = 0; 47 48 ParseNode * get_next() const { return next; } 49 ParseNode * set_next( ParseNode * newlink ) { next = newlink; return this; } 50 ParseNode * get_last() { 51 ParseNode * current; 52 52 for ( current = this; current->get_next() != 0; current = current->get_next() ); 53 53 return current; 54 54 } 55 ParseNode * set_last( ParseNode *newlast ) {55 ParseNode * set_last( ParseNode * newlast ) { 56 56 if ( newlast != 0 ) get_last()->set_next( newlast ); 57 57 return this; … … 66 66 static int indent_by; 67 67 68 ParseNode * next = nullptr;68 ParseNode * next = nullptr; 69 69 std::string name; 70 70 }; // ParseNode … … 74 74 class InitializerNode : public ParseNode { 75 75 public: 76 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = 0 );77 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = 0 );76 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = 0 ); 77 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = 0 ); 78 78 ~InitializerNode(); 79 virtual InitializerNode * clone() const { assert( false ); return nullptr; }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; }79 virtual InitializerNode * clone() const { assert( false ); return nullptr; } 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 87 bool get_maybeConstructed() const { return maybeConstructed; } 88 88 89 InitializerNode * next_init() const { return kids; }89 InitializerNode * next_init() const { return kids; } 90 90 91 91 void print( std::ostream &os, int indent = 0 ) const; 92 92 void printOneLine( std::ostream & ) const; 93 93 94 virtual Initializer * build() const;94 virtual Initializer * build() const; 95 95 private: 96 ExpressionNode * expr;96 ExpressionNode * expr; 97 97 bool aggregate; 98 ExpressionNode * designator;// may be list99 InitializerNode * kids;98 ExpressionNode * designator; // may be list 99 InitializerNode * kids; 100 100 bool maybeConstructed; 101 101 }; // InitializerNode … … 106 106 public: 107 107 ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {} 108 ExpressionNode( Expression * expr, const std::string * name ) : ParseNode( name ), expr( expr ) {}108 ExpressionNode( Expression * expr, const std::string * name ) : ParseNode( name ), expr( expr ) {} 109 109 ExpressionNode( const ExpressionNode &other ); 110 110 virtual ~ExpressionNode() {} 111 virtual ExpressionNode * clone() const { return expr ? new ExpressionNode( expr->clone() ) : nullptr; }111 virtual ExpressionNode * clone() const { return expr ? new ExpressionNode( expr->clone() ) : nullptr; } 112 112 113 113 bool get_extension() const { return extension; } 114 ExpressionNode * set_extension( bool exten ) { extension = exten; return this; }114 ExpressionNode * set_extension( bool exten ) { extension = exten; return this; } 115 115 116 116 void print( std::ostream &os, int indent = 0 ) const {} … … 122 122 } 123 123 124 Expression * build() const { return const_cast<ExpressionNode*>(this)->expr.release(); }124 Expression * build() const { return const_cast<ExpressionNode*>(this)->expr.release(); } 125 125 private: 126 126 bool extension = false; … … 130 130 template< typename T > 131 131 struct maybeBuild_t< Expression, T > { 132 static inline Expression * doit( const T * orig ) {132 static inline Expression * doit( const T * orig ) { 133 133 if ( orig ) { 134 Expression * p = orig->build();134 Expression * p = orig->build(); 135 135 p->set_extension( orig->get_extension() ); 136 136 return p; … … 156 156 }; 157 157 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 );162 163 NameExpr * build_varref( const std::string *name, bool labelp = false );164 Expression * build_typevalue( DeclarationNode *decl );165 166 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode *expr_node );167 Expression * build_fieldSel( ExpressionNode *expr_node, NameExpr *member );168 Expression * build_pfieldSel( ExpressionNode *expr_node, NameExpr *member );169 Expression * build_addressOf( ExpressionNode *expr_node );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 );175 Expression * build_and( ExpressionNode *expr_node1, ExpressionNode *expr_node2 );176 Expression * build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind );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 );181 Expression * build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 );182 Expression * build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 );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 );187 Expression * build_range( ExpressionNode * low, ExpressionNode *high );188 Expression * build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand );189 Expression * build_valexpr( StatementNode *s );190 Expression * build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids );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 ); 162 163 NameExpr * build_varref( const std::string * name, bool labelp = false ); 164 Expression * build_typevalue( DeclarationNode * decl ); 165 166 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); 167 Expression * build_fieldSel( ExpressionNode * expr_node, NameExpr * member ); 168 Expression * build_pfieldSel( ExpressionNode * expr_node, NameExpr * member ); 169 Expression * build_addressOf( ExpressionNode * expr_node ); 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 ); 175 Expression * build_and( ExpressionNode * expr_node1, ExpressionNode * expr_node2 ); 176 Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind ); 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 ); 181 Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 ); 182 Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 ); 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 ); 187 Expression * build_range( ExpressionNode * low, ExpressionNode * high ); 188 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand ); 189 Expression * build_valexpr( StatementNode * s ); 190 Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ); 191 191 192 192 //############################################################################## … … 204 204 enum BuiltinType { Valist }; 205 205 206 static const char * qualifierName[];207 static const char * storageName[];208 static const char * basicTypeName[];209 static const char * modifierName[];210 static const char * aggregateName[];211 static const char * typeClassName[];212 static const char * builtinTypeName[];213 214 static DeclarationNode * newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle = false );215 static DeclarationNode * newQualifier( Qualifier );216 static DeclarationNode * newForall( DeclarationNode *);217 static DeclarationNode * newStorageClass( StorageClass );218 static DeclarationNode * newBasicType( BasicType );219 static DeclarationNode * newModifier( Modifier );220 static DeclarationNode * newBuiltinType( BuiltinType );221 static DeclarationNode * newFromTypedef( std::string *);222 static DeclarationNode * newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body );223 static DeclarationNode * newEnum( std::string *name, DeclarationNode *constants );224 static DeclarationNode * newEnumConstant( std::string *name, ExpressionNode *constant );225 static DeclarationNode * newName( std::string *);226 static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode *params );227 static DeclarationNode * newTypeParam( TypeClass, std::string *);228 static DeclarationNode * newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts );229 static DeclarationNode * newTraitUse( std::string *name, ExpressionNode *params );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 );237 static DeclarationNode * newAttr( std::string *, ExpressionNode *expr );238 static DeclarationNode * newAttr( std::string *, DeclarationNode *type );206 static const char * qualifierName[]; 207 static const char * storageName[]; 208 static const char * basicTypeName[]; 209 static const char * modifierName[]; 210 static const char * aggregateName[]; 211 static const char * typeClassName[]; 212 static const char * builtinTypeName[]; 213 214 static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle = false ); 215 static DeclarationNode * newQualifier( Qualifier ); 216 static DeclarationNode * newForall( DeclarationNode *); 217 static DeclarationNode * newStorageClass( StorageClass ); 218 static DeclarationNode * newBasicType( BasicType ); 219 static DeclarationNode * newModifier( Modifier ); 220 static DeclarationNode * newBuiltinType( BuiltinType ); 221 static DeclarationNode * newFromTypedef( std::string *); 222 static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 223 static DeclarationNode * newEnum( std::string * name, DeclarationNode * constants ); 224 static DeclarationNode * newEnumConstant( std::string * name, ExpressionNode * constant ); 225 static DeclarationNode * newName( std::string *); 226 static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode * params ); 227 static DeclarationNode * newTypeParam( TypeClass, std::string *); 228 static DeclarationNode * newTrait( std::string * name, DeclarationNode * params, DeclarationNode * asserts ); 229 static DeclarationNode * newTraitUse( std::string * name, ExpressionNode * params ); 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 ); 237 static DeclarationNode * newAttr( std::string *, ExpressionNode * expr ); 238 static DeclarationNode * newAttr( std::string *, DeclarationNode * type ); 239 239 240 240 DeclarationNode(); 241 241 ~DeclarationNode(); 242 DeclarationNode * clone() const;243 244 DeclarationNode * addQualifiers( DeclarationNode *);242 DeclarationNode * clone() const; 243 244 DeclarationNode * addQualifiers( DeclarationNode *); 245 245 void checkQualifiers( const TypeData *, const TypeData * ); 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 ); 260 DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions 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 269 DeclarationNode *appendList( DeclarationNode *node ) { 246 void checkStorageClasses( DeclarationNode *q ); 247 DeclarationNode * copyStorageClasses( DeclarationNode *); 248 DeclarationNode * addType( DeclarationNode *); 249 DeclarationNode * addTypedef(); 250 DeclarationNode * addAssertions( DeclarationNode *); 251 DeclarationNode * addName( std::string *); 252 DeclarationNode * addBitfield( ExpressionNode * size ); 253 DeclarationNode * addVarArgs(); 254 DeclarationNode * addFunctionBody( StatementNode * body ); 255 DeclarationNode * addOldDeclList( DeclarationNode * list ); 256 DeclarationNode * addPointer( DeclarationNode * qualifiers ); 257 DeclarationNode * addArray( DeclarationNode * array ); 258 DeclarationNode * addNewPointer( DeclarationNode * pointer ); 259 DeclarationNode * addNewArray( DeclarationNode * array ); 260 DeclarationNode * addParamList( DeclarationNode * list ); 261 DeclarationNode * addIdList( DeclarationNode * list ); // old-style functions 262 DeclarationNode * addInitializer( InitializerNode * init ); 263 264 DeclarationNode * cloneType( std::string * newName ); 265 DeclarationNode * cloneType( DeclarationNode * existing ); 266 DeclarationNode * cloneType( int ) { return cloneType( ( std::string *)0 ); } 267 DeclarationNode * cloneBaseType( std::string * newName ); 268 DeclarationNode * cloneBaseType( DeclarationNode * newdecl ); 269 270 DeclarationNode * appendList( DeclarationNode * node ) { 270 271 return (DeclarationNode *)set_last( node ); 271 272 } … … 274 275 void printList( std::ostream &os, int indent = 0 ) const; 275 276 276 Declaration * build() const;277 ::Type * buildType() const;277 Declaration * build() const; 278 ::Type * buildType() const; 278 279 279 280 bool get_hasEllipsis() const; 280 281 const std::string &get_name() const { return name; } 281 282 LinkageSpec::Spec get_linkage() const { return linkage; } 282 DeclarationNode * extractAggregate() const;283 DeclarationNode * extractAggregate() const; 283 284 bool has_enumeratorValue() const { return (bool)enumeratorValue; } 284 ExpressionNode * consume_enumeratorValue() const { return const_cast<DeclarationNode*>(this)->enumeratorValue.release(); }285 ExpressionNode * consume_enumeratorValue() const { return const_cast<DeclarationNode*>(this)->enumeratorValue.release(); } 285 286 286 287 bool get_extension() const { return extension; } 287 DeclarationNode * set_extension( bool exten ) { extension = exten; return this; }288 DeclarationNode * set_extension( bool exten ) { extension = exten; return this; } 288 289 public: 289 290 // StorageClass buildStorageClass() const; … … 306 307 BuiltinType builtin; 307 308 308 TypeData * type;309 TypeData * type; 309 310 std::string name; 310 311 // std::list< StorageClass > storageClasses; … … 312 313 bool isInline, isNoreturn; 313 314 std::list< std::string > attributes; 314 ExpressionNode * bitfieldWidth;315 ExpressionNode * bitfieldWidth; 315 316 std::unique_ptr<ExpressionNode> enumeratorValue; 316 InitializerNode * initializer;317 InitializerNode * initializer; 317 318 bool hasEllipsis; 318 319 LinkageSpec::Spec linkage; … … 323 324 }; // DeclarationNode 324 325 325 Type * buildType( TypeData *type );326 Type * buildType( TypeData * type ); 326 327 //Type::Qualifiers buildQualifiers( const TypeData::Qualifiers & qualifiers ); 327 328 328 static inline Type * maybeMoveBuildType( const DeclarationNode * orig ) {329 static inline Type * maybeMoveBuildType( const DeclarationNode * orig ) { 329 330 Type* ret = orig ? orig->buildType() : nullptr; 330 331 delete orig; … … 337 338 public: 338 339 StatementNode() { stmt = nullptr; } 339 StatementNode( Statement * stmt ) : stmt( stmt ) {}340 StatementNode( DeclarationNode * decl );340 StatementNode( Statement * stmt ) : stmt( stmt ) {} 341 StatementNode( DeclarationNode * decl ); 341 342 virtual ~StatementNode() {} 342 343 343 virtual StatementNode * clone() const final { assert( false ); return nullptr; }344 Statement * build() const { return const_cast<StatementNode*>(this)->stmt.release(); }345 346 virtual StatementNode * add_label( const std::string * name ) {347 stmt->get_labels().emplace_back( * name );344 virtual StatementNode * clone() const final { assert( false ); return nullptr; } 345 Statement * build() const { return const_cast<StatementNode*>(this)->stmt.release(); } 346 347 virtual StatementNode * add_label( const std::string * name ) { 348 stmt->get_labels().emplace_back( * name ); 348 349 delete name; 349 350 return this; 350 351 } 351 352 352 virtual StatementNode * append_last_case( StatementNode * );353 virtual StatementNode * append_last_case( StatementNode * ); 353 354 354 355 virtual void print( std::ostream &os, int indent = 0 ) {} … … 358 359 }; // StatementNode 359 360 360 Statement * build_expr( ExpressionNode *ctl );361 Statement * build_expr( ExpressionNode * ctl ); 361 362 362 363 struct ForCtl { 363 ForCtl( ExpressionNode * expr, ExpressionNode *condition, ExpressionNode *change ) :364 ForCtl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) : 364 365 init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {} 365 ForCtl( DeclarationNode * decl, ExpressionNode *condition, ExpressionNode *change ) :366 ForCtl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) : 366 367 init( new StatementNode( decl ) ), condition( condition ), change( change ) {} 367 368 368 StatementNode * init;369 ExpressionNode * condition;370 ExpressionNode * change;369 StatementNode * init; 370 ExpressionNode * condition; 371 ExpressionNode * change; 371 372 }; 372 373 373 Statement * build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt );374 Statement * build_switch( ExpressionNode *ctl, StatementNode *stmt );375 Statement * build_case( ExpressionNode *ctl );376 Statement * build_default();377 Statement * build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind = false );378 Statement * build_for( ForCtl *forctl, StatementNode *stmt );379 Statement * build_branch( BranchStmt::Type kind );380 Statement * build_branch( std::string *identifier, BranchStmt::Type kind );381 Statement * build_computedgoto( ExpressionNode *ctl );382 Statement * build_return( ExpressionNode *ctl );383 Statement * build_throw( ExpressionNode *ctl );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 );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 );374 Statement * build_if( ExpressionNode * ctl, StatementNode * then_stmt, StatementNode * else_stmt ); 375 Statement * build_switch( ExpressionNode * ctl, StatementNode * stmt ); 376 Statement * build_case( ExpressionNode * ctl ); 377 Statement * build_default(); 378 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind = false ); 379 Statement * build_for( ForCtl * forctl, StatementNode * stmt ); 380 Statement * build_branch( BranchStmt::Type kind ); 381 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ); 382 Statement * build_computedgoto( ExpressionNode * ctl ); 383 Statement * build_return( ExpressionNode * ctl ); 384 Statement * build_throw( ExpressionNode * ctl ); 385 Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt ); 386 Statement * build_catch( DeclarationNode * decl, StatementNode * stmt, bool catchAny = false ); 387 Statement * build_finally( StatementNode * stmt ); 388 Statement * build_compound( StatementNode * first ); 389 Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = 0, ExpressionNode * input = 0, ExpressionNode * clobber = 0, LabelNode * gotolabels = 0 ); 389 390 390 391 //############################################################################## 391 392 392 393 template< typename SynTreeType, typename NodeType > 393 void buildList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {394 void buildList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) { 394 395 SemanticError errors; 395 396 std::back_insert_iterator< std::list< SynTreeType * > > out( outputList ); 396 const NodeType * cur = firstNode;397 const NodeType * cur = firstNode; 397 398 398 399 while ( cur ) { 399 400 try { 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 ) );401 // SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) ); 402 SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) ); 402 403 if ( result ) { 403 * out++ = result;404 * out++ = result; 404 405 } // if 405 406 } catch( SemanticError &e ) { … … 414 415 415 416 // in DeclarationNode.cc 416 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList );417 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList );418 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList );417 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ); 418 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ); 419 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ); 419 420 420 421 template< typename SynTreeType, typename NodeType > 421 void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) {422 void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) { 422 423 buildList(firstNode, outputList); 423 424 delete firstNode; -
src/Parser/TypeData.h
r126e54f rb6424d9 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 9 23:20:55201613 // Update Count : 11 712 // Last Modified On : Sat Sep 10 09:42:54 2016 13 // Update Count : 118 14 14 // 15 15 … … 89 89 typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers; 90 90 Qualifiers qualifiers; 91 typedef std::bitset< DeclarationNode::NoStorageClass > StorageClasses; 92 StorageClasses storageclasses; 91 93 DeclarationNode * forall; 92 94 -
src/tests/.expect/declarationErrors.txt
r126e54f rb6424d9 2 2 Error: duplicate static in declaration of x1: static const volatile short int 3 3 4 Error: multipleextern & static in declaration of x2: extern const volatile short int4 Error: conflicting extern & static in declaration of x2: extern const volatile short int 5 5 6 Error: multiple extern & auto, multiple extern & static, multipleextern & static, duplicate extern in declaration of x3: extern const volatile short int6 Error: conflicting extern & auto, conflicting extern & static, conflicting extern & static, duplicate extern in declaration of x3: extern const volatile short int 7 7 8 8 Error: duplicate static in declaration of x4: static const volatile instance of const volatile struct __anonymous0
Note: See TracChangeset
for help on using the changeset viewer.