Changeset 68fe077a for src/Parser
- Timestamp:
- Mar 16, 2017, 8:23:42 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:
- 26ba208
- Parents:
- 6e8bd43
- git-author:
- Peter A. Buhr <pabuhr@…> (03/16/17 08:19:39)
- git-committer:
- Peter A. Buhr <pabuhr@…> (03/16/17 08:23:42)
- Location:
- src/Parser
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Parser/DeclarationNode.cc ¶
r6e8bd43 r68fe077a 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 15 23:36:49201713 // Update Count : 99712 // Last Modified On : Thu Mar 16 07:59:40 2017 13 // Update Count : 1003 14 14 // 15 15 … … 33 33 34 34 // These must remain in the same order as the corresponding DeclarationNode enumerations. 35 const char * DeclarationNode::StorageClasses::Names[] = { "extern", "static", "auto", "register", "_Thread_local", "NoStorageClassNames" };36 35 const char * DeclarationNode::FuncSpecifiers::Names[] = { "inline", "fortran", "_Noreturn", "NoFunctionSpecifierNames" }; 37 36 const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicTypeNames" }; … … 181 180 182 181 183 DeclarationNode * DeclarationNode::newStorageClass( StorageClasses sc ) {182 DeclarationNode * DeclarationNode::newStorageClass( Type::StorageClasses sc ) { 184 183 DeclarationNode * newnode = new DeclarationNode; 185 184 newnode->storageClasses = sc; … … 458 457 if ( storageClasses.any() && src->storageClasses.any() ) { // any reason to check ? 459 458 if ( (storageClasses.val & src->storageClasses.val ) != 0 ) { // duplicates ? 460 for ( unsigned int i = 0; i < NumStorageClass; i += 1 ) { // find duplicates459 for ( unsigned int i = 0; i < Type::NumStorageClass; i += 1 ) { // find duplicates 461 460 if ( storageClasses[i] && src->storageClasses[i] ) { 462 appendError( error, string( "duplicate " ) + StorageClasses::Names[i] );461 appendError( error, string( "duplicate " ) + Type::StorageClasses::Names[i] ); 463 462 } // if 464 463 } // for 465 464 // src is the new item being added and has a single bit 466 465 } else if ( ! src->storageClasses.is_threadlocal ) { // conflict ? 467 appendError( error, string( "conflicting " ) + StorageClasses::Names[ffs( storageClasses.val ) - 1] +468 " & " + StorageClasses::Names[ffs( src->storageClasses.val ) - 1] );466 appendError( error, string( "conflicting " ) + Type::StorageClasses::Names[ffs( storageClasses.val ) - 1] + 467 " & " + Type::StorageClasses::Names[ffs( src->storageClasses.val ) - 1] ); 469 468 src->storageClasses.val = 0; // FIX to preserve invariant of one basic storage specifier 470 469 } // if … … 970 969 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) { 971 970 StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 972 auto obj = new ObjectDecl( "", DeclarationNode::StorageClasses(), linkage, nullptr, inst, nullptr );971 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr ); 973 972 obj->location = cur->location; 974 973 * out++ = obj; … … 976 975 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) { 977 976 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 978 auto obj = new ObjectDecl( "", DeclarationNode::StorageClasses(), linkage, nullptr, inst, nullptr );977 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr ); 979 978 obj->location = cur->location; 980 979 * out++ = obj; … … 1023 1022 assertf( sizeof(kindMap)/sizeof(kindMap[0] == NoTypeClass-1), "DeclarationNode::build: kindMap is out of sync." ); 1024 1023 assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." ); 1025 TypeDecl * ret = new TypeDecl( *name, DeclarationNode::StorageClasses(), nullptr, kindMap[ variable.tyClass ] );1024 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ] ); 1026 1025 buildList( variable.assertions, ret->get_assertions() ); 1027 1026 return ret; -
TabularUnified src/Parser/ParseNode.h ¶
r6e8bd43 r68fe077a 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 15 23:31:02201713 // Update Count : 77 012 // Last Modified On : Thu Mar 16 07:46:33 2017 13 // Update Count : 772 14 14 // 15 15 … … 201 201 class DeclarationNode : public ParseNode { 202 202 public: 203 // These must remain in the same order as the corresponding DeclarationNode names.204 205 enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, Threadlocal = 1 << 4, NumStorageClass = 5 };206 union StorageClasses {207 static const char * Names[];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 217 StorageClasses() : val( 0 ) {}218 StorageClasses( unsigned int val ) : val( val ) {}219 bool operator[]( unsigned int i ) const { return val & (1 << i); }220 bool any() const { return val != 0; }221 void print( std::ostream & os ) const {222 if ( (*this).any() ) { // any storage classes ?223 for ( unsigned int i = 0; i < NumStorageClass; i += 1 ) {224 if ( (*this)[i] ) {225 os << StorageClasses::Names[i] << ' ';226 } // if227 } // for228 } // if229 }230 }; // StorageClasses231 232 203 enum { Inline = 1 << 0, Noreturn = 1 << 1, Fortran = 1 << 2, NumFuncSpecifier = 3 }; 233 204 union FuncSpecifiers { … … 270 241 static const char * builtinTypeNames[]; 271 242 272 static DeclarationNode * newStorageClass( StorageClasses );243 static DeclarationNode * newStorageClass( Type::StorageClasses ); 273 244 static DeclarationNode * newFuncSpecifier( FuncSpecifiers ); 274 245 static DeclarationNode * newTypeQualifier( Type::Qualifiers ); … … 368 339 TypeData * type; 369 340 370 StorageClasses storageClasses;341 Type::StorageClasses storageClasses; 371 342 FuncSpecifiers funcSpecs; 372 343 -
TabularUnified src/Parser/TypeData.cc ¶
r6e8bd43 r68fe077a 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 15 22:53:04201713 // Update Count : 55 712 // Last Modified On : Thu Mar 16 07:54:50 2017 13 // Update Count : 558 14 14 // 15 15 … … 398 398 // add dtor: void ^?{}(T *) 399 399 FunctionType * dtorType = new FunctionType( Type::Qualifiers(), false ); 400 dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );401 td->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, dtorType, nullptr ) );400 dtorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) ); 401 td->get_assertions().push_front( new FunctionDecl( "^?{}", Type::StorageClasses(), LinkageSpec::Cforall, dtorType, nullptr ) ); 402 402 403 403 // add copy ctor: void ?{}(T *, T) 404 404 FunctionType * copyCtorType = new FunctionType( Type::Qualifiers(), false ); 405 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );406 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );407 td->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, copyCtorType, nullptr ) );405 copyCtorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) ); 406 copyCtorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) ); 407 td->get_assertions().push_front( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, copyCtorType, nullptr ) ); 408 408 409 409 // add default ctor: void ?{}(T *) 410 410 FunctionType * ctorType = new FunctionType( Type::Qualifiers(), false ); 411 ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );412 td->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, ctorType, nullptr ) );411 ctorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) ); 412 td->get_assertions().push_front( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, ctorType, nullptr ) ); 413 413 414 414 // add assignment operator: T * ?=?(T *, T) 415 415 FunctionType * assignType = new FunctionType( Type::Qualifiers(), false ); 416 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );417 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );418 assignType->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );419 td->get_assertions().push_front( new FunctionDecl( "?=?", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, assignType, nullptr ) );416 assignType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) ); 417 assignType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) ); 418 assignType->get_returnVals().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) ); 419 td->get_assertions().push_front( new FunctionDecl( "?=?", Type::StorageClasses(), LinkageSpec::Cforall, assignType, nullptr ) ); 420 420 } // if 421 421 } // for … … 726 726 } // buildAggInst 727 727 728 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, DeclarationNode::StorageClasses scs ) {728 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, Type::StorageClasses scs ) { 729 729 assert( td->kind == TypeData::Symbolic ); 730 730 NamedTypeDecl * ret; … … 778 778 } // buildTypeof 779 779 780 Declaration * buildDecl( const TypeData * td, const string &name, DeclarationNode::StorageClasses scs, Expression * bitfieldWidth, DeclarationNode::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, ConstantExpr *asmName, Initializer * init, std::list< Attribute * > attributes ) {780 Declaration * buildDecl( const TypeData * td, const string &name, Type::StorageClasses scs, Expression * bitfieldWidth, DeclarationNode::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, ConstantExpr *asmName, Initializer * init, std::list< Attribute * > attributes ) { 781 781 if ( td->kind == TypeData::Function ) { 782 782 if ( td->function.idList ) { // KR function ? … … 814 814 break; 815 815 default: 816 ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType * >( buildDecl( td->base, "", DeclarationNode::StorageClasses(), nullptr, DeclarationNode::FuncSpecifiers(), LinkageSpec::Cforall, nullptr ) ) );816 ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType * >( buildDecl( td->base, "", Type::StorageClasses(), nullptr, DeclarationNode::FuncSpecifiers(), LinkageSpec::Cforall, nullptr ) ) ); 817 817 } // switch 818 818 } else { 819 ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );819 ft->get_returnVals().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) ); 820 820 } // if 821 821 return ft; -
TabularUnified src/Parser/TypeData.h ¶
r6e8bd43 r68fe077a 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 15 22:10:23201713 // Update Count : 18 312 // Last Modified On : Thu Mar 16 07:53:41 2017 13 // Update Count : 184 14 14 // 15 15 … … 109 109 TupleType * buildTuple( const TypeData * ); 110 110 TypeofType * buildTypeof( const TypeData * ); 111 Declaration * buildDecl( const TypeData *, const std::string &, DeclarationNode::StorageClasses, Expression *, DeclarationNode::FuncSpecifiers funcSpec, LinkageSpec::Spec, ConstantExpr *asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );111 Declaration * buildDecl( const TypeData *, const std::string &, Type::StorageClasses, Expression *, DeclarationNode::FuncSpecifiers funcSpec, LinkageSpec::Spec, ConstantExpr *asmName, Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() ); 112 112 FunctionType * buildFunction( const TypeData * ); 113 113 void buildKRFunction( const TypeData::Function_t & function ); -
TabularUnified src/Parser/parser.yy ¶
r6e8bd43 r68fe077a 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 15 22:06:22201713 // Update Count : 230 812 // Last Modified On : Thu Mar 16 08:00:59 2017 13 // Update Count : 2309 14 14 // 15 15 … … 1449 1449 storage_class: 1450 1450 EXTERN 1451 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Extern ); }1451 { $$ = DeclarationNode::newStorageClass( Type::Extern ); } 1452 1452 | STATIC 1453 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Static ); }1453 { $$ = DeclarationNode::newStorageClass( Type::Static ); } 1454 1454 | AUTO 1455 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Auto ); }1455 { $$ = DeclarationNode::newStorageClass( Type::Auto ); } 1456 1456 | REGISTER 1457 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Register ); }1457 { $$ = DeclarationNode::newStorageClass( Type::Register ); } 1458 1458 | THREADLOCAL // C11 1459 { $$ = DeclarationNode::newStorageClass( DeclarationNode::Threadlocal ); }1459 { $$ = DeclarationNode::newStorageClass( Type::Threadlocal ); } 1460 1460 // Put function specifiers here to simplify parsing rules, but separate them semantically. 1461 1461 | INLINE // C99
Note: See TracChangeset
for help on using the changeset viewer.