Changeset 3b56166 for src/Parser
- Timestamp:
- Feb 10, 2020, 11:17:38 AM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 3966d9a, 41efd33
- Parents:
- 807a632 (diff), d231700 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/Parser
- Files:
-
- 1 deleted
- 8 edited
-
DeclarationNode.cc (modified) (12 diffs)
-
ExpressionNode.cc (modified) (4 diffs)
-
LinkageSpec.cc (deleted)
-
ParseNode.h (modified) (7 diffs)
-
TypeData.cc (modified) (9 diffs)
-
TypeData.h (modified) (3 diffs)
-
lex.ll (modified) (2 diffs)
-
module.mk (modified) (2 diffs)
-
parser.yy (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r807a632 r3b56166 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 25 22:17:10201913 // Update Count : 11 1612 // Last Modified On : Mon Dec 16 15:32:22 2019 13 // Update Count : 1133 14 14 // 15 15 … … 24 24 #include "Common/UniqueName.h" // for UniqueName 25 25 #include "Common/utility.h" // for maybeClone, maybeBuild, CodeLocation 26 #include "Parser/LinkageSpec.h" // for Spec, linkageName, Cforall27 26 #include "Parser/ParseNode.h" // for DeclarationNode, ExpressionNode 27 #include "SynTree/LinkageSpec.h" // for Spec, linkageName, Cforall 28 28 #include "SynTree/Attribute.h" // for Attribute 29 29 #include "SynTree/Declaration.h" // for TypeDecl, ObjectDecl, Declaration … … 47 47 const char * DeclarationNode::signednessNames[] = { "signed", "unsigned", "NoSignednessNames" }; 48 48 const char * DeclarationNode::lengthNames[] = { "short", "long", "long long", "NoLengthNames" }; 49 const char * DeclarationNode::aggregateNames[] = { "struct", "union", "trait", "coroutine", "monitor", "thread", "NoAggregateNames" };50 const char * DeclarationNode::typeClassNames[] = { "otype", "dtype", "ftype", "NoTypeClassNames" };51 49 const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "__auto_type", "zero_t", "one_t", "NoBuiltinTypeNames" }; 52 50 … … 59 57 60 58 // variable.name = nullptr; 61 variable.tyClass = NoTypeClass;59 variable.tyClass = TypeDecl::NUMBER_OF_KINDS; 62 60 variable.assertions = nullptr; 63 61 variable.initializer = nullptr; … … 135 133 136 134 if ( linkage != LinkageSpec::Cforall ) { 137 os << LinkageSpec:: linkageName( linkage ) << " ";135 os << LinkageSpec::name( linkage ) << " "; 138 136 } // if 139 137 … … 267 265 } 268 266 269 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {267 DeclarationNode * DeclarationNode::newAggregate( AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) { 270 268 DeclarationNode * newnode = new DeclarationNode; 271 269 newnode->type = new TypeData( TypeData::Aggregate ); … … 313 311 } // DeclarationNode::newFromTypeGen 314 312 315 DeclarationNode * DeclarationNode::newTypeParam( Type Classtc, const string * name ) {313 DeclarationNode * DeclarationNode::newTypeParam( TypeDecl::Kind tc, const string * name ) { 316 314 DeclarationNode * newnode = new DeclarationNode; 317 315 newnode->type = nullptr; … … 328 326 newnode->type = new TypeData( TypeData::Aggregate ); 329 327 newnode->type->aggregate.name = name; 330 newnode->type->aggregate.kind = Trait;328 newnode->type->aggregate.kind = AggregateDecl::Trait; 331 329 newnode->type->aggregate.params = params; 332 330 newnode->type->aggregate.fields = asserts; … … 338 336 newnode->type = new TypeData( TypeData::AggregateInst ); 339 337 newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate ); 340 newnode->type->aggInst.aggregate->aggregate.kind = Trait;338 newnode->type->aggInst.aggregate->aggregate.kind = AggregateDecl::Trait; 341 339 newnode->type->aggInst.aggregate->aggregate.name = name; 342 340 newnode->type->aggInst.params = params; … … 671 669 672 670 DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) { 673 if ( variable.tyClass != NoTypeClass) {671 if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) { 674 672 if ( variable.assertions ) { 675 673 variable.assertions->appendList( assertions ); … … 876 874 877 875 DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) { 878 assertf( variable.tyClass != NoTypeClass, "Called addTypeInitializer on something that isn't a type variable." );876 assertf( variable.tyClass != TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." ); 879 877 variable.initializer = init; 880 878 return this; … … 1075 1073 } // if 1076 1074 1077 if ( variable.tyClass != NoTypeClass) {1075 if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) { 1078 1076 // otype is internally converted to dtype + otype parameters 1079 1077 static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype }; 1080 assertf( sizeof(kindMap)/sizeof(kindMap[0]) == NoTypeClass, "DeclarationNode::build: kindMap is out of sync." );1078 static_assert( sizeof(kindMap)/sizeof(kindMap[0]) == TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." ); 1081 1079 assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." ); 1082 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == Otype, variable.initializer ? variable.initializer->buildType() : nullptr );1080 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype, variable.initializer ? variable.initializer->buildType() : nullptr ); 1083 1081 buildList( variable.assertions, ret->get_assertions() ); 1084 1082 return ret; -
src/Parser/ExpressionNode.cc
r807a632 r3b56166 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 4 20:57:55201913 // Update Count : 9 7812 // Last Modified On : Wed Dec 18 21:14:58 2019 13 // Update Count : 981 14 14 // 15 15 … … 265 265 static const BasicType::Kind kind[2][12] = { 266 266 { BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::uuFloat80, BasicType::uuFloat128, BasicType::uFloat16, BasicType::uFloat32, BasicType::uFloat32x, BasicType::uFloat64, BasicType::uFloat64x, BasicType::uFloat128, BasicType::uFloat128x }, 267 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, (BasicType::Kind)-1, (BasicType::Kind)-1, BasicType::uFloat16Complex, BasicType::uFloat32Complex, BasicType::uFloat32xComplex, BasicType::uFloat64Complex, BasicType::uFloat64xComplex, BasicType::uFloat128Complex, BasicType::uFloat128xComplex },267 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::NUMBER_OF_BASIC_TYPES, BasicType::NUMBER_OF_BASIC_TYPES, BasicType::uFloat16Complex, BasicType::uFloat32Complex, BasicType::uFloat32xComplex, BasicType::uFloat64Complex, BasicType::uFloat64xComplex, BasicType::uFloat128Complex, BasicType::uFloat128xComplex }, 268 268 }; 269 269 … … 374 374 375 375 Expression * build_field_name_FLOATING_DECIMALconstant( const string & str ) { 376 if ( str[str.size() -1] != '.' ) SemanticError( yylloc, "invalid tuple index " + str );376 if ( str[str.size() - 1] != '.' ) SemanticError( yylloc, "invalid tuple index " + str ); 377 377 Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) ); 378 378 delete &str; … … 434 434 } // build_cast 435 435 436 Expression * build_keyword_cast( KeywordCastExpr::Targettarget, ExpressionNode * expr_node ) {436 Expression * build_keyword_cast( AggregateDecl::Aggregate target, ExpressionNode * expr_node ) { 437 437 return new KeywordCastExpr( maybeMoveBuild< Expression >(expr_node), target ); 438 438 } -
src/Parser/ParseNode.h
r807a632 r3b56166 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 25 22:17:10 201913 // Update Count : 8 7612 // Last Modified On : Fri Feb 7 17:56:02 2020 13 // Update Count : 891 14 14 // 15 15 … … 28 28 #include "Common/UniqueName.h" // for UniqueName 29 29 #include "Common/utility.h" // for maybeClone, maybeBuild 30 #include "Parser/LinkageSpec.h" // for Spec 30 #include "SynTree/LinkageSpec.h" // for Spec 31 #include "SynTree/Declaration.h" // for Aggregate 31 32 #include "SynTree/Expression.h" // for Expression, ConstantExpr (ptr only) 32 33 #include "SynTree/Label.h" // for Label … … 184 185 185 186 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); 186 Expression * build_keyword_cast( KeywordCastExpr::Targettarget, ExpressionNode * expr_node );187 Expression * build_keyword_cast( AggregateDecl::Aggregate target, ExpressionNode * expr_node ); 187 188 Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); 188 189 Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ); … … 217 218 enum Length { Short, Long, LongLong, NoLength }; 218 219 static const char * lengthNames[]; 219 enum Aggregate { Struct, Union, Exception, Trait, Coroutine, Monitor, Thread, NoAggregate };220 static const char * aggregateNames[];221 enum TypeClass { Otype, Dtype, Ftype, Ttype, NoTypeClass };222 static const char * typeClassNames[];223 220 enum BuiltinType { Valist, AutoType, Zero, One, NoBuiltinType }; 224 221 static const char * builtinTypeNames[]; … … 237 234 static DeclarationNode * newQualifiedType( DeclarationNode *, DeclarationNode * ); 238 235 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ); 239 static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );236 static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 240 237 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body ); 241 238 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 242 239 static DeclarationNode * newName( const std::string * ); 243 240 static DeclarationNode * newFromTypeGen( const std::string *, ExpressionNode * params ); 244 static DeclarationNode * newTypeParam( Type Class, const std::string * );241 static DeclarationNode * newTypeParam( TypeDecl::Kind, const std::string * ); 245 242 static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts ); 246 243 static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params ); … … 312 309 struct Variable_t { 313 310 // const std::string * name; 314 DeclarationNode::TypeClasstyClass;311 TypeDecl::Kind tyClass; 315 312 DeclarationNode * assertions; 316 313 DeclarationNode * initializer; … … 452 449 * out++ = result; 453 450 } else { 454 assertf(false, "buildList unknown type");451 SemanticError( cur->location, "type specifier declaration in forall clause is currently unimplemented." ); 455 452 } // if 456 453 } catch( SemanticErrorException & e ) { -
src/Parser/TypeData.cc
r807a632 r3b56166 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 13 18:16:23201913 // Update Count : 6 4912 // Last Modified On : Mon Dec 16 07:56:46 2019 13 // Update Count : 662 14 14 // 15 15 … … 67 67 case Aggregate: 68 68 // aggregate = new Aggregate_t; 69 aggregate.kind = DeclarationNode::NoAggregate;69 aggregate.kind = AggregateDecl::NoAggregate; 70 70 aggregate.name = nullptr; 71 71 aggregate.params = nullptr; … … 345 345 break; 346 346 case Aggregate: 347 os << DeclarationNode::aggregateNames[ aggregate.kind ]<< ' ' << *aggregate.name << endl;347 os << AggregateDecl::aggrString( aggregate.kind ) << ' ' << *aggregate.name << endl; 348 348 if ( aggregate.params ) { 349 349 os << string( indent + 2, ' ' ) << "with type parameters" << endl; … … 489 489 for ( typename ForallList::iterator i = outputList.begin(); i != outputList.end(); ++i, n = (DeclarationNode*)n->get_next() ) { 490 490 TypeDecl * td = static_cast<TypeDecl *>(*i); 491 if ( n->variable.tyClass == DeclarationNode::Otype ) {491 if ( n->variable.tyClass == TypeDecl::Otype ) { 492 492 // add assertion parameters to `type' tyvars in reverse order 493 493 // add dtor: void ^?{}(T *) … … 522 522 switch ( td->kind ) { 523 523 case TypeData::Unknown: 524 // fill in implicit int525 return new BasicType( buildQualifiers( td ), BasicType::SignedInt );524 // fill in implicit int 525 return new BasicType( buildQualifiers( td ), BasicType::SignedInt ); 526 526 case TypeData::Basic: 527 return buildBasicType( td );527 return buildBasicType( td ); 528 528 case TypeData::Pointer: 529 return buildPointer( td );529 return buildPointer( td ); 530 530 case TypeData::Array: 531 return buildArray( td );531 return buildArray( td ); 532 532 case TypeData::Reference: 533 return buildReference( td );533 return buildReference( td ); 534 534 case TypeData::Function: 535 return buildFunction( td );535 return buildFunction( td ); 536 536 case TypeData::AggregateInst: 537 return buildAggInst( td );537 return buildAggInst( td ); 538 538 case TypeData::EnumConstant: 539 // the name gets filled in later -- by SymTab::Validate540 return new EnumInstType( buildQualifiers( td ), "" );539 // the name gets filled in later -- by SymTab::Validate 540 return new EnumInstType( buildQualifiers( td ), "" ); 541 541 case TypeData::SymbolicInst: 542 return buildSymbolicInst( td );542 return buildSymbolicInst( td ); 543 543 case TypeData::Tuple: 544 return buildTuple( td );544 return buildTuple( td ); 545 545 case TypeData::Typeof: 546 546 case TypeData::Basetypeof: 547 return buildTypeof( td );547 return buildTypeof( td ); 548 548 case TypeData::Builtin: 549 if (td->builtintype == DeclarationNode::Zero) { 550 return new ZeroType( noQualifiers ); 551 } 552 else if (td->builtintype == DeclarationNode::One) { 553 return new OneType( noQualifiers ); 554 } 555 else { 556 return new VarArgsType( buildQualifiers( td ) ); 557 } 549 switch ( td->builtintype ) { 550 case DeclarationNode::Zero: 551 return new ZeroType( noQualifiers ); 552 case DeclarationNode::One: 553 return new OneType( noQualifiers ); 554 default: 555 return new VarArgsType( buildQualifiers( td ) ); 556 } // switch 558 557 case TypeData::GlobalScope: 559 return new GlobalScopeType();560 case TypeData::Qualified:561 return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) );558 return new GlobalScopeType(); 559 case TypeData::Qualified: 560 return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) ); 562 561 case TypeData::Symbolic: 563 562 case TypeData::Enum: 564 563 case TypeData::Aggregate: 565 assert( false );564 assert( false ); 566 565 } // switch 567 566 … … 768 767 AggregateDecl * at; 769 768 switch ( td->aggregate.kind ) { 770 case DeclarationNode::Struct:771 case DeclarationNode::Coroutine:772 case DeclarationNode::Monitor:773 case DeclarationNode::Thread:769 case AggregateDecl::Struct: 770 case AggregateDecl::Coroutine: 771 case AggregateDecl::Monitor: 772 case AggregateDecl::Thread: 774 773 at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes, linkage ); 775 774 buildForall( td->aggregate.params, at->get_parameters() ); 776 775 break; 777 case DeclarationNode::Union:776 case AggregateDecl::Union: 778 777 at = new UnionDecl( *td->aggregate.name, attributes, linkage ); 779 778 buildForall( td->aggregate.params, at->get_parameters() ); 780 779 break; 781 case DeclarationNode::Trait:780 case AggregateDecl::Trait: 782 781 at = new TraitDecl( *td->aggregate.name, attributes, linkage ); 783 782 buildList( td->aggregate.params, at->get_parameters() ); … … 809 808 AggregateDecl * typedecl = buildAggregate( type, attributes, linkage ); 810 809 switch ( type->aggregate.kind ) { 811 case DeclarationNode::Struct:812 case DeclarationNode::Coroutine:813 case DeclarationNode::Monitor:814 case DeclarationNode::Thread:810 case AggregateDecl::Struct: 811 case AggregateDecl::Coroutine: 812 case AggregateDecl::Monitor: 813 case AggregateDecl::Thread: 815 814 ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl ); 816 815 break; 817 case DeclarationNode::Union:816 case AggregateDecl::Union: 818 817 ret = new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl ); 819 818 break; 820 case DeclarationNode::Trait:819 case AggregateDecl::Trait: 821 820 assert( false ); 822 821 //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl ); … … 827 826 } else { 828 827 switch ( type->aggregate.kind ) { 829 case DeclarationNode::Struct:830 case DeclarationNode::Coroutine:831 case DeclarationNode::Monitor:832 case DeclarationNode::Thread:828 case AggregateDecl::Struct: 829 case AggregateDecl::Coroutine: 830 case AggregateDecl::Monitor: 831 case AggregateDecl::Thread: 833 832 ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name ); 834 833 break; 835 case DeclarationNode::Union:834 case AggregateDecl::Union: 836 835 ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name ); 837 836 break; 838 case DeclarationNode::Trait:837 case AggregateDecl::Trait: 839 838 ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name ); 840 839 break; … … 863 862 case TypeData::Aggregate: { 864 863 switch ( type->aggregate.kind ) { 865 case DeclarationNode::Struct:866 case DeclarationNode::Coroutine:867 case DeclarationNode::Monitor:868 case DeclarationNode::Thread:864 case AggregateDecl::Struct: 865 case AggregateDecl::Coroutine: 866 case AggregateDecl::Monitor: 867 case AggregateDecl::Thread: 869 868 ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name ); 870 869 break; 871 case DeclarationNode::Union:870 case AggregateDecl::Union: 872 871 ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name ); 873 872 break; 874 case DeclarationNode::Trait:873 case AggregateDecl::Trait: 875 874 ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name ); 876 875 break; -
src/Parser/TypeData.h
r807a632 r3b56166 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 1 20:56:46 201813 // Update Count : 19 612 // Last Modified On : Fri Dec 13 23:42:35 2019 13 // Update Count : 199 14 14 // 15 15 … … 21 21 22 22 #include "ParseNode.h" // for DeclarationNode, DeclarationNode::Ag... 23 #include " Parser/LinkageSpec.h"// for Spec23 #include "SynTree/LinkageSpec.h" // for Spec 24 24 #include "SynTree/Type.h" // for Type, ReferenceToType (ptr only) 25 25 #include "SynTree/SynTree.h" // for Visitor Nodes … … 30 30 31 31 struct Aggregate_t { 32 DeclarationNode::Aggregate kind;32 AggregateDecl::Aggregate kind; 33 33 const std::string * name = nullptr; 34 34 DeclarationNode * params = nullptr; -
src/Parser/lex.ll
r807a632 r3b56166 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Sun Aug 4 20:53:47 201913 * Update Count : 7 1912 * Last Modified On : Fri Feb 7 19:02:43 2020 13 * Update Count : 725 14 14 */ 15 15 … … 330 330 /* identifier */ 331 331 {identifier} { IDENTIFIER_RETURN(); } 332 "` "{identifier}"`" {// CFA333 yytext[yyleng - 1] = '\0'; yytext += 1;// SKULLDUGGERY: remove backquotes (ok to shorten?)332 "``"{identifier} { // CFA 333 yytext[yyleng] = '\0'; yytext += 2; // SKULLDUGGERY: remove backquotes (ok to shorten?) 334 334 IDENTIFIER_RETURN(); 335 335 } -
src/Parser/module.mk
r807a632 r3b56166 11 11 ## Created On : Sat May 16 15:29:09 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Wed Jun 28 21:58:29 201714 ## Update Count : 10 413 ## Last Modified On : Sat Dec 14 07:34:47 2019 14 ## Update Count : 107 15 15 ############################################################################### 16 16 … … 19 19 AM_YFLAGS = -d -t -v 20 20 21 SRC += Parser/parser.yy \ 22 Parser/lex.ll \ 23 Parser/TypedefTable.cc \ 24 Parser/ParseNode.cc \ 21 SRC += \ 25 22 Parser/DeclarationNode.cc \ 26 23 Parser/ExpressionNode.cc \ 24 Parser/InitializerNode.cc \ 25 Parser/ParseNode.cc \ 27 26 Parser/StatementNode.cc \ 28 Parser/InitializerNode.cc \29 27 Parser/TypeData.cc \ 30 Parser/LinkageSpec.cc \ 28 Parser/TypedefTable.cc \ 29 Parser/lex.ll \ 30 Parser/parser.yy \ 31 31 Parser/parserutility.cc 32 32 33 SRCDEMANGLE += \34 Parser/LinkageSpec.cc35 36 37 33 MOSTLYCLEANFILES += Parser/lex.cc Parser/parser.cc Parser/parser.hh Parser/parser.output -
src/Parser/parser.yy
r807a632 r3b56166 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S un Aug 4 21:48:23 201913 // Update Count : 4 36412 // Last Modified On : Sat Feb 1 10:04:40 2020 13 // Update Count : 4440 14 14 // 15 15 … … 51 51 using namespace std; 52 52 53 #include "SynTree/Declaration.h" 53 54 #include "ParseNode.h" 54 55 #include "TypedefTable.h" 55 56 #include "TypeData.h" 56 #include " LinkageSpec.h"57 #include "SynTree/LinkageSpec.h" 57 58 #include "Common/SemanticError.h" // error_str 58 59 #include "Common/utility.h" // for maybeMoveBuild, maybeBuild, CodeLo... … … 211 212 } // forCtrl 212 213 213 214 214 bool forall = false, yyy = false; // aggregate have one or more forall qualifiers ? 215 215 … … 237 237 ExpressionNode * en; 238 238 DeclarationNode * decl; 239 DeclarationNode::Aggregate aggKey;240 DeclarationNode::TypeClasstclass;239 AggregateDecl::Aggregate aggKey; 240 TypeDecl::Kind tclass; 241 241 StatementNode * sn; 242 242 WaitForStmt * wfs; … … 323 323 %type<op> ptrref_operator unary_operator assignment_operator 324 324 %type<en> primary_expression postfix_expression unary_expression 325 %type<en> cast_expression exponential_expression multiplicative_expression additive_expression325 %type<en> cast_expression_list cast_expression exponential_expression multiplicative_expression additive_expression 326 326 %type<en> shift_expression relational_expression equality_expression 327 327 %type<en> AND_expression exclusive_OR_expression inclusive_OR_expression … … 365 365 %type<decl> abstract_parameter_declaration 366 366 367 %type<aggKey> aggregate_key 367 %type<aggKey> aggregate_key aggregate_data aggregate_control 368 368 %type<decl> aggregate_type aggregate_type_nobody 369 369 … … 579 579 | '(' compound_statement ')' // GCC, lambda expression 580 580 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); } 581 | constant '`' IDENTIFIER // CFA, postfix call582 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }583 | string_literal '`' IDENTIFIER // CFA, postfix call584 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( $1 ) ) ); }585 | IDENTIFIER '`' IDENTIFIER // CFA, postfix call586 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( build_varref( $1 ) ) ) ); }587 | tuple '`' IDENTIFIER // CFA, postfix call588 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }589 | '(' comma_expression ')' '`' IDENTIFIER // CFA, postfix call590 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }591 581 | type_name '.' identifier // CFA, nested type 592 582 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 642 632 | postfix_expression '(' argument_expression_list ')' 643 633 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 634 | postfix_expression '`' identifier // CFA, postfix call 635 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); } 636 | constant '`' identifier // CFA, postfix call 637 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); } 638 | string_literal '`' identifier // CFA, postfix call 639 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( $1 ) ) ); } 644 640 | postfix_expression '.' identifier 645 641 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } … … 650 646 | postfix_expression '.' '[' field_name_list ']' // CFA, tuple field selector 651 647 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 648 | postfix_expression '.' aggregate_control 649 { $$ = new ExpressionNode( build_keyword_cast( $3, $1 ) ); } 652 650 | postfix_expression ARROW identifier 653 651 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); } … … 664 662 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 665 663 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 666 | '^' primary_expression '{' argument_expression_list '}' // CFA 664 | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call 667 665 { 668 666 Token fn; … … 677 675 | argument_expression 678 676 | argument_expression_list ',' argument_expression 679 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }677 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 680 678 ; 681 679 … … 689 687 field_name_list: // CFA, tuple field selector 690 688 field 691 | field_name_list ',' field { $$ = (ExpressionNode *) $1->set_last( $3); }689 | field_name_list ',' field { $$ = (ExpressionNode *)($1->set_last( $3 )); } 692 690 ; 693 691 … … 793 791 | '(' type_no_function ')' cast_expression 794 792 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 795 // keyword cast cannot be grouped because of reduction in aggregate_key 796 | '(' GENERATOR '&' ')' cast_expression // CFA 797 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } 798 | '(' COROUTINE '&' ')' cast_expression // CFA 799 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } 800 | '(' THREAD '&' ')' cast_expression // CFA 801 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Thread, $5 ) ); } 802 | '(' MONITOR '&' ')' cast_expression // CFA 803 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Monitor, $5 ) ); } 793 | '(' aggregate_control '&' ')' cast_expression // CFA 794 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 804 795 // VIRTUAL cannot be opt because of look ahead issues 805 796 | '(' VIRTUAL ')' cast_expression // CFA … … 965 956 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); } 966 957 | '[' push assignment_expression pop ',' tuple_expression_list ']' 967 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *) $3->set_last( $6 ) )); }958 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $6 ) ) )); } 968 959 ; 969 960 … … 971 962 assignment_expression_opt 972 963 | tuple_expression_list ',' assignment_expression_opt 973 { $$ = (ExpressionNode *) $1->set_last( $3); }964 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 974 965 ; 975 966 … … 1195 1186 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1196 1187 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1188 | '=' comma_expression // CFA 1189 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1190 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1197 1191 | comma_expression inclexcl comma_expression // CFA 1198 1192 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1202 1196 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1203 1197 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1198 | comma_expression ';' '=' comma_expression // CFA 1199 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1200 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1204 1201 | comma_expression ';' comma_expression inclexcl comma_expression // CFA 1205 1202 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1306 1303 WAITFOR '(' cast_expression ')' 1307 1304 { $$ = $3; } 1308 | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1309 { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1305 // | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1306 // { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1307 | WAITFOR '(' cast_expression_list ':' argument_expression_list ')' 1308 { $$ = (ExpressionNode *)($3->set_last( $5 )); } 1309 ; 1310 1311 cast_expression_list: 1312 cast_expression 1313 | cast_expression_list ',' cast_expression 1314 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1310 1315 ; 1311 1316 … … 1418 1423 asm_operand 1419 1424 | asm_operands_list ',' asm_operand 1420 { $$ = (ExpressionNode *) $1->set_last( $3); }1425 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1421 1426 ; 1422 1427 1423 1428 asm_operand: // GCC 1424 1429 string_literal '(' constant_expression ')' 1425 { $$ = new ExpressionNode( new AsmExpr( maybeMoveBuild< Expression >( (ExpressionNode *)nullptr ), $1, maybeMoveBuild< Expression >( $3 ) ) ); }1426 | '[' constant_expression']' string_literal '(' constant_expression ')'1427 { $$ = new ExpressionNode( new AsmExpr( maybeMoveBuild< Expression >( $2 ), $4, maybeMoveBuild< Expression >( $6 ) ) ); }1430 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild< Expression >( $3 ) ) ); } 1431 | '[' IDENTIFIER ']' string_literal '(' constant_expression ')' 1432 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild< Expression >( $6 ) ) ); } 1428 1433 ; 1429 1434 … … 1434 1439 { $$ = new ExpressionNode( $1 ); } 1435 1440 | asm_clobbers_list_opt ',' string_literal 1436 // set_last returns ParseNode * 1437 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); } 1441 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); } 1438 1442 ; 1439 1443 … … 2059 2063 2060 2064 aggregate_key: 2065 aggregate_data 2066 | aggregate_control 2067 ; 2068 2069 aggregate_data: 2061 2070 STRUCT 2062 { yyy = true; $$ = DeclarationNode::Struct; }2071 { yyy = true; $$ = AggregateDecl::Struct; } 2063 2072 | UNION 2064 { yyy = true; $$ = DeclarationNode::Union; } 2065 | EXCEPTION 2066 { yyy = true; $$ = DeclarationNode::Exception; } 2067 | GENERATOR 2068 { yyy = true; $$ = DeclarationNode::Coroutine; } 2073 { yyy = true; $$ = AggregateDecl::Union; } 2074 | EXCEPTION // CFA 2075 { yyy = true; $$ = AggregateDecl::Exception; } 2076 ; 2077 2078 aggregate_control: // CFA 2079 GENERATOR 2080 { yyy = true; $$ = AggregateDecl::Coroutine; } 2069 2081 | COROUTINE 2070 { yyy = true; $$ = DeclarationNode::Coroutine; }2082 { yyy = true; $$ = AggregateDecl::Coroutine; } 2071 2083 | MONITOR 2072 { yyy = true; $$ = DeclarationNode::Monitor; }2084 { yyy = true; $$ = AggregateDecl::Monitor; } 2073 2085 | THREAD 2074 { yyy = true; $$ = DeclarationNode::Thread; }2086 { yyy = true; $$ = AggregateDecl::Thread; } 2075 2087 ; 2076 2088 … … 2096 2108 distInl( $3 ); 2097 2109 } 2110 | INLINE aggregate_control ';' // CFA 2111 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; } 2098 2112 | typedef_declaration ';' // CFA 2099 2113 | cfa_field_declaring_list ';' // CFA, new style field declaration … … 2348 2362 | initializer_list_opt ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } 2349 2363 | initializer_list_opt ',' designation initializer 2350 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) )); }2364 { $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); } 2351 2365 ; 2352 2366 … … 2370 2384 designator 2371 2385 | designator_list designator 2372 { $$ = (ExpressionNode *)( $1->set_last( $2 )); }2386 { $$ = (ExpressionNode *)($1->set_last( $2 )); } 2373 2387 //| designator_list designator { $$ = new ExpressionNode( $1, $2 ); } 2374 2388 ; … … 2426 2440 | type_specifier identifier_parameter_declarator 2427 2441 | assertion_list 2428 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }2442 { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); } 2429 2443 ; 2430 2444 2431 2445 type_class: // CFA 2432 2446 OTYPE 2433 { $$ = DeclarationNode::Otype; }2447 { $$ = TypeDecl::Otype; } 2434 2448 | DTYPE 2435 { $$ = DeclarationNode::Dtype; }2449 { $$ = TypeDecl::Dtype; } 2436 2450 | FTYPE 2437 { $$ = DeclarationNode::Ftype; }2451 { $$ = TypeDecl::Ftype; } 2438 2452 | TTYPE 2439 { $$ = DeclarationNode::Ttype; }2453 { $$ = TypeDecl::Ttype; } 2440 2454 ; 2441 2455 … … 2467 2481 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; } 2468 2482 | type_list ',' type 2469 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); }2483 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); } 2470 2484 | type_list ',' assignment_expression 2471 2485 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; } … … 2578 2592 { 2579 2593 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 2580 linkage = LinkageSpec:: linkageUpdate( yylloc, linkage, $2 );2594 linkage = LinkageSpec::update( yylloc, linkage, $2 ); 2581 2595 } 2582 2596 '{' up external_definition_list_opt down '}'
Note:
See TracChangeset
for help on using the changeset viewer.