- Timestamp:
- Mar 9, 2023, 2:37:53 PM (14 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- fed03b3
- Parents:
- a29477f
- Location:
- src/Parser
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
ra29477f r702e826 41 41 42 42 // These must harmonize with the corresponding DeclarationNode enumerations. 43 const char * DeclarationNode::basicTypeNames[] = { "void", "_Bool", "char", "int", "int128", 44 "float", "double", "long double", "float80", "float128", 45 "_float16", "_float32", "_float32x", "_float64", "_float64x", "_float128", "_float128x", "NoBasicTypeNames" }; 46 const char * DeclarationNode::complexTypeNames[] = { "_Complex", "NoComplexTypeNames", "_Imaginary" }; // Imaginary unsupported => parse, but make invisible and print error message 47 const char * DeclarationNode::signednessNames[] = { "signed", "unsigned", "NoSignednessNames" }; 48 const char * DeclarationNode::lengthNames[] = { "short", "long", "long long", "NoLengthNames" }; 49 const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "__auto_type", "zero_t", "one_t", "NoBuiltinTypeNames" }; 43 const char * DeclarationNode::basicTypeNames[] = { 44 "void", "_Bool", "char", "int", "int128", 45 "float", "double", "long double", "float80", "float128", 46 "_float16", "_float32", "_float32x", "_float64", "_float64x", "_float128", "_float128x", "NoBasicTypeNames" 47 }; 48 const char * DeclarationNode::complexTypeNames[] = { 49 "_Complex", "NoComplexTypeNames", "_Imaginary" 50 }; // Imaginary unsupported => parse, but make invisible and print error message 51 const char * DeclarationNode::signednessNames[] = { 52 "signed", "unsigned", "NoSignednessNames" 53 }; 54 const char * DeclarationNode::lengthNames[] = { 55 "short", "long", "long long", "NoLengthNames" 56 }; 57 const char * DeclarationNode::builtinTypeNames[] = { 58 "__builtin_va_list", "__auto_type", "zero_t", "one_t", "NoBuiltinTypeNames" 59 }; 50 60 51 61 UniqueName DeclarationNode::anonymous( "__anonymous" ); … … 70 80 delete variable.initializer; 71 81 72 // 82 // delete type; 73 83 delete bitfieldWidth; 74 84 … … 504 514 // src is the new item being added and has a single bit 505 515 } else if ( ! src->storageClasses.is_threadlocal_any() ) { // conflict ? 506 appendError( error, string( "conflicting " ) + Type::StorageClassesNames[storageClasses.ffs()] + 507 " & " + Type::StorageClassesNames[src->storageClasses.ffs()] ); 516 appendError( error, string( "conflicting " ) 517 + Type::StorageClassesNames[storageClasses.ffs()] 518 + " & " + Type::StorageClassesNames[src->storageClasses.ffs()] ); 508 519 src->storageClasses.reset(); // FIX to preserve invariant of one basic storage specifier 509 520 } // if … … 589 600 } else { 590 601 switch ( dst->kind ) { 591 602 case TypeData::Unknown: 592 603 src->qualifiers |= dst->qualifiers; 593 604 dst = src; 594 605 src = nullptr; 595 606 break; 596 607 case TypeData::Basic: 597 608 dst->qualifiers |= src->qualifiers; 598 609 if ( src->kind != TypeData::Unknown ) { … … 622 633 } // if 623 634 break; 624 635 default: 625 636 switch ( src->kind ) { 626 627 637 case TypeData::Aggregate: 638 case TypeData::Enum: 628 639 dst->base = new TypeData( TypeData::AggregateInst ); 629 640 dst->base->aggInst.aggregate = src; … … 634 645 src = nullptr; 635 646 break; 636 647 default: 637 648 if ( dst->forall ) { 638 649 dst->forall->appendList( src->forall ); … … 706 717 DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) { 707 718 if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) { 708 709 710 711 712 713 719 if ( variable.assertions ) { 720 variable.assertions->appendList( assertions ); 721 } else { 722 variable.assertions = assertions; 723 } // if 724 return this; 714 725 } // if 715 726 716 727 assert( type ); 717 728 switch ( type->kind ) { 718 729 case TypeData::Symbolic: 719 730 if ( type->symbolic.assertions ) { 720 731 type->symbolic.assertions->appendList( assertions ); … … 723 734 } // if 724 735 break; 725 736 default: 726 737 assert( false ); 727 738 } // switch … … 822 833 if ( type ) { 823 834 switch ( type->kind ) { 824 825 835 case TypeData::Aggregate: 836 case TypeData::Enum: 826 837 p->type->base = new TypeData( TypeData::AggregateInst ); 827 838 p->type->base->aggInst.aggregate = type; … … 832 843 break; 833 844 834 845 default: 835 846 p->type->base = type; 836 847 } // switch … … 854 865 855 866 DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) { 856 867 if ( ! a ) return this; 857 868 assert( a->type->kind == TypeData::Array ); 858 869 TypeData * lastArray = findLast( a->type ); 859 870 if ( type ) { 860 871 switch ( type->kind ) { 861 862 872 case TypeData::Aggregate: 873 case TypeData::Enum: 863 874 lastArray->base = new TypeData( TypeData::AggregateInst ); 864 875 lastArray->base->aggInst.aggregate = type; … … 868 879 lastArray->base->qualifiers |= type->qualifiers; 869 880 break; 870 881 default: 871 882 lastArray->base = type; 872 883 } // switch … … 1204 1215 } // if 1205 1216 bool isDelete = initializer && initializer->get_isDelete(); 1206 Declaration * decl = buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild < Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, isDelete ? nullptr : maybeBuild< Initializer >(initializer), attributes )->set_extension( extension );1217 Declaration * decl = buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild( bitfieldWidth ), funcSpecs, linkage, asmName, isDelete ? nullptr : maybeBuild(initializer), attributes )->set_extension( extension ); 1207 1218 if ( isDelete ) { 1208 1219 DeclarationWithType * dwt = strict_dynamic_cast<DeclarationWithType *>( decl ); … … 1213 1224 1214 1225 if ( assert.condition ) { 1215 return new StaticAssertDecl( maybeBuild < Expression >( assert.condition ), strict_dynamic_cast< ConstantExpr * >( maybeClone( assert.message ) ) );1226 return new StaticAssertDecl( maybeBuild( assert.condition ), strict_dynamic_cast< ConstantExpr * >( maybeClone( assert.message ) ) ); 1216 1227 } 1217 1228 … … 1227 1238 } // if 1228 1239 assertf( name, "ObjectDecl must a have name\n" ); 1229 return (new ObjectDecl( *name, storageClasses, linkage, maybeBuild < Expression >( bitfieldWidth ), nullptr, maybeBuild< Initializer >( initializer ) ))->set_asmName( asmName )->set_extension( extension );1240 return (new ObjectDecl( *name, storageClasses, linkage, maybeBuild( bitfieldWidth ), nullptr, maybeBuild( initializer ) ))->set_asmName( asmName )->set_extension( extension ); 1230 1241 } 1231 1242 … … 1234 1245 1235 1246 switch ( type->kind ) { 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1247 case TypeData::Enum: 1248 case TypeData::Aggregate: { 1249 ReferenceToType * ret = buildComAggInst( type, attributes, linkage ); 1250 buildList( type->aggregate.actuals, ret->get_parameters() ); 1251 return ret; 1252 } 1253 case TypeData::Symbolic: { 1254 TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false, attributes ); 1255 buildList( type->symbolic.actuals, ret->get_parameters() ); 1256 return ret; 1257 } 1258 default: 1248 1259 Type * simpletypes = typebuild( type ); 1249 1260 simpletypes->get_attributes() = attributes; // copy because member is const -
src/Parser/ExpressionNode.cc
ra29477f r702e826 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat May 16 13:17:07 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Feb 11 14:49:00 202313 // Update Count : 10 7911 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Mar 0 10:46:00 2023 13 // Update Count : 1080 14 14 // 15 15 … … 71 71 size_t end = str.length() - 1; 72 72 if ( posn == end ) { type = 3; return; } // no length after 'l' => long 73 73 74 74 string::size_type next = posn + 1; // advance to length 75 75 if ( str[next] == '3' ) { // 32 … … 122 122 if ( str[i] == '1' ) v |= 1; 123 123 i += 1; 124 124 if ( i == last - 1 || (str[i] != '0' && str[i] != '1') ) break; 125 125 v <<= 1; 126 126 } // for … … 157 157 } // if 158 158 159 string::size_type posn;160 161 159 // 'u' can appear before or after length suffix 162 160 if ( str.find_last_of( "uU" ) != string::npos ) Unsigned = true; … … 164 162 if ( isdigit( str[str.length() - 1] ) ) { // no suffix ? 165 163 lnthSuffix( str, type, ltype ); // could have length suffix 164 // At least one digit in integer constant, 165 // so safe to backup while looking for suffix. 166 // pointer value 167 } else if ( auto posn = str.find_last_of( "pP" ) ; posn != string::npos ) { 168 ltype = 5; str.erase( posn, 1 ); 169 // size_t 170 } else if ( auto posn = str.find_last_of( "zZ" ) ; posn != string::npos ) { 171 Unsigned = true; type = 2; ltype = 4; str.erase( posn, 1 ); 172 // signed char 173 } else if ( auto posn = str.rfind( "hh" ) ; posn != string::npos ) { 174 type = 1; str.erase( posn, 2 ); 175 // signed char 176 } else if ( auto posn = str.rfind( "HH" ) ; posn != string::npos ) { 177 type = 1; str.erase( posn, 2 ); 178 // short 179 } else if ( auto posn = str.find_last_of( "hH" ) ; posn != string::npos ) { 180 type = 0; str.erase( posn, 1 ); 181 // int (natural number) 182 } else if ( auto posn = str.find_last_of( "nN" ) ; posn != string::npos ) { 183 type = 2; str.erase( posn, 1 ); 184 } else if ( str.rfind( "ll" ) != string::npos || str.rfind( "LL" ) != string::npos ) { 185 type = 4; 166 186 } else { 167 // At least one digit in integer constant, so safe to backup while looking for suffix. 168 169 posn = str.find_last_of( "pP" ); // pointer value 170 if ( posn != string::npos ) { ltype = 5; str.erase( posn, 1 ); goto FINI; } 171 172 posn = str.find_last_of( "zZ" ); // size_t 173 if ( posn != string::npos ) { Unsigned = true; type = 2; ltype = 4; str.erase( posn, 1 ); goto FINI; } 174 175 posn = str.rfind( "hh" ); // signed char 176 if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; } 177 178 posn = str.rfind( "HH" ); // signed char 179 if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; } 180 181 posn = str.find_last_of( "hH" ); // short 182 if ( posn != string::npos ) { type = 0; str.erase( posn, 1 ); goto FINI; } 183 184 posn = str.find_last_of( "nN" ); // int (natural number) 185 if ( posn != string::npos ) { type = 2; str.erase( posn, 1 ); goto FINI; } 186 187 if ( str.rfind( "ll" ) != string::npos || str.rfind( "LL" ) != string::npos ) { type = 4; goto FINI; } 188 189 lnthSuffix( str, type, ltype ); // must be after check for "ll" 190 FINI: ; 191 } // if 187 lnthSuffix( str, type, ltype ); 188 } 192 189 193 190 // Cannot be just "0"/"1"; sscanf stops at the suffix, if any; value goes over the wall => always generate … … 196 193 if ( type == 5 ) SemanticError( yylloc, "int128 constant is not supported on this target " + str ); 197 194 #endif // ! __SIZEOF_INT128__ 198 195 199 196 if ( str[0] == '0' ) { // radix character ? 200 197 dec = false; … … 206 203 unsigned int len = str.length(); 207 204 if ( len > (2 + 16 + 16) ) SemanticError( yylloc, "128-bit hexadecimal constant to large " + str ); 208 if ( len <= (2 + 16) ) goto FHEX1; // hex digits < 2^64 209 str2 = "0x" + str.substr( len - 16 ); 210 sscanf( (char *)str2.c_str(), "%llx", &v2 ); 211 str = str.substr( 0, len - 16 ); 212 FHEX1: ; 205 // hex digits < 2^64 206 if ( len > (2 + 16) ) { 207 str2 = "0x" + str.substr( len - 16 ); 208 sscanf( (char *)str2.c_str(), "%llx", &v2 ); 209 str = str.substr( 0, len - 16 ); 210 } 213 211 sscanf( (char *)str.c_str(), "%llx", &v ); 214 212 #endif // __SIZEOF_INT128__ … … 309 307 // ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][type] ), false ); 310 308 ret2 = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::LongLongSignedInt ), str2, v2 ) ); 311 ret = build_compoundLiteral( DeclarationNode::newBasicType( DeclarationNode::Int128 )->addType( DeclarationNode::newSignedNess( DeclarationNode::Unsigned ) ), 312 new InitializerNode( (InitializerNode *)(new InitializerNode( new ExpressionNode( v2 == 0 ? ret2 : ret ) ))->set_last( new InitializerNode( new ExpressionNode( v2 == 0 ? ret : ret2 ) ) ), true ) ); 309 ret = build_compoundLiteral( 310 DeclarationNode::newBasicType( DeclarationNode::Int128 )->addType( DeclarationNode::newSignedNess( DeclarationNode::Unsigned ) ), 311 new InitializerNode( (InitializerNode *)(new InitializerNode( new ExpressionNode( v2 == 0 ? ret2 : ret ) ))->set_last( new InitializerNode( new ExpressionNode( v2 == 0 ? ret : ret2 ) ) ), true ) ); 313 312 } else { // explicit length, (length_type)constant 314 313 ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][ltype], false ), false ); … … 435 434 Type * strtype; 436 435 switch ( str[0] ) { // str has >= 2 characters, i.e, null string "" => safe to look at subscripts 0/1 437 436 case 'u': 438 437 if ( str[1] == '8' ) goto Default; // utf-8 characters => array of char 439 438 // lookup type of associated typedef 440 439 strtype = new TypeInstType( Type::Qualifiers( ), "char16_t", false ); 441 440 break; 442 441 case 'U': 443 442 strtype = new TypeInstType( Type::Qualifiers( ), "char32_t", false ); 444 443 break; 445 444 case 'L': 446 445 strtype = new TypeInstType( Type::Qualifiers( ), "wchar_t", false ); 447 446 break; 448 449 447 Default: // char default string type 448 default: 450 449 strtype = new BasicType( Type::Qualifiers( ), BasicType::Char ); 451 450 } // switch … … 500 499 501 500 Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts ) { 502 return make_field_name_fraction_constants( fieldName, maybeMoveBuild < Expression >( fracts ) );501 return make_field_name_fraction_constants( fieldName, maybeMoveBuild( fracts ) ); 503 502 } // build_field_name_fraction_constants 504 503 … … 510 509 511 510 QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name ) { 512 Declaration * newDecl = maybeBuild < Declaration >(decl_node);511 Declaration * newDecl = maybeBuild(decl_node); 513 512 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { 514 513 const Type * t = newDeclWithType->get_type(); … … 548 547 if ( dynamic_cast< VoidType * >( targetType ) ) { 549 548 delete targetType; 550 return new CastExpr( maybeMoveBuild < Expression >(expr_node), false );549 return new CastExpr( maybeMoveBuild( expr_node ), false ); 551 550 } else { 552 return new CastExpr( maybeMoveBuild < Expression >(expr_node), targetType, false );551 return new CastExpr( maybeMoveBuild( expr_node ), targetType, false ); 553 552 } // if 554 553 } // build_cast 555 554 556 555 Expression * build_keyword_cast( AggregateDecl::Aggregate target, ExpressionNode * expr_node ) { 557 return new KeywordCastExpr( maybeMoveBuild < Expression >(expr_node), target );556 return new KeywordCastExpr( maybeMoveBuild( expr_node ), target ); 558 557 } 559 558 560 559 Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) { 561 return new VirtualCastExpr( maybeMoveBuild < Expression >( expr_node ), maybeMoveBuildType( decl_node ) );560 return new VirtualCastExpr( maybeMoveBuild( expr_node ), maybeMoveBuildType( decl_node ) ); 562 561 } // build_virtual_cast 563 562 564 563 Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ) { 565 return new UntypedMemberExpr( member, maybeMoveBuild < Expression >(expr_node) );564 return new UntypedMemberExpr( member, maybeMoveBuild( expr_node ) ); 566 565 } // build_fieldSel 567 566 … … 569 568 UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) ); 570 569 deref->location = expr_node->location; 571 deref->get_args().push_back( maybeMoveBuild < Expression >(expr_node) );570 deref->get_args().push_back( maybeMoveBuild( expr_node ) ); 572 571 UntypedMemberExpr * ret = new UntypedMemberExpr( member, deref ); 573 572 return ret; … … 581 580 582 581 Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind ) { 583 return new LogicalExpr( notZeroExpr( maybeMoveBuild < Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression >(expr_node2) ), kind );582 return new LogicalExpr( notZeroExpr( maybeMoveBuild( expr_node1 ) ), notZeroExpr( maybeMoveBuild( expr_node2 ) ), kind ); 584 583 } // build_and_or 585 584 586 585 Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) { 587 586 list< Expression * > args; 588 args.push_back( maybeMoveBuild < Expression >(expr_node) );587 args.push_back( maybeMoveBuild( expr_node ) ); 589 588 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 590 589 } // build_unary_val 591 590 592 Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) {593 list< Expression * > args;594 args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.595 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );596 } // build_unary_ptr597 598 591 Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 599 592 list< Expression * > args; 600 args.push_back( maybeMoveBuild < Expression >(expr_node1) );601 args.push_back( maybeMoveBuild < Expression >(expr_node2) );593 args.push_back( maybeMoveBuild( expr_node1 ) ); 594 args.push_back( maybeMoveBuild( expr_node2 ) ); 602 595 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 603 596 } // build_binary_val … … 605 598 Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 606 599 list< Expression * > args; 607 args.push_back( maybeMoveBuild < Expression >(expr_node1) );608 args.push_back( maybeMoveBuild < Expression >(expr_node2) );600 args.push_back( maybeMoveBuild( expr_node1 ) ); 601 args.push_back( maybeMoveBuild( expr_node2 ) ); 609 602 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 610 603 } // build_binary_ptr 611 604 612 605 Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 ) { 613 return new ConditionalExpr( notZeroExpr( maybeMoveBuild < Expression >(expr_node1) ), maybeMoveBuild< Expression >(expr_node2), maybeMoveBuild< Expression >(expr_node3) );606 return new ConditionalExpr( notZeroExpr( maybeMoveBuild( expr_node1 ) ), maybeMoveBuild( expr_node2 ), maybeMoveBuild( expr_node3 ) ); 614 607 } // build_cond 615 608 … … 623 616 list< Expression * > args; 624 617 buildMoveList( expr_node, args ); 625 return new UntypedExpr( maybeMoveBuild < Expression >(function), args );618 return new UntypedExpr( maybeMoveBuild( function ), args ); 626 619 } // build_func 627 620 628 621 Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ) { 629 Declaration * newDecl = maybeBuild < Declaration >(decl_node); // compound literal type622 Declaration * newDecl = maybeBuild( decl_node ); // compound literal type 630 623 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type 631 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeMoveBuild < Initializer >(kids) );624 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeMoveBuild( kids ) ); 632 625 // these types do not have associated type information 633 626 } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl ) ) { 634 627 if ( newDeclStructDecl->has_body() ) { 635 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl ), maybeMoveBuild < Initializer >(kids) );628 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl ), maybeMoveBuild( kids ) ); 636 629 } else { 637 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeMoveBuild < Initializer >(kids) );630 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeMoveBuild( kids ) ); 638 631 } // if 639 632 } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl ) ) { 640 633 if ( newDeclUnionDecl->has_body() ) { 641 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl ), maybeMoveBuild < Initializer >(kids) );634 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl ), maybeMoveBuild( kids ) ); 642 635 } else { 643 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeMoveBuild < Initializer >(kids) );636 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeMoveBuild( kids ) ); 644 637 } // if 645 638 } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl ) ) { 646 639 if ( newDeclEnumDecl->has_body() ) { 647 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl ), maybeMoveBuild < Initializer >(kids) );640 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl ), maybeMoveBuild( kids ) ); 648 641 } else { 649 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeMoveBuild < Initializer >(kids) );642 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeMoveBuild( kids ) ); 650 643 } // if 651 644 } else { -
src/Parser/InitializerNode.cc
ra29477f r702e826 102 102 if ( get_expression() ) { 103 103 assertf( get_expression()->expr, "The expression of initializer must have value" ); 104 return new SingleInit( maybeBuild < Expression >( get_expression() ), maybeConstructed );104 return new SingleInit( maybeBuild( get_expression() ), maybeConstructed ); 105 105 } // if 106 106 } // if -
src/Parser/ParseNode.h
ra29477f r702e826 137 137 bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr.get()); } 138 138 139 Expression * build() const { return const_cast<ExpressionNode *>(this)->expr.release(); } 139 Expression * build() const { 140 Expression * node = const_cast<ExpressionNode *>(this)->expr.release(); 141 node->set_extension( this->get_extension() ); 142 node->location = this->location; 143 return node; 144 } 140 145 141 146 std::unique_ptr<Expression> expr; // public because of lifetime implications … … 143 148 bool extension = false; 144 149 }; // ExpressionNode 145 146 template< typename T >147 struct maybeBuild_t< Expression, T > {148 static inline Expression * doit( const T * orig ) {149 if ( orig ) {150 Expression * p = orig->build();151 p->set_extension( orig->get_extension() );152 p->location = orig->location;153 return p;154 } else {155 return nullptr;156 } // if157 }158 };159 150 160 151 // Must harmonize with OperName. … … 199 190 Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind ); 200 191 Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ); 201 Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node );202 192 Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ); 203 193 Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ); … … 213 203 struct DeclarationNode : public ParseNode { 214 204 // These enumerations must harmonize with their names in DeclarationNode.cc. 215 enum BasicType { Void, Bool, Char, Int, Int128, 216 Float, Double, LongDouble, uuFloat80, uuFloat128, 217 uFloat16, uFloat32, uFloat32x, uFloat64, uFloat64x, uFloat128, uFloat128x, NoBasicType }; 205 enum BasicType { 206 Void, Bool, Char, Int, Int128, 207 Float, Double, LongDouble, uuFloat80, uuFloat128, 208 uFloat16, uFloat32, uFloat32x, uFloat64, uFloat64x, uFloat128, uFloat128x, 209 NoBasicType 210 }; 218 211 static const char * basicTypeNames[]; 219 212 enum ComplexType { Complex, NoComplexType, Imaginary }; // Imaginary unsupported => parse, but make invisible and print error message … … 451 444 while ( cur ) { 452 445 try { 453 SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild < typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) );446 SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild( cur ) ); 454 447 if ( result ) { 455 448 result->location = cur->location; -
src/Parser/StatementNode.cc
ra29477f r702e826 38 38 DeclarationNode * agg = decl->extractAggregate(); 39 39 if ( agg ) { 40 StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild < Declaration >( decl ) ) );40 StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild( decl ) ) ); 41 41 set_next( nextStmt ); 42 42 if ( decl->get_next() ) { … … 51 51 agg = decl; 52 52 } // if 53 stmt.reset( new DeclStmt( maybeMoveBuild < Declaration >(agg) ) );53 stmt.reset( new DeclStmt( maybeMoveBuild( agg ) ) ); 54 54 } // StatementNode::StatementNode 55 55 … … 73 73 74 74 Statement * build_expr( ExpressionNode * ctl ) { 75 Expression * e = maybeMoveBuild < Expression >( ctl );75 Expression * e = maybeMoveBuild( ctl ); 76 76 77 77 if ( e ) return new ExprStmt( e ); … … 87 87 if ( ctl->condition ) { 88 88 // compare the provided condition against 0 89 cond = notZeroExpr( maybeMoveBuild < Expression >(ctl->condition) );89 cond = notZeroExpr( maybeMoveBuild( ctl->condition ) ); 90 90 } else { 91 91 for ( Statement * stmt : init ) { … … 134 134 } // if 135 135 // aststmt.size() == 0 for switch (...) {}, i.e., no declaration or statements 136 return new SwitchStmt( maybeMoveBuild < Expression >(ctl), aststmt );136 return new SwitchStmt( maybeMoveBuild( ctl ), aststmt ); 137 137 } // build_switch 138 138 139 139 Statement * build_case( ExpressionNode * ctl ) { 140 return new CaseStmt( maybeMoveBuild < Expression >(ctl), {} ); // stmt starts empty and then added to140 return new CaseStmt( maybeMoveBuild( ctl ), {} ); // stmt starts empty and then added to 141 141 } // build_case 142 142 … … 168 168 169 169 // do-while cannot have declarations in the contitional, so init is always empty 170 return new WhileDoStmt( notZeroExpr( maybeMoveBuild < Expression >(ctl) ), aststmt.front(), astelse.front(), {}, true );170 return new WhileDoStmt( notZeroExpr( maybeMoveBuild( ctl ) ), aststmt.front(), astelse.front(), {}, true ); 171 171 } // build_do_while 172 172 … … 176 176 177 177 Expression * astcond = nullptr; // maybe empty 178 astcond = notZeroExpr( maybeMoveBuild < Expression >(forctl->condition) );178 astcond = notZeroExpr( maybeMoveBuild( forctl->condition ) ); 179 179 180 180 Expression * astincr = nullptr; // maybe empty 181 astincr = maybeMoveBuild < Expression >(forctl->change);181 astincr = maybeMoveBuild( forctl->change ); 182 182 delete forctl; 183 183 … … 199 199 Statement * build_branch( string * identifier, BranchStmt::Type kind ) { 200 200 Statement * ret = new BranchStmt( * identifier, kind ); 201 delete identifier; 201 delete identifier; // allocated by lexer 202 202 return ret; 203 203 } // build_branch 204 204 205 205 Statement * build_computedgoto( ExpressionNode * ctl ) { 206 return new BranchStmt( maybeMoveBuild < Expression >(ctl), BranchStmt::Goto );206 return new BranchStmt( maybeMoveBuild( ctl ), BranchStmt::Goto ); 207 207 } // build_computedgoto 208 208 … … 236 236 list< CatchStmt * > aststmt; 237 237 buildMoveList< CatchStmt, StatementNode >( catch_, aststmt ); 238 CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >( maybeMoveBuild< Statement >(try_));239 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >( maybeMoveBuild< Statement >(finally_) );238 CompoundStmt * tryBlock = strict_dynamic_cast< CompoundStmt * >( maybeMoveBuild( try_ ) ); 239 FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >( maybeMoveBuild( finally_ ) ); 240 240 return new TryStmt( tryBlock, aststmt, finallyBlock ); 241 241 } // build_try … … 245 245 buildMoveList< Statement, StatementNode >( body, aststmt ); 246 246 assert( aststmt.size() == 1 ); 247 return new CatchStmt( kind, maybeMoveBuild < Declaration >(decl), maybeMoveBuild< Expression >(cond), aststmt.front() );247 return new CatchStmt( kind, maybeMoveBuild( decl ), maybeMoveBuild( cond ), aststmt.front() ); 248 248 } // build_catch 249 249 … … 274 274 275 275 WaitForStmt::Target target; 276 target.function = maybeBuild <Expression>( targetExpr );276 target.function = maybeBuild( targetExpr ); 277 277 278 278 ExpressionNode * next = dynamic_cast<ExpressionNode *>( targetExpr->get_next() ); … … 284 284 node->clauses.push_back( WaitForStmt::Clause{ 285 285 target, 286 maybeMoveBuild <Statement >( stmt ),287 notZeroExpr( maybeMoveBuild <Expression>( when ) )286 maybeMoveBuild( stmt ), 287 notZeroExpr( maybeMoveBuild( when ) ) 288 288 }); 289 289 … … 293 293 WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when, WaitForStmt * node ) { 294 294 WaitForStmt::Target target; 295 target.function = maybeBuild <Expression>( targetExpr );295 target.function = maybeBuild( targetExpr ); 296 296 297 297 ExpressionNode * next = dynamic_cast<ExpressionNode *>( targetExpr->get_next() ); … … 303 303 node->clauses.insert( node->clauses.begin(), WaitForStmt::Clause{ 304 304 std::move( target ), 305 maybeMoveBuild <Statement >( stmt ),306 notZeroExpr( maybeMoveBuild <Expression>( when ) )305 maybeMoveBuild( stmt ), 306 notZeroExpr( maybeMoveBuild( when ) ) 307 307 }); 308 308 … … 314 314 315 315 if( timeout ) { 316 node->timeout.time = maybeMoveBuild <Expression>( timeout );317 node->timeout.statement = maybeMoveBuild <Statement >( stmt );318 node->timeout.condition = notZeroExpr( maybeMoveBuild <Expression>( when ) );316 node->timeout.time = maybeMoveBuild( timeout ); 317 node->timeout.statement = maybeMoveBuild( stmt ); 318 node->timeout.condition = notZeroExpr( maybeMoveBuild( when ) ); 319 319 } else { 320 node->orelse.statement = maybeMoveBuild <Statement >( stmt );321 node->orelse.condition = notZeroExpr( maybeMoveBuild <Expression>( when ) );320 node->orelse.statement = maybeMoveBuild( stmt ); 321 node->orelse.condition = notZeroExpr( maybeMoveBuild( when ) ); 322 322 } // if 323 323 … … 328 328 auto node = new WaitForStmt(); 329 329 330 node->timeout.time = maybeMoveBuild <Expression>( timeout );331 node->timeout.statement = maybeMoveBuild <Statement >( stmt );332 node->timeout.condition = notZeroExpr( maybeMoveBuild <Expression>( when ) );333 334 node->orelse.statement = maybeMoveBuild <Statement >( else_ );335 node->orelse.condition = notZeroExpr( maybeMoveBuild <Expression>( else_when ) );330 node->timeout.time = maybeMoveBuild( timeout ); 331 node->timeout.statement = maybeMoveBuild( stmt ); 332 node->timeout.condition = notZeroExpr( maybeMoveBuild( when ) ); 333 334 node->orelse.statement = maybeMoveBuild( else_ ); 335 node->orelse.condition = notZeroExpr( maybeMoveBuild( else_when ) ); 336 336 337 337 return node; … … 341 341 list< Expression * > e; 342 342 buildMoveList( exprs, e ); 343 Statement * s = maybeMoveBuild <Statement>( stmt );343 Statement * s = maybeMoveBuild( stmt ); 344 344 return new DeclStmt( new WithStmt( e, s ) ); 345 345 } // build_with … … 384 384 list< Expression * > expList; 385 385 buildMoveList( exprs, expList ); 386 Statement * body = maybeMoveBuild <Statement>( stmt );386 Statement * body = maybeMoveBuild( stmt ); 387 387 return new MutexStmt( body, expList ); 388 388 } // build_mutex -
src/Parser/TypeData.cc
ra29477f r702e826 33 33 TypeData::TypeData( Kind k ) : location( yylloc ), kind( k ), base( nullptr ), forall( nullptr ) /*, PTR1( (void*)(0xdeadbeefdeadbeef)), PTR2( (void*)(0xdeadbeefdeadbeef) ) */ { 34 34 switch ( kind ) { 35 case Unknown: 36 case Pointer: 37 case Reference: 38 case EnumConstant: 39 case GlobalScope: 40 // nothing else to initialize 41 break; 42 case Basic: 43 // basic = new Basic_t; 44 break; 45 case Array: 46 // array = new Array_t; 35 case Unknown: 36 case Pointer: 37 case Reference: 38 case EnumConstant: 39 case GlobalScope: 40 case Basic: 41 // No unique data to initialize. 42 break; 43 case Array: 47 44 array.dimension = nullptr; 48 45 array.isVarLen = false; 49 46 array.isStatic = false; 50 47 break; 51 case Function: 52 // function = new Function_t; 48 case Function: 53 49 function.params = nullptr; 54 50 function.idList = nullptr; … … 57 53 function.withExprs = nullptr; 58 54 break; 59 // Enum is an Aggregate, so both structures are initialized together. 60 case Enum: 61 // enumeration = new Enumeration_t; 55 case Enum: 62 56 enumeration.name = nullptr; 63 57 enumeration.constants = nullptr; … … 65 59 enumeration.anon = false; 66 60 break; 67 case Aggregate: 68 // aggregate = new Aggregate_t; 61 case Aggregate: 69 62 aggregate.kind = AggregateDecl::NoAggregate; 70 63 aggregate.name = nullptr; … … 77 70 aggregate.anon = false; 78 71 break; 79 case AggregateInst: 80 // aggInst = new AggInst_t; 72 case AggregateInst: 81 73 aggInst.aggregate = nullptr; 82 74 aggInst.params = nullptr; 83 75 aggInst.hoistType = false; 84 76 break; 85 case Symbolic: 86 case SymbolicInst: 87 // symbolic = new Symbolic_t; 77 case Symbolic: 78 case SymbolicInst: 88 79 symbolic.name = nullptr; 89 80 symbolic.params = nullptr; … … 91 82 symbolic.assertions = nullptr; 92 83 break; 93 case Tuple: 94 // tuple = new Tuple_t; 84 case Tuple: 95 85 tuple = nullptr; 96 86 break; 97 case Typeof: 98 case Basetypeof: 99 // typeexpr = new Typeof_t; 87 case Typeof: 88 case Basetypeof: 100 89 typeexpr = nullptr; 101 90 break; 102 case Vtable:103 break;104 case Builtin:105 // builtin = new Builtin_t;106 91 case Builtin: 92 case Vtable: 93 // No unique data to initialize. 94 break; 95 case Qualified: 107 96 qualified.parent = nullptr; 108 97 qualified.child = nullptr; … … 117 106 118 107 switch ( kind ) { 119 case Unknown: 120 case Pointer: 121 case Reference: 122 case EnumConstant: 123 case GlobalScope: 124 // nothing to destroy 125 break; 126 case Basic: 127 // delete basic; 128 break; 129 case Array: 108 case Unknown: 109 case Pointer: 110 case Reference: 111 case EnumConstant: 112 case GlobalScope: 113 // No unique data to deconstruct. 114 break; 115 case Basic: 116 break; 117 case Array: 130 118 delete array.dimension; 131 // delete array; 132 break; 133 case Function: 119 break; 120 case Function: 134 121 delete function.params; 135 122 delete function.idList; … … 137 124 delete function.body; 138 125 delete function.withExprs; 139 // delete function; 140 break; 141 case Aggregate: 126 break; 127 case Aggregate: 142 128 delete aggregate.name; 143 129 delete aggregate.params; 144 130 delete aggregate.actuals; 145 131 delete aggregate.fields; 146 // delete aggregate; 147 break; 148 case AggregateInst: 132 break; 133 case AggregateInst: 149 134 delete aggInst.aggregate; 150 135 delete aggInst.params; 151 // delete aggInst; 152 break; 153 case Enum: 136 break; 137 case Enum: 154 138 delete enumeration.name; 155 139 delete enumeration.constants; 156 // delete enumeration; 157 break; 158 case Symbolic: 159 case SymbolicInst: 140 break; 141 case Symbolic: 142 case SymbolicInst: 160 143 delete symbolic.name; 161 144 delete symbolic.params; 162 145 delete symbolic.actuals; 163 146 delete symbolic.assertions; 164 // delete symbolic; 165 break; 166 case Tuple: 167 // delete tuple->members; 147 break; 148 case Tuple: 168 149 delete tuple; 169 150 break; 170 case Typeof: 171 case Basetypeof: 172 // delete typeexpr->expr; 151 case Typeof: 152 case Basetypeof: 173 153 delete typeexpr; 174 154 break; 175 case Vtable: 176 break; 177 case Builtin: 178 // delete builtin; 179 break; 180 case Qualified: 155 case Vtable: 156 case Builtin: 157 // No unique data to deconstruct. 158 break; 159 case Qualified: 181 160 delete qualified.parent; 182 161 delete qualified.child; 162 break; 183 163 } // switch 184 164 } // TypeData::~TypeData … … 192 172 193 173 switch ( kind ) { 194 195 196 197 198 174 case Unknown: 175 case EnumConstant: 176 case Pointer: 177 case Reference: 178 case GlobalScope: 199 179 // nothing else to copy 200 180 break; 201 181 case Basic: 202 182 newtype->basictype = basictype; 203 183 newtype->complextype = complextype; … … 205 185 newtype->length = length; 206 186 break; 207 187 case Array: 208 188 newtype->array.dimension = maybeClone( array.dimension ); 209 189 newtype->array.isVarLen = array.isVarLen; 210 190 newtype->array.isStatic = array.isStatic; 211 191 break; 212 192 case Function: 213 193 newtype->function.params = maybeClone( function.params ); 214 194 newtype->function.idList = maybeClone( function.idList ); … … 217 197 newtype->function.withExprs = maybeClone( function.withExprs ); 218 198 break; 219 199 case Aggregate: 220 200 newtype->aggregate.kind = aggregate.kind; 221 201 newtype->aggregate.name = aggregate.name ? new string( *aggregate.name ) : nullptr; … … 228 208 newtype->aggregate.parent = aggregate.parent ? new string( *aggregate.parent ) : nullptr; 229 209 break; 230 210 case AggregateInst: 231 211 newtype->aggInst.aggregate = maybeClone( aggInst.aggregate ); 232 212 newtype->aggInst.params = maybeClone( aggInst.params ); 233 213 newtype->aggInst.hoistType = aggInst.hoistType; 234 214 break; 235 215 case Enum: 236 216 newtype->enumeration.name = enumeration.name ? new string( *enumeration.name ) : nullptr; 237 217 newtype->enumeration.constants = maybeClone( enumeration.constants ); … … 239 219 newtype->enumeration.anon = enumeration.anon; 240 220 break; 241 242 221 case Symbolic: 222 case SymbolicInst: 243 223 newtype->symbolic.name = symbolic.name ? new string( *symbolic.name ) : nullptr; 244 224 newtype->symbolic.params = maybeClone( symbolic.params ); … … 247 227 newtype->symbolic.isTypedef = symbolic.isTypedef; 248 228 break; 249 229 case Tuple: 250 230 newtype->tuple = maybeClone( tuple ); 251 231 break; 252 253 232 case Typeof: 233 case Basetypeof: 254 234 newtype->typeexpr = maybeClone( typeexpr ); 255 235 break; 256 257 break; 258 236 case Vtable: 237 break; 238 case Builtin: 259 239 assert( builtintype == DeclarationNode::Zero || builtintype == DeclarationNode::One ); 260 240 newtype->builtintype = builtintype; 261 241 break; 262 242 case Qualified: 263 243 newtype->qualified.parent = maybeClone( qualified.parent ); 264 244 newtype->qualified.child = maybeClone( qualified.child ); … … 280 260 281 261 switch ( kind ) { 282 262 case Basic: 283 263 if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessNames[ signedness ] << " "; 284 264 if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthNames[ length ] << " "; … … 286 266 if ( basictype != DeclarationNode::NoBasicType ) os << DeclarationNode::basicTypeNames[ basictype ] << " "; 287 267 break; 288 268 case Pointer: 289 269 os << "pointer "; 290 270 if ( base ) { … … 293 273 } // if 294 274 break; 295 275 case Reference: 296 276 os << "reference "; 297 277 if ( base ) { … … 300 280 } // if 301 281 break; 302 282 case Array: 303 283 if ( array.isStatic ) { 304 284 os << "static "; … … 316 296 } // if 317 297 break; 318 298 case Function: 319 299 os << "function" << endl; 320 300 if ( function.params ) { … … 344 324 } // if 345 325 break; 346 326 case Aggregate: 347 327 os << AggregateDecl::aggrString( aggregate.kind ) << ' ' << *aggregate.name << endl; 348 328 if ( aggregate.params ) { … … 362 342 } // if 363 343 break; 364 344 case AggregateInst: 365 345 if ( aggInst.aggregate ) { 366 346 os << "instance of " ; … … 374 354 } // if 375 355 break; 376 356 case Enum: 377 357 os << "enumeration " << *enumeration.name << endl;; 378 358 if ( enumeration.constants ) { … … 388 368 } // if 389 369 break; 390 370 case EnumConstant: 391 371 os << "enumeration constant "; 392 372 break; 393 373 case Symbolic: 394 374 if ( symbolic.isTypedef ) { 395 375 os << "typedef definition "; … … 411 391 } // if 412 392 break; 413 393 case SymbolicInst: 414 394 os << *symbolic.name; 415 395 if ( symbolic.actuals ) { … … 419 399 } // if 420 400 break; 421 401 case Tuple: 422 402 os << "tuple "; 423 403 if ( tuple ) { … … 426 406 } // if 427 407 break; 428 408 case Basetypeof: 429 409 os << "base-"; 430 410 #if defined(__GNUC__) && __GNUC__ >= 7 … … 432 412 #endif 433 413 // FALL THROUGH 434 414 case Typeof: 435 415 os << "type-of expression "; 436 416 if ( typeexpr ) { … … 438 418 } // if 439 419 break; 440 420 case Vtable: 441 421 os << "vtable"; 442 422 break; 443 423 case Builtin: 444 424 os << DeclarationNode::builtinTypeNames[builtintype]; 445 425 break; 446 447 break; 448 426 case GlobalScope: 427 break; 428 case Qualified: 449 429 qualified.parent->print( os ); 450 430 os << "."; 451 431 qualified.child->print( os ); 452 432 break; 453 433 case Unknown: 454 434 os << "entity of unknown type "; 455 435 break; 456 436 default: 457 437 os << "internal error: TypeData::print " << kind << endl; 458 438 assert( false ); … … 462 442 const std::string * TypeData::leafName() const { 463 443 switch ( kind ) { 464 465 466 467 468 469 470 471 472 473 474 475 476 477 444 case Unknown: 445 case Pointer: 446 case Reference: 447 case EnumConstant: 448 case GlobalScope: 449 case Array: 450 case Basic: 451 case Function: 452 case AggregateInst: 453 case Tuple: 454 case Typeof: 455 case Basetypeof: 456 case Builtin: 457 case Vtable: 478 458 assertf(false, "Tried to get leaf name from kind without a name: %d", kind); 479 459 break; 480 460 case Aggregate: 481 461 return aggregate.name; 482 462 case Enum: 483 463 return enumeration.name; 484 485 464 case Symbolic: 465 case SymbolicInst: 486 466 return symbolic.name; 487 467 case Qualified: 488 468 return qualified.child->leafName(); 489 469 } // switch … … 530 510 assert( td ); 531 511 switch ( td->kind ) { 532 512 case TypeData::Unknown: 533 513 // fill in implicit int 534 514 return new BasicType( buildQualifiers( td ), BasicType::SignedInt ); 535 515 case TypeData::Basic: 536 516 return buildBasicType( td ); 537 517 case TypeData::Pointer: 538 518 return buildPointer( td ); 539 519 case TypeData::Array: 540 520 return buildArray( td ); 541 521 case TypeData::Reference: 542 522 return buildReference( td ); 543 523 case TypeData::Function: 544 524 return buildFunction( td ); 545 525 case TypeData::AggregateInst: 546 526 return buildAggInst( td ); 547 527 case TypeData::EnumConstant: 548 528 return new EnumInstType( buildQualifiers( td ), "" ); 549 529 case TypeData::SymbolicInst: 550 530 return buildSymbolicInst( td ); 551 531 case TypeData::Tuple: 552 532 return buildTuple( td ); 553 554 533 case TypeData::Typeof: 534 case TypeData::Basetypeof: 555 535 return buildTypeof( td ); 556 536 case TypeData::Vtable: 557 537 return buildVtable( td ); 558 538 case TypeData::Builtin: 559 539 switch ( td->builtintype ) { 560 540 case DeclarationNode::Zero: 561 541 return new ZeroType( noQualifiers ); 562 542 case DeclarationNode::One: 563 543 return new OneType( noQualifiers ); 564 544 default: 565 545 return new VarArgsType( buildQualifiers( td ) ); 566 546 } // switch 567 547 case TypeData::GlobalScope: 568 548 return new GlobalScopeType(); 569 549 case TypeData::Qualified: 570 550 return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) ); 571 572 573 551 case TypeData::Symbolic: 552 case TypeData::Enum: 553 case TypeData::Aggregate: 574 554 assert( false ); 575 555 } // switch … … 583 563 584 564 switch ( td->kind ) { 585 565 case TypeData::Aggregate: 586 566 if ( ! toplevel && td->aggregate.body ) { 587 567 ret = td->clone(); 588 568 } // if 589 569 break; 590 570 case TypeData::Enum: 591 571 if ( ! toplevel && td->enumeration.body ) { 592 572 ret = td->clone(); 593 573 } // if 594 574 break; 595 575 case TypeData::AggregateInst: 596 576 if ( td->aggInst.aggregate ) { 597 577 ret = typeextractAggregate( td->aggInst.aggregate, false ); 598 578 } // if 599 579 break; 600 580 default: 601 581 if ( td->base ) { 602 582 ret = typeextractAggregate( td->base, false ); … … 620 600 621 601 switch ( td->basictype ) { 622 602 case DeclarationNode::Void: 623 603 if ( td->signedness != DeclarationNode::NoSignedness ) { 624 604 genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype ); … … 630 610 break; 631 611 632 612 case DeclarationNode::Bool: 633 613 if ( td->signedness != DeclarationNode::NoSignedness ) { 634 614 genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype ); … … 641 621 break; 642 622 643 623 case DeclarationNode::Char: 644 624 // C11 Standard 6.2.5.15: The three types char, signed char, and unsigned char are collectively called the 645 625 // character types. The implementation shall define char to have the same range, representation, and behavior as … … 654 634 break; 655 635 656 636 case DeclarationNode::Int: 657 637 static BasicType::Kind inttype[2][4] = { 658 638 { BasicType::ShortSignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt, BasicType::SignedInt }, … … 660 640 }; 661 641 662 642 Integral: ; 663 643 if ( td->signedness == DeclarationNode::NoSignedness ) { 664 644 const_cast<TypeData *>(td)->signedness = DeclarationNode::Signed; … … 667 647 break; 668 648 669 649 case DeclarationNode::Int128: 670 650 ret = td->signedness == DeclarationNode::Unsigned ? BasicType::UnsignedInt128 : BasicType::SignedInt128; 671 651 if ( td->length != DeclarationNode::NoLength ) { … … 674 654 break; 675 655 676 677 678 679 680 681 682 683 684 685 686 687 656 case DeclarationNode::Float: 657 case DeclarationNode::Double: 658 case DeclarationNode::LongDouble: // not set until below 659 case DeclarationNode::uuFloat80: 660 case DeclarationNode::uuFloat128: 661 case DeclarationNode::uFloat16: 662 case DeclarationNode::uFloat32: 663 case DeclarationNode::uFloat32x: 664 case DeclarationNode::uFloat64: 665 case DeclarationNode::uFloat64x: 666 case DeclarationNode::uFloat128: 667 case DeclarationNode::uFloat128x: 688 668 static BasicType::Kind floattype[2][12] = { 689 669 { 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, }, … … 691 671 }; 692 672 693 673 FloatingPoint: ; 694 674 if ( td->signedness != DeclarationNode::NoSignedness ) { 695 675 genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype ); … … 715 695 break; 716 696 717 697 case DeclarationNode::NoBasicType: 718 698 // No basic type in declaration => default double for Complex/Imaginary and int type for integral types 719 699 if ( td->complextype == DeclarationNode::Complex || td->complextype == DeclarationNode::Imaginary ) { … … 724 704 const_cast<TypeData *>(td)->basictype = DeclarationNode::Int; 725 705 goto Integral; 726 727 706 default: 707 assertf( false, "unknown basic type" ); 728 708 return nullptr; 729 709 } // switch … … 750 730 ArrayType * at; 751 731 if ( td->base ) { 752 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild < Expression >( td->array.dimension ),732 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild( td->array.dimension ), 753 733 td->array.isVarLen, td->array.isStatic ); 754 734 } else { 755 735 at = new ArrayType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 756 maybeBuild < Expression >( td->array.dimension ), td->array.isVarLen, td->array.isStatic );736 maybeBuild( td->array.dimension ), td->array.isVarLen, td->array.isStatic ); 757 737 } // if 758 738 buildForall( td->forall, at->get_forall() ); … … 777 757 AggregateDecl * at; 778 758 switch ( td->aggregate.kind ) { 779 780 781 782 783 784 759 case AggregateDecl::Struct: 760 case AggregateDecl::Coroutine: 761 case AggregateDecl::Exception: 762 case AggregateDecl::Generator: 763 case AggregateDecl::Monitor: 764 case AggregateDecl::Thread: 785 765 at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes, linkage ); 786 766 buildForall( td->aggregate.params, at->get_parameters() ); 787 767 break; 788 768 case AggregateDecl::Union: 789 769 at = new UnionDecl( *td->aggregate.name, attributes, linkage ); 790 770 buildForall( td->aggregate.params, at->get_parameters() ); 791 771 break; 792 772 case AggregateDecl::Trait: 793 773 at = new TraitDecl( *td->aggregate.name, attributes, linkage ); 794 774 buildList( td->aggregate.params, at->get_parameters() ); 795 775 break; 796 776 default: 797 777 assert( false ); 798 778 } // switch … … 807 787 ReferenceToType * buildComAggInst( const TypeData * type, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) { 808 788 switch ( type->kind ) { 809 case TypeData::Enum: { 810 if ( type->enumeration.body ) { 811 EnumDecl * typedecl = buildEnum( type, attributes, linkage ); 812 return new EnumInstType( buildQualifiers( type ), typedecl ); 813 } else { 814 return new EnumInstType( buildQualifiers( type ), *type->enumeration.name ); 815 } // if 816 } 817 case TypeData::Aggregate: { 818 ReferenceToType * ret; 819 if ( type->aggregate.body ) { 820 AggregateDecl * typedecl = buildAggregate( type, attributes, linkage ); 821 switch ( type->aggregate.kind ) { 822 case AggregateDecl::Struct: 823 case AggregateDecl::Coroutine: 824 case AggregateDecl::Monitor: 825 case AggregateDecl::Thread: 826 ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl ); 827 break; 828 case AggregateDecl::Union: 829 ret = new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl ); 830 break; 831 case AggregateDecl::Trait: 832 assert( false ); 833 //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl ); 834 break; 835 default: 836 assert( false ); 837 } // switch 838 } else { 839 switch ( type->aggregate.kind ) { 840 case AggregateDecl::Struct: 841 case AggregateDecl::Coroutine: 842 case AggregateDecl::Monitor: 843 case AggregateDecl::Thread: 844 ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name ); 845 break; 846 case AggregateDecl::Union: 847 ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name ); 848 break; 849 case AggregateDecl::Trait: 850 ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name ); 851 break; 852 default: 853 assert( false ); 854 } // switch 855 } // if 856 return ret; 857 } 858 default: 789 case TypeData::Enum: 790 if ( type->enumeration.body ) { 791 EnumDecl * typedecl = buildEnum( type, attributes, linkage ); 792 return new EnumInstType( buildQualifiers( type ), typedecl ); 793 } else { 794 return new EnumInstType( buildQualifiers( type ), *type->enumeration.name ); 795 } // if 796 case TypeData::Aggregate: 797 if ( type->aggregate.body ) { 798 AggregateDecl * typedecl = buildAggregate( type, attributes, linkage ); 799 switch ( type->aggregate.kind ) { 800 case AggregateDecl::Struct: 801 case AggregateDecl::Coroutine: 802 case AggregateDecl::Monitor: 803 case AggregateDecl::Thread: 804 return new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl ); 805 case AggregateDecl::Union: 806 return new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl ); 807 case AggregateDecl::Trait: 808 assert( false ); 809 //return new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl ); 810 break; 811 default: 812 assert( false ); 813 } // switch 814 } else { 815 switch ( type->aggregate.kind ) { 816 case AggregateDecl::Struct: 817 case AggregateDecl::Coroutine: 818 case AggregateDecl::Monitor: 819 case AggregateDecl::Thread: 820 return new StructInstType( buildQualifiers( type ), *type->aggregate.name ); 821 case AggregateDecl::Union: 822 return new UnionInstType( buildQualifiers( type ), *type->aggregate.name ); 823 case AggregateDecl::Trait: 824 return new TraitInstType( buildQualifiers( type ), *type->aggregate.name ); 825 default: 826 assert( false ); 827 } // switch 828 } // if 829 return nullptr; 830 default: 859 831 assert( false ); 860 832 } // switch … … 869 841 TypeData * type = td->aggInst.aggregate; 870 842 switch ( type->kind ) { 871 case TypeData::Enum: { 872 return new EnumInstType( buildQualifiers( type ), *type->enumeration.name ); 873 } 874 case TypeData::Aggregate: { 875 switch ( type->aggregate.kind ) { 876 case AggregateDecl::Struct: 877 case AggregateDecl::Coroutine: 878 case AggregateDecl::Monitor: 879 case AggregateDecl::Thread: 880 ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name ); 881 break; 882 case AggregateDecl::Union: 883 ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name ); 884 break; 885 case AggregateDecl::Trait: 886 ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name ); 887 break; 888 default: 889 assert( false ); 890 } // switch 891 } 892 break; 893 default: 843 case TypeData::Enum: 844 return new EnumInstType( buildQualifiers( type ), *type->enumeration.name ); 845 case TypeData::Aggregate: 846 switch ( type->aggregate.kind ) { 847 case AggregateDecl::Struct: 848 case AggregateDecl::Coroutine: 849 case AggregateDecl::Monitor: 850 case AggregateDecl::Thread: 851 ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name ); 852 break; 853 case AggregateDecl::Union: 854 ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name ); 855 break; 856 case AggregateDecl::Trait: 857 ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name ); 858 break; 859 default: 860 assert( false ); 861 } // switch 862 break; 863 default: 894 864 assert( false ); 895 865 } // switch … … 931 901 } else if ( cur->has_enumeratorValue() ) { 932 902 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 933 member->set_init( new SingleInit( maybeMoveBuild < Expression >( cur->consume_enumeratorValue() ) ) );903 member->set_init( new SingleInit( maybeMoveBuild( cur->consume_enumeratorValue() ) ) ); 934 904 } else if ( !cur->initializer ) { 935 905 if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isInteger())) { … … 985 955 986 956 FunctionDecl * decl; 987 Statement * stmt = maybeBuild <Statement>( td->function.body );957 Statement * stmt = maybeBuild( td->function.body ); 988 958 CompoundStmt * body = dynamic_cast< CompoundStmt * >( stmt ); 989 959 decl = new FunctionDecl( name, scs, linkage, buildFunction( td ), body, attributes, funcSpec ); … … 1010 980 if ( td->base ) { 1011 981 switch ( td->base->kind ) { 1012 982 case TypeData::Tuple: 1013 983 buildList( td->base->tuple, ft->returnVals ); 1014 984 break; 1015 985 default: 1016 986 ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType * >( buildDecl( td->base, "", Type::StorageClasses(), nullptr, Type::FuncSpecifiers(), LinkageSpec::Cforall, nullptr ) ) ); 1017 987 } // switch -
src/Parser/TypeData.h
ra29477f r702e826 130 130 TypeofType * buildTypeof( const TypeData * ); 131 131 VTableType * buildVtable( const TypeData * ); 132 Declaration * buildDecl( const TypeData *, const std::string &, Type::StorageClasses, Expression *, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec, Expression * asmName, 133 Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() ); 132 Declaration * buildDecl( 133 const TypeData *, const std::string &, Type::StorageClasses, Expression *, 134 Type::FuncSpecifiers funcSpec, LinkageSpec::Spec, Expression * asmName, 135 Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() ); 134 136 FunctionType * buildFunction( const TypeData * ); 135 137 Declaration * addEnumBase( Declaration *, const TypeData * ); -
src/Parser/TypedefTable.cc
ra29477f r702e826 31 31 static const char *kindName( int kind ) { 32 32 switch ( kind ) { 33 34 35 36 37 33 case IDENTIFIER: return "identifier"; 34 case TYPEDIMname: return "typedim"; 35 case TYPEDEFname: return "typedef"; 36 case TYPEGENname: return "typegen"; 37 default: 38 38 cerr << "Error: cfa-cpp internal error, invalid kind of identifier" << endl; 39 39 abort(); -
src/Parser/parser.yy
ra29477f r702e826 223 223 ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get()); 224 224 if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) { 225 type = new ExpressionNode( new CastExpr( maybeMoveBuild <Expression>(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );225 type = new ExpressionNode( new CastExpr( maybeMoveBuild( type ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) ); 226 226 } // if 227 227 // type = new ExpressionNode( build_func( new ExpressionNode( build_varref( new string( "__for_control_index_constraints__" ) ) ), type ) ); … … 649 649 { $$ = $2; } 650 650 | '(' compound_statement ')' // GCC, lambda expression 651 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild <Statement>($2) ) ) ); }651 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild( $2 ) ) ) ); } 652 652 | type_name '.' identifier // CFA, nested type 653 653 { $$ = new ExpressionNode( build_qualified_expr( $1, build_varref( $3 ) ) ); } … … 657 657 { 658 658 // add the missing control expression to the GenericExpr and return it 659 $5->control = maybeMoveBuild <Expression>( $3 );659 $5->control = maybeMoveBuild( $3 ); 660 660 $$ = new ExpressionNode( $5 ); 661 661 } … … 693 693 { 694 694 // create a GenericExpr wrapper with one association pair 695 $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild <Expression>( $3 ) } } );695 $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild( $3 ) } } ); 696 696 } 697 697 | DEFAULT ':' assignment_expression 698 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild <Expression>( $3 ) } } ); }698 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild( $3 ) } } ); } 699 699 ; 700 700 … … 751 751 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 752 752 | postfix_expression ICR 753 { $$ = new ExpressionNode( build_unary_ ptr( OperKinds::IncrPost, $1 ) ); }753 { $$ = new ExpressionNode( build_unary_val( OperKinds::IncrPost, $1 ) ); } 754 754 | postfix_expression DECR 755 { $$ = new ExpressionNode( build_unary_ ptr( OperKinds::DecrPost, $1 ) ); }755 { $$ = new ExpressionNode( build_unary_val( OperKinds::DecrPost, $1 ) ); } 756 756 | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal 757 757 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } … … 793 793 field_name 794 794 | FLOATING_DECIMALconstant field 795 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild <Expression>( $2 ) ) ); }795 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild( $2 ) ) ); } 796 796 | FLOATING_DECIMALconstant '[' field_name_list ']' 797 797 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); } 798 798 | field_name '.' field 799 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild <Expression>( $3 ) ) ); }799 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild( $3 ) ) ); } 800 800 | field_name '.' '[' field_name_list ']' 801 801 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 802 802 | field_name ARROW field 803 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild <Expression>( $3 ) ) ); }803 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild( $3 ) ) ); } 804 804 | field_name ARROW '[' field_name_list ']' 805 805 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } … … 843 843 switch ( $1 ) { 844 844 case OperKinds::AddressOf: 845 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild <Expression>( $2 ) ) );845 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild( $2 ) ) ); 846 846 break; 847 847 case OperKinds::PointTo: … … 849 849 break; 850 850 case OperKinds::And: 851 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild <Expression>( $2 ) ) ) );851 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild( $2 ) ) ) ); 852 852 break; 853 853 default: … … 858 858 { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); } 859 859 | ICR unary_expression 860 { $$ = new ExpressionNode( build_unary_ ptr( OperKinds::Incr, $2 ) ); }860 { $$ = new ExpressionNode( build_unary_val( OperKinds::Incr, $2 ) ); } 861 861 | DECR unary_expression 862 { $$ = new ExpressionNode( build_unary_ ptr( OperKinds::Decr, $2 ) ); }862 { $$ = new ExpressionNode( build_unary_val( OperKinds::Decr, $2 ) ); } 863 863 | SIZEOF unary_expression 864 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild <Expression>( $2 ) ) ); }864 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild( $2 ) ) ); } 865 865 | SIZEOF '(' type_no_function ')' 866 866 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuildType( $3 ) ) ); } 867 867 | ALIGNOF unary_expression // GCC, variable alignment 868 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild <Expression>( $2 ) ) ); }868 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild( $2 ) ) ); } 869 869 | ALIGNOF '(' type_no_function ')' // GCC, type alignment 870 870 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); } … … 901 901 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 902 902 | '(' VIRTUAL ')' cast_expression // CFA 903 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild <Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); }903 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild( $4 ), maybeMoveBuildType( nullptr ) ) ); } 904 904 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 905 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild <Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); }905 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); } 906 906 | '(' RETURN type_no_function ')' cast_expression // CFA 907 907 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; } … … 1092 1092 assignment_expression 1093 1093 | comma_expression ',' assignment_expression 1094 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild <Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }1094 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 1095 1095 ; 1096 1096 … … 1230 1230 constant_expression { $$ = $1; } 1231 1231 | constant_expression ELLIPSIS constant_expression // GCC, subrange 1232 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild <Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }1232 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 1233 1233 | subrange // CFA, subrange 1234 1234 ; … … 1732 1732 asm_operand: // GCC 1733 1733 string_literal '(' constant_expression ')' 1734 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild <Expression>( $3 ) ) ); }1734 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild( $3 ) ) ); } 1735 1735 | '[' IDENTIFIER ']' string_literal '(' constant_expression ')' 1736 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild <Expression>( $6 ) ) ); }1736 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild( $6 ) ) ); } 1737 1737 ; 1738 1738 … … 2843 2843 { $$ = $3; } 2844 2844 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2845 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild <Expression>( $3 ), maybeMoveBuild<Expression>( $5 ) ) ); }2845 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $3 ), maybeMoveBuild( $5 ) ) ); } 2846 2846 | '.' '[' push field_name_list pop ']' // CFA, tuple field selector 2847 2847 { $$ = $4; } … … 3231 3231 subrange: 3232 3232 constant_expression '~' constant_expression // CFA, integer subrange 3233 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild <Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }3233 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 3234 3234 ; 3235 3235 -
src/Parser/parserutility.h
ra29477f r702e826 10 10 // Created On : Sat May 16 15:31:46 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Feb 16 12:34:00 202313 // Update Count : 512 // Last Modified On : Thr Mar 9 12:16:00 2023 13 // Update Count : 6 14 14 // 15 15 … … 20 20 Expression *notZeroExpr( Expression *orig ); 21 21 22 template< typename T, typename U > 23 struct maybeBuild_t { 24 static T * doit( const U *orig ) { 25 if ( orig ) { 26 return orig->build(); 27 } else { 28 return 0; 29 } 30 } 31 }; 32 33 template< typename T, typename U > 34 static inline T * maybeBuild( const U *orig ) { 35 return maybeBuild_t<T,U>::doit(orig); 22 template< typename T > 23 static inline auto maybeBuild( const T *orig ) -> decltype(orig->build()) { 24 return (orig) ? orig->build() : nullptr; 36 25 } 37 26 38 template< typename T , typename U>39 static inline T * maybeMoveBuild( const U *orig) {40 T*ret = maybeBuild<T>(orig);27 template< typename T > 28 static inline auto maybeMoveBuild( const T *orig ) -> decltype(orig->build()) { 29 auto ret = maybeBuild<T>(orig); 41 30 delete orig; 42 31 return ret;
Note: See TracChangeset
for help on using the changeset viewer.