Changeset b1e63ac5 for src/Parser
- Timestamp:
- Jul 4, 2017, 9:40:16 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:
- 208e5be
- Parents:
- 9c951e3 (diff), f7cb0bc (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:
-
- 13 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r9c951e3 rb1e63ac5 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 12:34:05 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Mar 17 15:46:33201713 // Update Count : 101 811 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jun 28 15:27:00 2017 13 // Update Count : 1019 14 14 // 15 15 … … 57 57 variable.tyClass = NoTypeClass; 58 58 variable.assertions = nullptr; 59 variable.initializer = nullptr; 59 60 60 61 // attr.name = nullptr; … … 70 71 // delete variable.name; 71 72 delete variable.assertions; 73 delete variable.initializer; 72 74 73 75 delete type; … … 101 103 newnode->variable.tyClass = variable.tyClass; 102 104 newnode->variable.assertions = maybeClone( variable.assertions ); 105 newnode->variable.initializer = maybeClone( variable.initializer ); 103 106 104 107 // newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr; … … 857 860 } 858 861 862 DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) { 863 assertf( variable.tyClass != NoTypeClass, "Called addTypeInitializer on something that isn't a type variable." ); 864 variable.initializer = init; 865 return this; 866 } 867 859 868 DeclarationNode * DeclarationNode::cloneType( string * newName ) { 860 869 DeclarationNode * newnode = new DeclarationNode; … … 1014 1023 assertf( sizeof(kindMap)/sizeof(kindMap[0] == NoTypeClass-1), "DeclarationNode::build: kindMap is out of sync." ); 1015 1024 assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." ); 1016 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ] );1025 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.initializer ? variable.initializer->buildType() : nullptr ); 1017 1026 buildList( variable.assertions, ret->get_assertions() ); 1018 1027 return ret; … … 1054 1063 case TypeData::Enum: 1055 1064 case TypeData::Aggregate: { 1056 ReferenceToType * ret = buildComAggInst( type, attributes );1065 ReferenceToType * ret = buildComAggInst( type, attributes, linkage ); 1057 1066 buildList( type->aggregate.actuals, ret->get_parameters() ); 1058 1067 return ret; -
src/Parser/ExpressionNode.cc
r9c951e3 rb1e63ac5 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 30 17:02:46201713 // Update Count : 5 1512 // Last Modified On : Wed Jun 28 21:08:15 2017 13 // Update Count : 542 14 14 // 15 15 … … 27 27 #include "SynTree/Declaration.h" 28 28 #include "Common/UnimplementedError.h" 29 #include "parse utility.h"29 #include "parserutility.h" 30 30 #include "Common/utility.h" 31 31 … … 62 62 bool dec = true, Unsigned = false; // decimal, unsigned constant 63 63 int size; // 0 => int, 1 => long, 2 => long long 64 unsigned long long v; // converted integral value64 unsigned long long int v; // converted integral value 65 65 size_t last = str.length() - 1; // last character of constant 66 66 … … 118 118 } // if 119 119 120 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str ) );120 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str, v ) ); 121 121 delete &str; // created by lex 122 122 return ret; … … 133 133 // floating-point constant has minimum of 2 characters: 1. or .1 134 134 size_t last = str.length() - 1; 135 double v; 136 137 sscanf( str.c_str(), "%lg", &v ); 135 138 136 139 if ( checkI( str[last] ) ) { // imaginary ? … … 150 153 } // if 151 154 152 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str ) );155 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str, v ) ); 153 156 delete &str; // created by lex 154 157 return ret; … … 156 159 157 160 Expression *build_constantChar( const std::string & str ) { 158 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str ) );161 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) ); 159 162 delete &str; // created by lex 160 163 return ret; … … 164 167 // string should probably be a primitive type 165 168 ArrayType *at = new ArrayType( emptyQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), 166 new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::UnsignedInt ), 167 toString( str.size()+1-2 ) ) ), // +1 for '\0' and -2 for '"' 169 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 168 170 false, false ); 169 ConstantExpr * ret = new ConstantExpr( Constant( at, str ) ); 171 // constant 0 is ignored for pure string value 172 ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); 170 173 delete &str; // created by lex 171 174 return ret; … … 173 176 174 177 Expression *build_constantZeroOne( const std::string & str ) { 175 Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( emptyQualifiers ) : (Type*)new OneType( emptyQualifiers ), str ) ); 178 Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( emptyQualifiers ) : (Type*)new OneType( emptyQualifiers ), str, 179 str == "0" ? (unsigned long long int)0 : (unsigned long long int)1 ) ); 176 180 delete &str; // created by lex 177 181 return ret; … … 184 188 std::stringstream ss( str ); 185 189 ss >> a >> dot >> b; 186 UntypedMemberExpr * ret = new UntypedMemberExpr( 187 new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::SignedInt ), toString( b ) ) ), 188 new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::SignedInt ), toString( a ) ) ) ); 190 UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) ); 189 191 delete &str; 190 192 return ret; … … 207 209 } // build_field_name_fraction_constants 208 210 211 212 209 213 Expression * build_field_name_REALFRACTIONconstant( const std::string & str ) { 210 assert( str[0] == '.');214 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str ); 211 215 Expression * ret = build_constantInteger( *new std::string( str.substr(1) ) ); 212 216 delete &str; … … 215 219 216 220 Expression * build_field_name_REALDECIMALconstant( const std::string & str ) { 217 assert( str[str.size()-1] == '.');221 if ( str[str.size()-1] != '.' ) throw SemanticError( "invalid tuple index " + str ); 218 222 Expression * ret = build_constantInteger( *new std::string( str.substr( 0, str.size()-1 ) ) ); 219 223 delete &str; … … 221 225 } // build_field_name_REALDECIMALconstant 222 226 223 NameExpr * build_varref( const string *name , bool labelp) {227 NameExpr * build_varref( const string *name ) { 224 228 NameExpr *expr = new NameExpr( *name, nullptr ); 225 229 delete name; … … 344 348 345 349 Expression *build_valexpr( StatementNode *s ) { 346 return new UntypedValofExpr( maybeMoveBuild< Statement >(s), nullptr);350 return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ) ); 347 351 } 348 352 Expression *build_typevalue( DeclarationNode *decl ) { -
src/Parser/InitializerNode.cc
r9c951e3 rb1e63ac5 74 74 75 75 InitializerNode *moreInit; 76 if ( get_next() != 0 && ((moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) != 0) )76 if ( (moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) ) { 77 77 moreInit->printOneLine( os ); 78 } 78 79 } 79 80 80 81 Initializer *InitializerNode::build() const { 81 82 if ( aggregate ) { 83 // steal designators from children 84 std::list< Designation * > designlist; 85 InitializerNode * child = next_init(); 86 for ( ; child != nullptr; child = dynamic_cast< InitializerNode * >( child->get_next() ) ) { 87 std::list< Expression * > desList; 88 buildList< Expression, ExpressionNode >( child->designator, desList ); 89 designlist.push_back( new Designation( desList ) ); 90 } // for 82 91 std::list< Initializer * > initlist; 83 92 buildList< Initializer, InitializerNode >( next_init(), initlist ); 84 85 std::list< Expression * > designlist;86 87 if ( designator != 0 ) {88 buildList< Expression, ExpressionNode >( designator, designlist );89 } // if90 91 93 return new ListInit( initlist, designlist, maybeConstructed ); 92 94 } else { 93 std::list< Expression * > designators; 94 95 if ( designator != 0 ) 96 buildList< Expression, ExpressionNode >( designator, designators ); 97 98 if ( get_expression() != 0) 99 return new SingleInit( maybeBuild< Expression >( get_expression() ), designators, maybeConstructed ); 95 if ( get_expression() != 0) { 96 return new SingleInit( maybeBuild< Expression >( get_expression() ), maybeConstructed ); 97 } 100 98 } // if 101 102 99 return 0; 103 100 } -
src/Parser/LinkageSpec.cc
r9c951e3 rb1e63ac5 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:22:09 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun Oct 2 23:16:21 201613 // Update Count : 2 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jun 28 11:51:00 2017 13 // Update Count : 24 14 14 // 15 15 … … 28 28 } else if ( *spec == "\"C\"" ) { 29 29 return C; 30 } else if ( *spec == "\"BuiltinC\"" ) { 31 return BuiltinC; 30 32 } else { 31 33 throw SemanticError( "Invalid linkage specifier " + *spec ); … … 36 38 assert( 0 <= linkage && linkage < LinkageSpec::NoOfSpecs ); 37 39 static const char *linkageKinds[LinkageSpec::NoOfSpecs] = { 38 "intrinsic", "Cforall", "C", "automatically generated", "compiler built-in", 40 "intrinsic", "Cforall", "C", "automatically generated", "compiler built-in", "cfa built-in", "c built-in", 39 41 }; 40 42 return linkageKinds[linkage]; 41 43 } 42 44 43 bool LinkageSpec::is Decoratable( Spec spec ) {45 bool LinkageSpec::isMangled( Spec spec ) { 44 46 assert( 0 <= spec && spec < LinkageSpec::NoOfSpecs ); 45 47 static bool decoratable[LinkageSpec::NoOfSpecs] = { 46 // Intrinsic, Cforall, C, AutoGen, Compiler 48 // Intrinsic, Cforall, C, AutoGen, Compiler, 47 49 true, true, false, true, false, 50 // Builtin, BuiltinC, 51 true, false, 48 52 }; 49 53 return decoratable[spec]; … … 53 57 assert( 0 <= spec && spec < LinkageSpec::NoOfSpecs ); 54 58 static bool generatable[LinkageSpec::NoOfSpecs] = { 55 // Intrinsic, Cforall, C, AutoGen, Compiler 59 // Intrinsic, Cforall, C, AutoGen, Compiler, 56 60 true, true, true, true, false, 61 // Builtin, BuiltinC, 62 true, true, 57 63 }; 58 64 return generatable[spec]; … … 62 68 assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs ); 63 69 static bool overridable[LinkageSpec::NoOfSpecs] = { 64 // Intrinsic, Cforall, C, AutoGen, Compiler 70 // Intrinsic, Cforall, C, AutoGen, Compiler, 65 71 true, false, false, true, false, 72 // Builtin, BuiltinC, 73 false, false, 66 74 }; 67 75 return overridable[spec]; … … 71 79 assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs ); 72 80 static bool builtin[LinkageSpec::NoOfSpecs] = { 73 // Intrinsic, Cforall, C, AutoGen, Compiler 81 // Intrinsic, Cforall, C, AutoGen, Compiler, 74 82 true, false, false, false, true, 83 // Builtin, BuiltinC, 84 true, true, 75 85 }; 76 86 return builtin[spec]; -
src/Parser/LinkageSpec.h
r9c951e3 rb1e63ac5 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:24:28 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Oct 1 23:03:17 201613 // Update Count : 1 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jun 28 11:50:00 2017 13 // Update Count : 12 14 14 // 15 15 … … 26 26 AutoGen, // built by translator (struct assignment) 27 27 Compiler, // gcc internal 28 Builtin, // mangled builtins 29 BuiltinC, // non-mangled builtins 28 30 NoOfSpecs 29 31 }; … … 32 34 static std::string linkageName( Spec ); 33 35 34 static bool is Decoratable( Spec );36 static bool isMangled( Spec ); 35 37 static bool isGeneratable( Spec ); 36 38 static bool isOverridable( Spec ); -
src/Parser/ParseNode.h
r9c951e3 rb1e63ac5 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:28:16 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Mar 17 15:42:18201713 // Update Count : 77 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jun 12 13:00:00 2017 13 // Update Count : 779 14 14 // 15 15 … … 61 61 } 62 62 63 virtual void print( std::ostream &os,int indent = 0 ) const {}64 virtual void printList( std::ostream &os,int indent = 0 ) const {}63 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 64 virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 65 65 66 66 static int indent_by; … … 113 113 ExpressionNode * set_extension( bool exten ) { extension = exten; return this; } 114 114 115 virtual void print( std::ostream &os,int indent = 0 ) const override {}116 void printOneLine( std::ostream &os,int indent = 0 ) const {}115 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {} 116 void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 117 117 118 118 template<typename T> … … 166 166 Expression * build_field_name_REALDECIMALconstant( const std::string & str ); 167 167 168 NameExpr * build_varref( const std::string * name , bool labelp = false);168 NameExpr * build_varref( const std::string * name ); 169 169 Expression * build_typevalue( DeclarationNode * decl ); 170 170 … … 274 274 DeclarationNode * addIdList( DeclarationNode * list ); // old-style functions 275 275 DeclarationNode * addInitializer( InitializerNode * init ); 276 DeclarationNode * addTypeInitializer( DeclarationNode * init ); 276 277 277 278 DeclarationNode * cloneType( std::string * newName ); … … 282 283 } 283 284 284 virtual void print( std::ostream &os,int indent = 0 ) const override;285 virtual void printList( std::ostream &os,int indent = 0 ) const override;285 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override; 286 virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override; 286 287 287 288 Declaration * build() const; … … 301 302 DeclarationNode::TypeClass tyClass; 302 303 DeclarationNode * assertions; 304 DeclarationNode * initializer; 303 305 }; 304 306 Variable_t variable; … … 361 363 virtual StatementNode * append_last_case( StatementNode * ); 362 364 363 virtual void print( std::ostream &os,int indent = 0 ) const override {}364 virtual void printList( std::ostream &os,int indent = 0 ) const override {}365 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {} 366 virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override {} 365 367 private: 366 368 std::unique_ptr<Statement> stmt; … … 391 393 Statement * build_return( ExpressionNode * ctl ); 392 394 Statement * build_throw( ExpressionNode * ctl ); 395 Statement * build_resume( ExpressionNode * ctl ); 396 Statement * build_resume_at( ExpressionNode * ctl , ExpressionNode * target ); 393 397 Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt ); 394 Statement * build_catch( DeclarationNode * decl, StatementNode * stmt, bool catchAny = false);398 Statement * build_catch( CatchStmt::Kind kind, DeclarationNode *decl, ExpressionNode *cond, StatementNode *body ); 395 399 Statement * build_finally( StatementNode * stmt ); 396 400 Statement * build_compound( StatementNode * first ); … … 411 415 result->location = cur->location; 412 416 * out++ = result; 417 } else { 418 assertf(false, "buildList unknown type"); 413 419 } // if 414 420 } catch( SemanticError &e ) { -
src/Parser/StatementNode.cc
r9c951e3 rb1e63ac5 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 2 22:16:40201713 // Update Count : 3 2712 // Last Modified On : Wed Jun 28 21:08:37 2017 13 // Update Count : 330 14 14 // 15 15 … … 21 21 #include "SynTree/Statement.h" 22 22 #include "SynTree/Expression.h" 23 #include "parse utility.h"23 #include "parserutility.h" 24 24 #include "Common/utility.h" 25 25 … … 152 152 return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr ); 153 153 } 154 154 155 Statement *build_throw( ExpressionNode *ctl ) { 155 156 std::list< Expression * > exps; 156 157 buildMoveList( ctl, exps ); 157 158 assertf( exps.size() < 2, "This means we are leaking memory"); 158 return new ReturnStmt( noLabels, !exps.empty() ? exps.back() : nullptr, true ); 159 return new ThrowStmt( noLabels, ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr ); 160 } 161 162 Statement *build_resume( ExpressionNode *ctl ) { 163 std::list< Expression * > exps; 164 buildMoveList( ctl, exps ); 165 assertf( exps.size() < 2, "This means we are leaking memory"); 166 return new ThrowStmt( noLabels, ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr ); 167 } 168 169 Statement *build_resume_at( ExpressionNode *ctl, ExpressionNode *target ) { 170 (void)ctl; 171 (void)target; 172 assertf( false, "resume at (non-local throw) is not yet supported," ); 159 173 } 160 174 161 175 Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) { 162 std::list< Statement * > branches;163 buildMoveList< Statement, StatementNode >( catch_stmt, branches );176 std::list< CatchStmt * > branches; 177 buildMoveList< CatchStmt, StatementNode >( catch_stmt, branches ); 164 178 CompoundStmt *tryBlock = safe_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt)); 165 179 FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) ); 166 180 return new TryStmt( noLabels, tryBlock, branches, finallyBlock ); 167 181 } 168 Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny ) {169 std::list< Statement * > branches; 170 buildMoveList< Statement, StatementNode >( stmt, branches );171 assert( branches.size() == 1 ); 172 return new CatchStmt( noLabels, maybeMoveBuild< Declaration >(decl), branches.front(), catchAny);182 Statement *build_catch( CatchStmt::Kind kind, DeclarationNode *decl, ExpressionNode *cond, StatementNode *body ) { 183 std::list< Statement * > branches; 184 buildMoveList< Statement, StatementNode >( body, branches ); 185 assert( branches.size() == 1 ); 186 return new CatchStmt( noLabels, kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() ); 173 187 } 174 188 Statement *build_finally( StatementNode *stmt ) { -
src/Parser/TypeData.cc
r9c951e3 rb1e63ac5 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:12:51 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Mar 17 15:52:43201713 // Update Count : 56 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jun 28 15:28:00 2017 13 // Update Count : 564 14 14 // 15 15 … … 630 630 } // buildReference 631 631 632 AggregateDecl * buildAggregate( const TypeData * td, std::list< Attribute * > attributes ) {632 AggregateDecl * buildAggregate( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) { 633 633 assert( td->kind == TypeData::Aggregate ); 634 634 AggregateDecl * at; … … 638 638 case DeclarationNode::Monitor: 639 639 case DeclarationNode::Thread: 640 at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes );640 at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes, linkage ); 641 641 buildForall( td->aggregate.params, at->get_parameters() ); 642 642 break; … … 659 659 } // buildAggregate 660 660 661 ReferenceToType * buildComAggInst( const TypeData * type, std::list< Attribute * > attributes ) {661 ReferenceToType * buildComAggInst( const TypeData * type, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) { 662 662 switch ( type->kind ) { 663 663 case TypeData::Enum: { … … 672 672 ReferenceToType * ret; 673 673 if ( type->aggregate.body ) { 674 AggregateDecl * typedecl = buildAggregate( type, attributes );674 AggregateDecl * typedecl = buildAggregate( type, attributes, linkage ); 675 675 switch ( type->aggregate.kind ) { 676 676 case DeclarationNode::Struct: … … 776 776 if ( cur->has_enumeratorValue() ) { 777 777 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 778 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) , list< Expression * >()) );778 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) ); 779 779 } // if 780 780 } // for … … 793 793 TupleType * buildTuple( const TypeData * td ) { 794 794 assert( td->kind == TypeData::Tuple ); 795 TupleType * ret = new TupleType( buildQualifiers( td ) ); 796 buildTypeList( td->tuple, ret->get_types() ); 795 std::list< Type * > types; 796 buildTypeList( td->tuple, types ); 797 TupleType * ret = new TupleType( buildQualifiers( td ), types ); 797 798 buildForall( td->forall, ret->get_forall() ); 798 799 return ret; … … 818 819 return decl->set_asmName( asmName ); 819 820 } else if ( td->kind == TypeData::Aggregate ) { 820 return buildAggregate( td, attributes );821 return buildAggregate( td, attributes, linkage ); 821 822 } else if ( td->kind == TypeData::Enum ) { 822 823 return buildEnum( td, attributes ); -
src/Parser/TypeData.h
r9c951e3 rb1e63ac5 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:18:36 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Mar 16 08:32:39201713 // Update Count : 18 511 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jun 28 15:29:00 2017 13 // Update Count : 186 14 14 // 15 15 … … 103 103 ReferenceType * buildReference( const TypeData * ); 104 104 AggregateDecl * buildAggregate( const TypeData *, std::list< Attribute * > ); 105 ReferenceToType * buildComAggInst( const TypeData *, std::list< Attribute * > attributes );105 ReferenceToType * buildComAggInst( const TypeData *, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ); 106 106 ReferenceToType * buildAggInst( const TypeData * ); 107 107 TypeDecl * buildVariable( const TypeData * ); -
src/Parser/TypedefTable.h
r9c951e3 rb1e63ac5 10 10 // Created On : Sat May 16 15:24:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 15 18:25:04 201613 // Update Count : 2812 // Last Modified On : Wed Jun 28 21:56:34 2017 13 // Update Count : 33 14 14 // 15 15 … … 22 22 #include <stack> 23 23 24 #include " lex.h"24 #include "parser.hh" 25 25 #include "parser.h" 26 26 -
src/Parser/lex.ll
r9c951e3 rb1e63ac5 5 5 * file "LICENCE" distributed with Cforall. 6 6 * 7 * lex.l --7 * lex.ll -- 8 8 * 9 9 * Author : Peter A. Buhr 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Mon Mar 13 08:36:17201713 * Update Count : 5 0612 * Last Modified On : Wed Jun 28 21:03:45 2017 13 * Update Count : 529 14 14 */ 15 15 … … 27 27 #include <cstdio> // FILENAME_MAX 28 28 29 #include "lex.h"30 #include "parser.h" // YACC generated definitions based on C++ grammar31 29 #include "ParseNode.h" 32 30 #include "TypedefTable.h" … … 77 75 // numeric constants, CFA: '_' in constant 78 76 hex_quad {hex}("_"?{hex}){3} 79 integer_suffix "_"?(([uU] [lL]?)|([uU]("ll"|"LL")?)|([lL][uU]?)|("ll"|"LL")[uU]?)77 integer_suffix "_"?(([uU](("ll"|"LL"|[lL])[iI]|[iI]?("ll"|"LL"|[lL])?))|([iI](("ll"|"LL"|[lL])[uU]|[uU]?("ll"|"LL"|[lL])?))|(("ll"|"LL"|[lL])([iI][uU]|[uU]?[iI]?))) 80 78 81 79 octal_digits ({octal})|({octal}({octal}|"_")*{octal}) … … 91 89 92 90 decimal_digits ({decimal})|({decimal}({decimal}|"_")*{decimal}) 93 real_decimal {decimal_digits}"." 94 real_fraction "."{decimal_digits} 95 real_constant {decimal_digits} ?{real_fraction}91 real_decimal {decimal_digits}"."{exponent}?{floating_suffix}? 92 real_fraction "."{decimal_digits}{exponent}?{floating_suffix}? 93 real_constant {decimal_digits}{real_fraction} 96 94 exponent "_"?[eE]"_"?[+-]?{decimal_digits} 97 // GCC: D (double), DL (long double) and iI (imaginary) suffixes 98 floating_suffix "_"?([fFdDlL][iI]?|"DL"|[iI][lLfFdD]?) 99 //floating_suffix "_"?([fFdD]|[lL]|[D][L])|([iI][lLfFdD])|([lLfFdD][iI])) 95 // GCC: D (double) and iI (imaginary) suffixes, and DL (long double) 96 floating_suffix "_"?([fFdDlL][iI]?|[iI][lLfFdD]?|"DL") 100 97 floating_constant (({real_constant}{exponent}?)|({decimal_digits}{exponent})){floating_suffix}? 101 98 … … 236 233 long { KEYWORD_RETURN(LONG); } 237 234 lvalue { KEYWORD_RETURN(LVALUE); } // CFA 238 monitor { KEYWORD_RETURN(MONITOR); } // CFA235 monitor { KEYWORD_RETURN(MONITOR); } // CFA 239 236 mutex { KEYWORD_RETURN(MUTEX); } // CFA 240 237 _Noreturn { KEYWORD_RETURN(NORETURN); } // C11 … … 378 375 "?"{op_binary_over}"?" { IDENTIFIER_RETURN(); } // binary 379 376 /* 380 This rule handles ambiguous cases with operator identifiers, e.g., "int *?*?()", where the string "*?*?" 381 can be lexed as "*"/"?*?" or "*?"/"*?". Since it is common practise to put a unary operator juxtaposed382 to an identifier, e.g., "*i", users will be annoyed if they cannot do this with respect to operator383 identifiers. Even with this special hack, there are 5 general cases that cannot be handled. The first384 case is for the function-call identifier "?()":385 386 int * ?()(); // declaration: space required after '*' 387 * ?()(); // expression: space required after '*'388 389 Without the space, the string "*?()" is ambiguous without N character look ahead; it requires scanning390 ahead to determine if there is a '(', which is the start of an argument/parameter list.391 392 The 4 remaining cases occur in expressions: 393 394 i++?i:0; // space required before '?' 395 i --?i:0; // space required before '?'396 i?++ i:0; // space required after '?'397 i?--i:0; // space required after '?' 398 399 In the first two cases, the string "i++?" is ambiguous, where this string can be lexed as "i"/"++?" or 400 "i++"/"?"; it requires scanning ahead to determine if there is a '(', which is the start of an argument 401 list. In the second two cases, the string "?++x" is ambiguous, where this string can be lexed as 402 "?++"/"x" or "?"/"++x"; it requires scanning ahead to determine if there is a '(', which is the start of403 an argument list.377 This rule handles ambiguous cases with operator identifiers, e.g., "int *?*?()", where the string "*?*?" can be 378 lexed as "*?"/"*?" or "*"/"?*?". Since it is common practise to put a unary operator juxtaposed to an identifier, 379 e.g., "*i", users will be annoyed if they cannot do this with respect to operator identifiers. Therefore, there is 380 a lexical look-ahead for the second case, with backtracking to return the leading unary operator and then 381 reparsing the trailing operator identifier. Otherwise a space is needed between the unary operator and operator 382 identifier to disambiguate this common case. 383 384 A similar issue occurs with the dereference, *?(...), and routine-call, ?()(...) identifiers. The ambiguity 385 occurs when the deference operator has no parameters, *?() and *?()(...), requiring arbitrary whitespace 386 look-ahead for the routine-call parameter-list to disambiguate. However, the dereference operator must have a 387 parameter/argument to dereference *?(...). Hence, always interpreting the string *?() as * ?() does not preclude 388 any meaningful program. 389 390 The remaining cases are with the increment/decrement operators and conditional expression: 391 392 i++? ...(...); 393 i?++ ...(...); 394 395 requiring arbitrary whitespace look-ahead for the operator parameter-list, even though that interpretation is an 396 incorrect expression (juxtaposed identifiers). Therefore, it is necessary to disambiguate these cases with a 397 space: 398 399 i++ ? i : 0; 400 i? ++i : 0; 404 401 */ 405 {op_unary}"?"({op_unary_pre_post}|" [?]"|{op_binary_over}"?") {402 {op_unary}"?"({op_unary_pre_post}|"()"|"[?]"|{op_binary_over}"?") { 406 403 // 1 or 2 character unary operator ? 407 404 int i = yytext[1] == '?' ? 1 : 2; -
src/Parser/module.mk
r9c951e3 rb1e63ac5 11 11 ## Created On : Sat May 16 15:29:09 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Tue Aug 16 17:28:34 201614 ## Update Count : 10 113 ## Last Modified On : Wed Jun 28 21:58:29 2017 14 ## Update Count : 104 15 15 ############################################################################### 16 16 … … 29 29 Parser/TypeData.cc \ 30 30 Parser/LinkageSpec.cc \ 31 Parser/parse utility.cc31 Parser/parserutility.cc 32 32 33 33 MAINTAINERCLEANFILES += Parser/parser.output -
src/Parser/parser.hh
r9c951e3 rb1e63ac5 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // lex.h --7 // parser.hh -- 8 8 // 9 9 // Author : Peter A. Buhr 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 21 11:28:47 201613 // Update Count : 34 712 // Last Modified On : Wed Jun 28 22:10:17 2017 13 // Update Count : 349 14 14 // 15 15 16 #ifndef PARSER_ LEX_H17 #define PARSER_ LEX_H16 #ifndef PARSER_HH 17 #define PARSER_HH 18 18 19 19 int yylex(); … … 42 42 }; // Token 43 43 44 #endif // PARSER_ LEX_H44 #endif // PARSER_HH 45 45 46 46 // Local Variables: // -
src/Parser/parser.yy
r9c951e3 rb1e63ac5 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // cfa.y --7 // parser.yy -- 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 30 15:42:32 201713 // Update Count : 2 31812 // Last Modified On : Wed Jun 28 22:11:22 2017 13 // Update Count : 2414 14 14 // 15 15 … … 48 48 #include <cstdio> 49 49 #include <stack> 50 #include "lex.h"51 #include "parser.h"52 50 #include "ParseNode.h" 53 51 #include "TypedefTable.h" … … 85 83 } // for 86 84 } // distExt 85 86 bool forall = false; // aggregate have one or more forall qualifiers ? 87 87 %} 88 89 // Types declaration 90 %union 91 { 92 Token tok; 93 ParseNode * pn; 94 ExpressionNode * en; 95 DeclarationNode * decl; 96 DeclarationNode::Aggregate aggKey; 97 DeclarationNode::TypeClass tclass; 98 StatementNode * sn; 99 ConstantExpr * constant; 100 ForCtl * fctl; 101 LabelNode * label; 102 InitializerNode * in; 103 OperKinds op; 104 std::string * str; 105 bool flag; 106 } 88 107 89 108 //************************* TERMINAL TOKENS ******************************** … … 138 157 %token ATassign // @= 139 158 140 // Types declaration 141 %union 142 { 143 Token tok; 144 ParseNode * pn; 145 ExpressionNode * en; 146 DeclarationNode * decl; 147 DeclarationNode::Aggregate aggKey; 148 DeclarationNode::TypeClass tclass; 149 StatementNode * sn; 150 ConstantExpr * constant; 151 ForCtl * fctl; 152 LabelNode * label; 153 InitializerNode * in; 154 OperKinds op; 155 std::string * str; 156 bool flag; 157 } 158 159 %type<tok> identifier no_01_identifier no_attr_identifier zero_one 160 %type<tok> identifier_or_type_name no_attr_identifier_or_type_name no_01_identifier_or_type_name attr_name 159 %type<tok> identifier no_attr_identifier zero_one 160 %type<tok> identifier_or_type_name no_attr_identifier_or_type_name attr_name 161 161 %type<constant> string_literal 162 162 %type<str> string_literal_list … … 191 191 %type<sn> case_value_list case_label case_label_list 192 192 %type<sn> switch_clause_list_opt switch_clause_list choose_clause_list_opt choose_clause_list 193 %type<sn> handler_listhandler_clause finally_clause193 %type<sn> /* handler_list */ handler_clause finally_clause 194 194 195 195 // declarations … … 205 205 %type<en> bit_subrange_size_opt bit_subrange_size 206 206 207 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type _name indirect_type_name207 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type 208 208 209 209 %type<decl> trait_declaration trait_declaration_list trait_declaring_list trait_specifier … … 259 259 %type<decl> type_declarator type_declarator_name type_declaring_list 260 260 261 %type<decl> typedef typedef_type_specifier typedef_declaration typedef_declaration_specifier typedef_expression 261 %type<decl> type_declaration_specifier type_type_specifier type_name typegen_name 262 %type<decl> typedef typedef_declaration typedef_expression 262 263 263 264 %type<decl> variable_type_redeclarator type_ptr type_array type_function 264 265 265 266 %type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function 266 %type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name 267 268 %type<decl> type_name type_name_no_function 269 %type<decl> type_parameter type_parameter_list 270 271 %type<en> type_name_list 267 268 %type<decl> type type_no_function 269 %type<decl> type_parameter type_parameter_list type_initializer_opt 270 271 %type<en> type_list 272 272 273 273 %type<decl> type_qualifier type_qualifier_name type_qualifier_list_opt type_qualifier_list … … 349 349 IDENTIFIER 350 350 | ATTR_IDENTIFIER // CFA 351 | zero_one // CFA352 ;353 354 no_01_identifier:355 IDENTIFIER356 | ATTR_IDENTIFIER // CFA357 351 ; 358 352 359 353 no_attr_identifier: 360 354 IDENTIFIER 361 | zero_one // CFA362 355 ; 363 356 … … 365 358 ZERO 366 359 | ONE 367 ;360 ; 368 361 369 362 string_literal: … … 393 386 | '(' compound_statement ')' // GCC, lambda expression 394 387 { $$ = new ExpressionNode( build_valexpr( $2 ) ); } 395 | primary_expression '{' argument_expression_list '}' // CFA 388 | primary_expression '{' argument_expression_list '}' // CFA, constructor call 396 389 { 397 390 Token fn; … … 399 392 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) ); 400 393 } 394 | type_name '.' no_attr_identifier // CFA, nested type 395 { $$ = nullptr; } // FIX ME 396 | type_name '.' '[' push field_list pop ']' // CFA, nested type / tuple field selector 397 { $$ = nullptr; } // FIX ME 401 398 ; 402 399 … … 429 426 | postfix_expression DECR 430 427 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); } 431 | '(' type_n ame_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal428 | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal 432 429 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } 433 430 | '^' primary_expression '{' argument_expression_list '}' // CFA … … 481 478 | no_attr_identifier fraction_constants 482 479 { 483 if( (*$1) == "0" || (*$1) == "1" ) {484 $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantZeroOne( *$1 ), $2 ) );485 } else {486 $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );487 }480 $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) ); 481 } 482 | zero_one fraction_constants 483 { 484 $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantZeroOne( *$1 ), $2 ) ); 488 485 } 489 486 ; … … 533 530 | SIZEOF unary_expression 534 531 { $$ = new ExpressionNode( build_sizeOfexpr( $2 ) ); } 535 | SIZEOF '(' type_n ame_no_function ')'532 | SIZEOF '(' type_no_function ')' 536 533 { $$ = new ExpressionNode( build_sizeOftype( $3 ) ); } 537 534 | ALIGNOF unary_expression // GCC, variable alignment 538 535 { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); } 539 | ALIGNOF '(' type_n ame_no_function ')' // GCC, type alignment536 | ALIGNOF '(' type_no_function ')' // GCC, type alignment 540 537 { $$ = new ExpressionNode( build_alignOftype( $3 ) ); } 541 | OFFSETOF '(' type_n ame_no_function ',' no_attr_identifier ')'538 | OFFSETOF '(' type_no_function ',' no_attr_identifier ')' 542 539 { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); } 543 540 | ATTR_IDENTIFIER … … 545 542 | ATTR_IDENTIFIER '(' argument_expression ')' 546 543 { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), $3 ) ); } 547 | ATTR_IDENTIFIER '(' type _name')'544 | ATTR_IDENTIFIER '(' type ')' 548 545 { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); } 549 546 // | ANDAND IDENTIFIER // GCC, address of label 550 // { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2 , true) ); }547 // { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2 ) ); } 551 548 ; 552 549 … … 567 564 cast_expression: 568 565 unary_expression 569 | '(' type_n ame_no_function ')' cast_expression566 | '(' type_no_function ')' cast_expression 570 567 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 571 // | '(' type_n ame_no_function ')' tuple568 // | '(' type_no_function ')' tuple 572 569 // { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 573 570 ; … … 656 653 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 657 654 { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); } 658 // | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression659 // { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }660 655 ; 661 656 … … 669 664 | unary_expression assignment_operator assignment_expression 670 665 { $$ = new ExpressionNode( build_binary_ptr( $2, $1, $3 ) ); } 671 // | tuple assignment_opt // CFA, tuple expression672 // { $$ = ( $2 == 0 ) ? $1 : new ExpressionNode( build_binary_ptr( OperKinds::Assign, $1, $2 ) ); }673 666 ; 674 667 … … 936 929 { $$ = new StatementNode( build_throw( $2 ) ); } 937 930 | THROWRESUME assignment_expression_opt ';' // handles reresume 938 { $$ = new StatementNode( build_ throw( $2 ) ); }931 { $$ = new StatementNode( build_resume( $2 ) ); } 939 932 | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume 940 { $$ = new StatementNode( build_ throw( $2) ); }933 { $$ = new StatementNode( build_resume_at( $2, $4 ) ); } 941 934 ; 942 935 943 936 exception_statement: 944 TRY compound_statement handler_ list937 TRY compound_statement handler_clause 945 938 { $$ = new StatementNode( build_try( $2, $3, 0 ) ); } 946 939 | TRY compound_statement finally_clause 947 940 { $$ = new StatementNode( build_try( $2, 0, $3 ) ); } 948 | TRY compound_statement handler_ listfinally_clause941 | TRY compound_statement handler_clause finally_clause 949 942 { $$ = new StatementNode( build_try( $2, $3, $4 ) ); } 950 943 ; 951 944 952 handler_list:953 handler_clause954 // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block.955 | CATCH '(' ELLIPSIS ')' compound_statement956 { $$ = new StatementNode( build_catch( 0, $5, true ) ); }957 | handler_clause CATCH '(' ELLIPSIS ')' compound_statement958 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }959 | CATCHRESUME '(' ELLIPSIS ')' compound_statement960 { $$ = new StatementNode( build_catch( 0, $5, true ) ); }961 | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement962 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); }963 ;945 //handler_list: 946 // handler_clause 947 // // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block. 948 // | CATCH '(' ELLIPSIS ')' compound_statement 949 // { $$ = new StatementNode( build_catch( 0, $5, true ) ); } 950 // | handler_clause CATCH '(' ELLIPSIS ')' compound_statement 951 // { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); } 952 // | CATCHRESUME '(' ELLIPSIS ')' compound_statement 953 // { $$ = new StatementNode( build_catch( 0, $5, true ) ); } 954 // | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement 955 // { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true ) ) ); } 956 // ; 964 957 965 958 handler_clause: 966 CATCH '(' push push exception_declaration pop ')' compound_statement pop 967 { $$ = new StatementNode( build_catch( $5, $8 ) ); } 959 // TEMPORARY, TEST EXCEPTIONS 960 CATCH '(' push push INTEGERconstant pop ')' compound_statement pop 961 { $$ = new StatementNode( build_catch( CatchStmt::Terminate, nullptr, new ExpressionNode( build_constantInteger( *$5 ) ), $8 ) ); } 962 | handler_clause CATCH '(' push push INTEGERconstant pop ')' compound_statement pop 963 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( CatchStmt::Terminate, nullptr, new ExpressionNode( build_constantInteger( *$6 ) ), $9 ) ) ); } 964 965 | CATCH '(' push push exception_declaration pop ')' compound_statement pop 966 { $$ = new StatementNode( build_catch( CatchStmt::Terminate, $5, nullptr, $8 ) ); } 968 967 | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop 969 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }968 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( CatchStmt::Terminate, $6, nullptr, $9 ) ) ); } 970 969 | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 971 { $$ = new StatementNode( build_catch( $5, $8 ) ); }970 { $$ = new StatementNode( build_catch( CatchStmt::Resume, $5, nullptr, $8 ) ); } 972 971 | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 973 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 ) ) ); }972 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( CatchStmt::Resume, $6, nullptr, $9 ) ) ); } 974 973 ; 975 974 … … 1350 1349 basic_declaration_specifier 1351 1350 | sue_declaration_specifier 1352 | typedef_declaration_specifier 1353 | typegen_declaration_specifier 1351 | type_declaration_specifier 1354 1352 ; 1355 1353 … … 1362 1360 basic_declaration_specifier 1363 1361 | sue_declaration_specifier_nobody 1364 | typedef_declaration_specifier 1365 | typegen_declaration_specifier 1362 | type_declaration_specifier 1366 1363 ; 1367 1364 … … 1369 1366 basic_type_specifier 1370 1367 | sue_type_specifier 1371 | typedef_type_specifier 1372 | typegen_type_specifier 1368 | type_type_specifier 1373 1369 ; 1374 1370 … … 1381 1377 basic_type_specifier 1382 1378 | sue_type_specifier_nobody 1383 | typedef_type_specifier 1384 | typegen_type_specifier 1379 | type_type_specifier 1385 1380 ; 1386 1381 … … 1517 1512 1518 1513 basic_type_specifier: 1519 direct_type _name1520 | type_qualifier_list_opt indirect_type _nametype_qualifier_list_opt1514 direct_type 1515 | type_qualifier_list_opt indirect_type type_qualifier_list_opt 1521 1516 { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); } 1522 1517 ; 1523 1518 1524 direct_type _name:1519 direct_type: 1525 1520 // A semantic check is necessary for conflicting type qualifiers. 1526 1521 basic_type_name 1527 1522 | type_qualifier_list basic_type_name 1528 1523 { $$ = $2->addQualifiers( $1 ); } 1529 | direct_type _nametype_qualifier1524 | direct_type type_qualifier 1530 1525 { $$ = $1->addQualifiers( $2 ); } 1531 | direct_type _namebasic_type_name1526 | direct_type basic_type_name 1532 1527 { $$ = $1->addType( $2 ); } 1533 1528 ; 1534 1529 1535 indirect_type _name:1536 TYPEOF '(' type _name ')'// GCC: typeof(x) y;1530 indirect_type: 1531 TYPEOF '(' type ')' // GCC: typeof(x) y; 1537 1532 { $$ = $3; } 1538 1533 | TYPEOF '(' comma_expression ')' // GCC: typeof(a+b) y; 1539 1534 { $$ = DeclarationNode::newTypeof( $3 ); } 1540 | ATTR_TYPEGENname '(' type _name ')'// CFA: e.g., @type(x) y;1535 | ATTR_TYPEGENname '(' type ')' // CFA: e.g., @type(x) y; 1541 1536 { $$ = DeclarationNode::newAttr( $1, $3 ); } 1542 1537 | ATTR_TYPEGENname '(' comma_expression ')' // CFA: e.g., @type(a+b) y; … … 1556 1551 sue_type_specifier: // struct, union, enum + type specifier 1557 1552 elaborated_type 1558 | type_qualifier_list elaborated_type 1559 { $$ = $2->addQualifiers( $1 ); } 1553 | type_qualifier_list 1554 { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type 1555 elaborated_type 1556 { $$ = $3->addQualifiers( $1 ); } 1560 1557 | sue_type_specifier type_qualifier 1561 1558 { $$ = $1->addQualifiers( $2 ); } … … 1580 1577 ; 1581 1578 1582 type def_declaration_specifier:1583 type def_type_specifier1584 | declaration_qualifier_list type def_type_specifier1579 type_declaration_specifier: 1580 type_type_specifier 1581 | declaration_qualifier_list type_type_specifier 1585 1582 { $$ = $2->addQualifiers( $1 ); } 1586 | type def_declaration_specifier storage_class// remaining OBSOLESCENT (see 2)1583 | type_declaration_specifier storage_class // remaining OBSOLESCENT (see 2) 1587 1584 { $$ = $1->addQualifiers( $2 ); } 1588 | type def_declaration_specifier storage_class type_qualifier_list1585 | type_declaration_specifier storage_class type_qualifier_list 1589 1586 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } 1590 1587 ; 1591 1588 1592 typedef_type_specifier: // typedef types 1589 type_type_specifier: // typedef types 1590 type_name 1591 | type_qualifier_list type_name 1592 { $$ = $2->addQualifiers( $1 ); } 1593 | type_type_specifier type_qualifier 1594 { $$ = $1->addQualifiers( $2 ); } 1595 ; 1596 1597 type_name: 1593 1598 TYPEDEFname 1594 1599 { $$ = DeclarationNode::newFromTypedef( $1 ); } 1595 | type_qualifier_list TYPEDEFname 1596 { $$ = DeclarationNode::newFromTypedef( $2 )->addQualifiers( $1 ); } 1597 | typedef_type_specifier type_qualifier 1598 { $$ = $1->addQualifiers( $2 ); } 1600 | '.' TYPEDEFname 1601 { $$ = DeclarationNode::newFromTypedef( $2 ); } // FIX ME 1602 | type_name '.' TYPEDEFname 1603 { $$ = DeclarationNode::newFromTypedef( $3 ); } // FIX ME 1604 | typegen_name 1605 | '.' typegen_name 1606 { $$ = $2; } // FIX ME 1607 | type_name '.' typegen_name 1608 { $$ = $3; } // FIX ME 1609 ; 1610 1611 typegen_name: // CFA 1612 TYPEGENname '(' ')' 1613 { $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); } 1614 | TYPEGENname '(' type_list ')' 1615 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); } 1599 1616 ; 1600 1617 … … 1613 1630 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); } 1614 1631 | aggregate_key attribute_list_opt no_attr_identifier_or_type_name 1615 { typedefTable.makeTypedef( *$3 ); } 1632 { 1633 typedefTable.makeTypedef( *$3 ); // create typedef 1634 if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update 1635 forall = false; // reset 1636 } 1616 1637 '{' field_declaration_list '}' 1617 1638 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); } 1618 | aggregate_key attribute_list_opt '(' type_ name_list ')' '{' field_declaration_list '}' // CFA1639 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA 1619 1640 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); } 1620 1641 | aggregate_type_nobody … … 1622 1643 1623 1644 aggregate_type_nobody: // struct, union - {...} 1624 aggregate_key attribute_list_opt no_attr_identifier _or_type_name1645 aggregate_key attribute_list_opt no_attr_identifier 1625 1646 { 1626 1647 typedefTable.makeTypedef( *$3 ); 1627 1648 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 1628 1649 } 1629 | aggregate_key attribute_list_opt typegen_name // CFA, S/R conflict 1650 | aggregate_key attribute_list_opt TYPEDEFname 1651 { 1652 typedefTable.makeTypedef( *$3 ); 1653 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 1654 } 1655 | aggregate_key attribute_list_opt typegen_name // CFA 1630 1656 { $$ = $3->addQualifiers( $2 ); } 1631 1657 ; … … 1865 1891 ; 1866 1892 1867 no_01_identifier_or_type_name:1868 no_01_identifier1869 | TYPEDEFname1870 | TYPEGENname1871 ;1872 1873 1893 no_attr_identifier_or_type_name: 1874 1894 no_attr_identifier … … 1877 1897 ; 1878 1898 1879 type_n ame_no_function:// sizeof, alignof, cast (constructor)1899 type_no_function: // sizeof, alignof, cast (constructor) 1880 1900 cfa_abstract_declarator_tuple // CFA 1881 1901 | type_specifier … … 1884 1904 ; 1885 1905 1886 type _name:// typeof, assertion1887 type_n ame_no_function1906 type: // typeof, assertion 1907 type_no_function 1888 1908 | cfa_abstract_function // CFA 1889 1909 ; … … 1925 1945 designation: 1926 1946 designator_list ':' // C99, CFA uses ":" instead of "=" 1927 | no_attr_identifier _or_type_name ':'// GCC, field name1947 | no_attr_identifier ':' // GCC, field name 1928 1948 { $$ = new ExpressionNode( build_varref( $1 ) ); } 1929 1949 ; … … 1937 1957 1938 1958 designator: 1939 '.' no_attr_identifier _or_type_name// C99, field name1959 '.' no_attr_identifier // C99, field name 1940 1960 { $$ = new ExpressionNode( build_varref( $2 ) ); } 1941 1961 | '[' push assignment_expression pop ']' // C99, single array element … … 1968 1988 // on type arguments of polymorphic functions. 1969 1989 1970 typegen_declaration_specifier: // CFA1971 typegen_type_specifier1972 | declaration_qualifier_list typegen_type_specifier1973 { $$ = $2->addQualifiers( $1 ); }1974 | typegen_declaration_specifier storage_class // remaining OBSOLESCENT (see 2)1975 { $$ = $1->addQualifiers( $2 ); }1976 | typegen_declaration_specifier storage_class type_qualifier_list1977 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); }1978 ;1979 1980 typegen_type_specifier: // CFA1981 typegen_name1982 | type_qualifier_list typegen_name1983 { $$ = $2->addQualifiers( $1 ); }1984 | typegen_type_specifier type_qualifier1985 { $$ = $1->addQualifiers( $2 ); }1986 ;1987 1988 typegen_name: // CFA1989 TYPEGENname '(' type_name_list ')'1990 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }1991 ;1992 1993 1990 type_parameter_list: // CFA 1994 type_parameter assignment_opt 1995 | type_parameter_list ',' type_parameter assignment_opt 1991 type_parameter 1992 { $$ = $1; } 1993 | type_parameter_list ',' type_parameter 1996 1994 { $$ = $1->appendList( $3 ); } 1995 ; 1996 1997 type_initializer_opt: // CFA 1998 // empty 1999 { $$ = nullptr; } 2000 | '=' type 2001 { $$ = $2; } 1997 2002 ; 1998 2003 … … 2000 2005 type_class no_attr_identifier_or_type_name 2001 2006 { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); } 2002 assertion_list_opt2003 { $$ = DeclarationNode::newTypeParam( $1, $2 )->add Assertions( $4); }2007 type_initializer_opt assertion_list_opt 2008 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } 2004 2009 | type_specifier identifier_parameter_declarator 2005 2010 ; … … 2024 2029 2025 2030 assertion: // CFA 2026 '|' no_attr_identifier_or_type_name '(' type_ name_list ')'2031 '|' no_attr_identifier_or_type_name '(' type_list ')' 2027 2032 { 2028 2033 typedefTable.openTrait( *$2 ); … … 2031 2036 | '|' '{' push trait_declaration_list '}' 2032 2037 { $$ = $4; } 2033 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_ name_list ')'2038 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')' 2034 2039 { $$ = nullptr; } 2035 2040 ; 2036 2041 2037 type_ name_list:// CFA2038 type _name2042 type_list: // CFA 2043 type 2039 2044 { $$ = new ExpressionNode( build_typevalue( $1 ) ); } 2040 2045 | assignment_expression 2041 | type_ name_list ',' type_name2046 | type_list ',' type 2042 2047 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( build_typevalue( $3 ) ) ) ); } 2043 | type_ name_list ',' assignment_expression2048 | type_list ',' assignment_expression 2044 2049 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2045 2050 ; … … 2057 2062 type_declarator_name assertion_list_opt 2058 2063 { $$ = $1->addAssertions( $2 ); } 2059 | type_declarator_name assertion_list_opt '=' type _name2064 | type_declarator_name assertion_list_opt '=' type 2060 2065 { $$ = $1->addAssertions( $2 )->addType( $4 ); } 2061 2066 ; … … 2067 2072 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2068 2073 } 2069 | no_ 01_identifier_or_type_name '(' push type_parameter_list pop ')'2074 | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' 2070 2075 { 2071 2076 typedefTable.addToEnclosingScope( *$1, TypedefTable::TG ); … … 2093 2098 ; 2094 2099 2095 trait_declaration_list: // CFA2100 trait_declaration_list: // CFA 2096 2101 trait_declaration 2097 2102 | trait_declaration_list push trait_declaration … … 2099 2104 ; 2100 2105 2101 trait_declaration: // CFA2106 trait_declaration: // CFA 2102 2107 cfa_trait_declaring_list pop ';' 2103 2108 | trait_declaring_list pop ';' -
src/Parser/parserutility.cc
r9c951e3 rb1e63ac5 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // parse utility.cc --7 // parserutility.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:30:39 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 14 23:45:03 201613 // Update Count : 312 // Last Modified On : Wed Jun 28 22:11:32 2017 13 // Update Count : 7 14 14 // 15 15 16 #include "parse utility.h"16 #include "parserutility.h" 17 17 #include "SynTree/Type.h" 18 18 #include "SynTree/Expression.h" … … 26 26 UntypedExpr *comparison = new UntypedExpr( new NameExpr( "?!=?" ) ); 27 27 comparison->get_args().push_back( orig ); 28 comparison->get_args().push_back( new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0" ) ) );28 comparison->get_args().push_back( new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0", (unsigned long long int)0 ) ) ); 29 29 return new CastExpr( comparison, new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 30 30 } -
src/Parser/parserutility.h
r9c951e3 rb1e63ac5 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // parse utility.h --7 // parserutility.h -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:31:46 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 16 15:32:58 201513 // Update Count : 212 // Last Modified On : Wed Jun 28 22:11:40 2017 13 // Update Count : 3 14 14 // 15 15
Note:
See TracChangeset
for help on using the changeset viewer.