- Timestamp:
- Aug 29, 2016, 10:52:33 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, 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:
- 3403534
- Parents:
- 8f6f47d7
- Location:
- src/Parser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Parser/DeclarationNode.cc ¶
r8f6f47d7 r28307be 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 15:55:12201613 // Update Count : 3 1112 // Last Modified On : Mon Aug 29 22:30:56 2016 13 // Update Count : 327 14 14 // 15 15 … … 42 42 43 43 extern LinkageSpec::Spec linkage; // defined in parser.yy 44 45 DeclarationNode::DeclarationNode() 46 : type( 0 ) 47 , storageClass( NoStorageClass ) 48 , isInline( false ) 49 , isNoreturn( false ) 50 , bitfieldWidth( 0 ) 51 , initializer( 0 ) 52 , hasEllipsis( false ) 53 , linkage( ::linkage ) 54 , extension( false ) 55 , error() { 56 attr.expr = nullptr; 57 attr.type = nullptr; 58 59 variable.tyClass = DeclarationNode::Type; 60 variable.assertions = nullptr; 61 } 62 63 DeclarationNode::~DeclarationNode() { 64 delete attr.expr; 65 delete attr.type; 66 delete type; 67 delete bitfieldWidth; 68 delete initializer; 69 } 44 70 45 71 DeclarationNode *DeclarationNode::clone() const { … … 55 81 newnode->set_next( maybeClone( get_next() ) ); 56 82 newnode->linkage = linkage; 83 84 newnode->variable.assertions = maybeClone( variable.assertions ); 85 newnode->variable.name = variable.name; 86 newnode->variable.tyClass = variable.tyClass; 87 88 newnode->attr.expr = maybeClone( attr.expr ); 89 newnode->attr.type = maybeClone( attr.type ); 57 90 return newnode; 58 91 } // DeclarationNode::clone 59 60 DeclarationNode::DeclarationNode()61 : type( 0 )62 , storageClass( NoStorageClass )63 , isInline( false )64 , isNoreturn( false )65 , bitfieldWidth( 0 )66 , initializer( 0 )67 , hasEllipsis( false )68 , linkage( ::linkage )69 , extension( false )70 , error() {71 }72 73 DeclarationNode::~DeclarationNode() {74 delete type;75 delete bitfieldWidth;76 delete initializer;77 }78 92 79 93 bool DeclarationNode::get_hasEllipsis() const { … … 248 262 newnode->name = assign_strptr( name ); 249 263 newnode->type = new TypeData( TypeData::Variable ); 250 newnode-> type->variable.tyClass = tc;251 newnode-> type->variable.name = newnode->name;264 newnode->variable.tyClass = tc; 265 newnode->variable.name = newnode->name; 252 266 return newnode; 253 267 } // DeclarationNode::newTypeParam … … 341 355 DeclarationNode *newnode = new DeclarationNode; 342 356 newnode->type = new TypeData( TypeData::Attr ); 343 newnode-> type->attr.name = assign_strptr( name );344 newnode-> type->attr.expr = expr;357 newnode->attr.name = assign_strptr( name ); 358 newnode->attr.expr = expr; 345 359 return newnode; 346 360 } … … 349 363 DeclarationNode *newnode = new DeclarationNode; 350 364 newnode->type = new TypeData( TypeData::Attr ); 351 newnode-> type->attr.name = assign_strptr( name );352 newnode-> type->attr.type = type;365 newnode->attr.name = assign_strptr( name ); 366 newnode->attr.type = type; 353 367 return newnode; 354 368 } … … 542 556 break; 543 557 case TypeData::Variable: 544 if ( type->variable.assertions ) {545 type->variable.assertions->appendList( assertions );558 if ( variable.assertions ) { 559 variable.assertions->appendList( assertions ); 546 560 } else { 547 type->variable.assertions = assertions;561 variable.assertions = assertions; 548 562 } // if 549 563 break; … … 896 910 if ( ! error.empty() ) throw SemanticError( error, this ); 897 911 if ( type ) { 898 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 912 if ( type->kind == TypeData::Variable ) { 913 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 914 TypeDecl * ret = new TypeDecl( variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ variable.tyClass ] ); 915 buildList( variable.assertions, ret->get_assertions() ); 916 return ret; 917 } else { 918 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 919 } // if 899 920 } // if 900 921 if ( ! isInline && ! isNoreturn ) { … … 933 954 return ret; 934 955 } 956 case TypeData::Attr: { 957 assert( type->kind == TypeData::Attr ); 958 // assert( type->attr ); 959 AttrType * ret; 960 if ( attr.expr ) { 961 ret = new AttrType( buildQualifiers( type ), attr.name, attr.expr->build() ); 962 } else { 963 assert( attr.type ); 964 ret = new AttrType( buildQualifiers( type ), attr.name, attr.type->buildType() ); 965 } // if 966 return ret; 967 } 935 968 default: 936 969 return typebuild( type ); -
TabularUnified src/Parser/ParseNode.h ¶
r8f6f47d7 r28307be 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 10:19:01201613 // Update Count : 5 7912 // Last Modified On : Mon Aug 29 21:45:43 2016 13 // Update Count : 583 14 14 // 15 15 … … 290 290 // bool buildFuncSpecifier( StorageClass key ) const; 291 291 292 struct Enumeration_t { 293 std::string name; 294 DeclarationNode * constants; 295 }; 296 Enumeration_t enumeration; 297 298 struct Variable_t { 299 DeclarationNode::TypeClass tyClass; 300 std::string name; 301 DeclarationNode * assertions; 302 }; 303 Variable_t variable; 304 305 struct Attr_t { 306 std::string name; 307 ExpressionNode * expr; 308 DeclarationNode * type; 309 }; 310 Attr_t attr; 311 292 312 BuiltinType builtin; 293 313 -
TabularUnified src/Parser/TypeData.cc ¶
r8f6f47d7 r28307be 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 15:54:55201613 // Update Count : 2 6612 // Last Modified On : Mon Aug 29 22:31:53 2016 13 // Update Count : 277 14 14 // 15 15 … … 74 74 case Variable: 75 75 // variable = new Variable_t; 76 variable.tyClass = DeclarationNode::Type;77 variable.assertions = 0;76 // variable.tyClass = DeclarationNode::Type; 77 // variable.assertions = 0; 78 78 break; 79 79 case Tuple: … … 85 85 typeexpr = nullptr; 86 86 break; 87 case Attr: 88 // attr = new Attr_t; 89 // attr.expr = nullptr; 90 // attr.type = nullptr; 91 break; 87 92 case Builtin: 88 93 // builtin = new Builtin_t; 89 break;90 case Attr:91 // attr = new Attr_t;92 attr.expr = nullptr;93 attr.type = nullptr;94 94 break; 95 95 } // switch … … 143 143 break; 144 144 case Variable: 145 delete variable.assertions;145 // delete variable.assertions; 146 146 // delete variable; 147 147 break; … … 154 154 delete typeexpr; 155 155 break; 156 case Attr: 157 // delete attr.expr; 158 // delete attr.type; 159 // delete attr; 160 break; 156 161 case Builtin: 157 162 // delete builtin; 158 break;159 case Attr:160 delete attr.expr;161 delete attr.type;162 // delete attr;163 163 break; 164 164 } // switch … … 219 219 break; 220 220 case Variable: 221 newtype->variable.assertions = maybeClone( variable.assertions ); 222 newtype->variable.name = variable.name; 223 newtype->variable.tyClass = variable.tyClass; 221 assert( false ); 222 // newtype->variable.assertions = maybeClone( variable.assertions ); 223 // newtype->variable.name = variable.name; 224 // newtype->variable.tyClass = variable.tyClass; 224 225 break; 225 226 case Tuple: … … 229 230 newtype->typeexpr = maybeClone( typeexpr ); 230 231 break; 232 case Attr: 233 assert( false ); 234 // newtype->attr.expr = maybeClone( attr.expr ); 235 // newtype->attr.type = maybeClone( attr.type ); 236 break; 231 237 case Builtin: 238 assert( false ); 232 239 // newtype->builtin = builtin; 233 break;234 case Attr:235 newtype->attr.expr = maybeClone( attr.expr );236 newtype->attr.type = maybeClone( attr.type );237 240 break; 238 241 } // switch … … 382 385 break; 383 386 case Variable: 384 os << DeclarationNode::typeClassName[ variable.tyClass ] << " variable ";385 if ( variable.assertions ) {386 os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;387 variable.assertions->printList( os, indent + 4 );388 os << string( indent + 2, ' ' );389 } // if387 // os << DeclarationNode::typeClassName[ variable.tyClass ] << " variable "; 388 // if ( variable.assertions ) { 389 // os << endl << string( indent + 2, ' ' ) << "with assertions" << endl; 390 // variable.assertions->printList( os, indent + 4 ); 391 // os << string( indent + 2, ' ' ); 392 // } // if 390 393 break; 391 394 case Tuple: … … 403 406 break; 404 407 case Attr: 405 os << "attribute type decl " << attr.name << " applied to ";406 if ( attr.expr ) {407 attr.expr->print( os, indent + 2 );408 } // if409 if ( attr.type ) {410 attr.type->print( os, indent + 2 );411 } // if408 // os << "attribute type decl " << attr.name << " applied to "; 409 // if ( attr.expr ) { 410 // attr.expr->print( os, indent + 2 ); 411 // } // if 412 // if ( attr.type ) { 413 // attr.type->print( os, indent + 2 ); 414 // } // if 412 415 break; 413 416 case Builtin: … … 479 482 return new VarArgsType( buildQualifiers( td ) ); 480 483 case TypeData::Attr: 484 assert( false ); 481 485 return buildAttr( td ); 482 486 case TypeData::Symbolic: … … 824 828 825 829 TypeDecl * buildVariable( const TypeData * td ) { 826 assert( td->kind == TypeData::Variable ); 827 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 828 829 TypeDecl * ret = new TypeDecl( td->variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable.tyClass ] ); 830 buildList( td->variable.assertions, ret->get_assertions() ); 831 return ret; 830 assert( false ); 831 return nullptr; 832 // assert( td->kind == TypeData::Variable ); 833 // static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 834 835 // TypeDecl * ret = new TypeDecl( td->variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable.tyClass ] ); 836 // buildList( td->variable.assertions, ret->get_assertions() ); 837 // return ret; 832 838 } // buildSymbolic 833 839 … … 870 876 871 877 AttrType * buildAttr( const TypeData * td ) { 872 assert( td->kind == TypeData::Attr ); 873 // assert( td->attr ); 874 AttrType * ret; 875 if ( td->attr.expr ) { 876 ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.expr->build() ); 877 } else { 878 assert( td->attr.type ); 879 ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.type->buildType() ); 880 } // if 881 return ret; 878 assert( false ); 879 return nullptr; 880 // assert( td->kind == TypeData::Attr ); 881 // // assert( td->attr ); 882 // AttrType * ret; 883 // if ( td->attr.expr ) { 884 // ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.expr->build() ); 885 // } else { 886 // assert( td->attr.type ); 887 // ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.type->buildType() ); 888 // } // if 889 // return ret; 882 890 } // buildAttr 883 891 … … 912 920 return buildSymbolic( td, name, sc ); 913 921 } else if ( td->kind == TypeData::Variable ) { 922 assert( false ); 914 923 return buildVariable( td ); 915 924 } else { -
TabularUnified src/Parser/TypeData.h ¶
r8f6f47d7 r28307be 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 15:54:00201613 // Update Count : 1 0612 // Last Modified On : Mon Aug 29 22:31:52 2016 13 // Update Count : 110 14 14 // 15 15 … … 24 24 struct TypeData { 25 25 enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst, 26 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr } kind;26 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr }; 27 27 28 28 struct Basic_t { … … 73 73 }; 74 74 75 struct Variable_t {76 DeclarationNode::TypeClass tyClass;77 std::string name;78 DeclarationNode * assertions;79 };80 81 75 // struct Tuple_t { 82 76 // DeclarationNode * members; … … 91 85 // }; 92 86 93 struct Attr_t { 94 std::string name; 95 ExpressionNode * expr; 96 DeclarationNode * type; 97 }; 98 87 Kind kind; 99 88 TypeData * base; 100 89 typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers; … … 109 98 Function_t function; 110 99 Symbolic_t symbolic; 111 Variable_t variable;112 100 DeclarationNode * tuple; 113 101 ExpressionNode * typeexpr; 114 Attr_t attr;102 //Attr_t attr; 115 103 // DeclarationNode::BuiltinType builtin; 116 104
Note: See TracChangeset
for help on using the changeset viewer.