Changeset dbae916 for src


Ignore:
Timestamp:
Mar 14, 2023, 4:21:05 PM (14 months ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
1afd9ccb, 360bfe41, 6e6989c
Parents:
5217569 (diff), c19ca4b (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/AST/TranslationUnit.hpp

    r5217569 rdbae916  
    1010// Created On       : Tue Jun 11 15:30:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Mar 11 11:19:00 2022
    13 // Update Count     : 1
     12// Last Modified On : Thr Mar  9 16:41:00 2023
     13// Update Count     : 2
    1414//
    1515
     
    1717
    1818#include <map>
    19 #include <vector>
     19#include <list>
    2020
    2121#include "Fwd.hpp"
     
    2828
    2929        ptr<Type> sizeType;
    30         const FunctionDecl * dereference;
    31         const StructDecl * dtorStruct;
    32         const FunctionDecl * dtorDestroy;
     30        const FunctionDecl * dereference = nullptr;
     31        const StructDecl * dtorStruct = nullptr;
     32        const FunctionDecl * dtorDestroy = nullptr;
    3333};
    3434
  • src/Parser/DeclarationNode.cc

    r5217569 rdbae916  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 12:34:05 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb 25 12:15:40 2023
    13 // Update Count     : 1404
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Mar 14 11:56:00 2023
     13// Update Count     : 1406
    1414//
    1515
     
    4141
    4242// 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" };
     43const 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};
     48const char * DeclarationNode::complexTypeNames[] = {
     49        "_Complex", "NoComplexTypeNames", "_Imaginary"
     50}; // Imaginary unsupported => parse, but make invisible and print error message
     51const char * DeclarationNode::signednessNames[] = {
     52        "signed", "unsigned", "NoSignednessNames"
     53};
     54const char * DeclarationNode::lengthNames[] = {
     55        "short", "long", "long long", "NoLengthNames"
     56};
     57const char * DeclarationNode::builtinTypeNames[] = {
     58        "__builtin_va_list", "__auto_type", "zero_t", "one_t", "NoBuiltinTypeNames"
     59};
    5060
    5161UniqueName DeclarationNode::anonymous( "__anonymous" );
     
    7080        delete variable.initializer;
    7181
    72 //      delete type;
     82//      delete type;
    7383        delete bitfieldWidth;
    7484
     
    504514                        // src is the new item being added and has a single bit
    505515                } 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()] );
    508519                        src->storageClasses.reset();                            // FIX to preserve invariant of one basic storage specifier
    509520                } // if
     
    589600        } else {
    590601                switch ( dst->kind ) {
    591                   case TypeData::Unknown:
     602                case TypeData::Unknown:
    592603                        src->qualifiers |= dst->qualifiers;
    593604                        dst = src;
    594605                        src = nullptr;
    595606                        break;
    596                   case TypeData::Basic:
     607                case TypeData::Basic:
    597608                        dst->qualifiers |= src->qualifiers;
    598609                        if ( src->kind != TypeData::Unknown ) {
     
    622633                        } // if
    623634                        break;
    624                   default:
     635                default:
    625636                        switch ( src->kind ) {
    626                           case TypeData::Aggregate:
    627                           case TypeData::Enum:
     637                        case TypeData::Aggregate:
     638                        case TypeData::Enum:
    628639                                dst->base = new TypeData( TypeData::AggregateInst );
    629640                                dst->base->aggInst.aggregate = src;
     
    634645                                src = nullptr;
    635646                                break;
    636                           default:
     647                        default:
    637648                                if ( dst->forall ) {
    638649                                        dst->forall->appendList( src->forall );
     
    706717DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
    707718        if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {
    708                 if ( variable.assertions ) {
    709                         variable.assertions->appendList( assertions );
    710                 } else {
    711                         variable.assertions = assertions;
    712                 } // if
    713                 return this;
     719                if ( variable.assertions ) {
     720                        variable.assertions->appendList( assertions );
     721                } else {
     722                        variable.assertions = assertions;
     723                } // if
     724                return this;
    714725        } // if
    715726
    716727        assert( type );
    717728        switch ( type->kind ) {
    718           case TypeData::Symbolic:
     729        case TypeData::Symbolic:
    719730                if ( type->symbolic.assertions ) {
    720731                        type->symbolic.assertions->appendList( assertions );
     
    723734                } // if
    724735                break;
    725           default:
     736        default:
    726737                assert( false );
    727738        } // switch
     
    822833                if ( type ) {
    823834                        switch ( type->kind ) {
    824                           case TypeData::Aggregate:
    825                           case TypeData::Enum:
     835                        case TypeData::Aggregate:
     836                        case TypeData::Enum:
    826837                                p->type->base = new TypeData( TypeData::AggregateInst );
    827838                                p->type->base->aggInst.aggregate = type;
     
    832843                                break;
    833844
    834                           default:
     845                        default:
    835846                                p->type->base = type;
    836847                        } // switch
     
    854865
    855866DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) {
    856   if ( ! a ) return this;
     867        if ( ! a ) return this;
    857868        assert( a->type->kind == TypeData::Array );
    858869        TypeData * lastArray = findLast( a->type );
    859870        if ( type ) {
    860871                switch ( type->kind ) {
    861                   case TypeData::Aggregate:
    862                   case TypeData::Enum:
     872                case TypeData::Aggregate:
     873                case TypeData::Enum:
    863874                        lastArray->base = new TypeData( TypeData::AggregateInst );
    864875                        lastArray->base->aggInst.aggregate = type;
     
    868879                        lastArray->base->qualifiers |= type->qualifiers;
    869880                        break;
    870                   default:
     881                default:
    871882                        lastArray->base = type;
    872883                } // switch
     
    12041215                } // if
    12051216                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 );
    12071218                if ( isDelete ) {
    12081219                        DeclarationWithType * dwt = strict_dynamic_cast<DeclarationWithType *>( decl );
     
    12131224
    12141225        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 ) ) );
    12161227        }
    12171228
     
    12271238        } // if
    12281239        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 );
    12301241}
    12311242
     
    12341245
    12351246        switch ( type->kind ) {
    1236           case TypeData::Enum:
    1237           case TypeData::Aggregate: {
    1238                   ReferenceToType * ret = buildComAggInst( type, attributes, linkage );
    1239                   buildList( type->aggregate.actuals, ret->get_parameters() );
    1240                   return ret;
    1241           }
    1242           case TypeData::Symbolic: {
    1243                   TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false, attributes );
    1244                   buildList( type->symbolic.actuals, ret->get_parameters() );
    1245                   return ret;
    1246           }
    1247           default:
     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:
    12481259                Type * simpletypes = typebuild( type );
    12491260                simpletypes->get_attributes() = attributes;             // copy because member is const
  • src/Parser/ExpressionNode.cc

    r5217569 rdbae916  
    99// Author           : Peter A. Buhr
    1010// Created On       : Sat May 16 13:17:07 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb 11 14:49:00 2023
    13 // Update Count     : 1079
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Mar 14 12:00:00 2023
     13// Update Count     : 1082
    1414//
    1515
     
    7171        size_t end = str.length() - 1;
    7272        if ( posn == end ) { type = 3; return; }                        // no length after 'l' => long
    73        
     73
    7474        string::size_type next = posn + 1;                                      // advance to length
    7575        if ( str[next] == '3' ) {                                                       // 32
     
    122122                if ( str[i] == '1' ) v |= 1;
    123123                i += 1;
    124           if ( i == last - 1 || (str[i] != '0' && str[i] != '1') ) break;
     124                if ( i == last - 1 || (str[i] != '0' && str[i] != '1') ) break;
    125125                v <<= 1;
    126126        } // for
     
    157157        } // if
    158158
    159         string::size_type posn;
    160 
    161159        // 'u' can appear before or after length suffix
    162160        if ( str.find_last_of( "uU" ) != string::npos ) Unsigned = true;
     
    166164        } else {
    167165                // 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: ;
     166                string::size_type posn;
     167                // pointer value
     168                if ( posn = str.find_last_of( "pP" ); posn != string::npos ) {
     169                        ltype = 5; str.erase( posn, 1 );
     170                // size_t
     171                } else if ( posn = str.find_last_of( "zZ" ); posn != string::npos ) {
     172                        Unsigned = true; type = 2; ltype = 4; str.erase( posn, 1 );
     173                // signed char
     174                } else if ( posn = str.rfind( "hh" ); posn != string::npos ) {
     175                        type = 1; str.erase( posn, 2 );
     176                // signed char
     177                } else if ( posn = str.rfind( "HH" ); posn != string::npos ) {
     178                        type = 1; str.erase( posn, 2 );
     179                // short
     180                } else if ( posn = str.find_last_of( "hH" ); posn != string::npos ) {
     181                        type = 0; str.erase( posn, 1 );
     182                // int (natural number)
     183                } else if ( posn = str.find_last_of( "nN" ); posn != string::npos ) {
     184                        type = 2; str.erase( posn, 1 );
     185                } else if ( str.rfind( "ll" ) != string::npos || str.rfind( "LL" ) != string::npos ) {
     186                        type = 4;
     187                } else {
     188                        lnthSuffix( str, type, ltype );
     189                } // if
    191190        } // if
    192191
     
    196195        if ( type == 5 ) SemanticError( yylloc, "int128 constant is not supported on this target " + str );
    197196#endif // ! __SIZEOF_INT128__
    198        
     197
    199198        if ( str[0] == '0' ) {                                                          // radix character ?
    200199                dec = false;
     
    206205                                unsigned int len = str.length();
    207206                                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: ;
     207                                // hex digits < 2^64
     208                                if ( len > (2 + 16) ) {
     209                                        str2 = "0x" + str.substr( len - 16 );
     210                                        sscanf( (char *)str2.c_str(), "%llx", &v2 );
     211                                        str = str.substr( 0, len - 16 );
     212                                } // if
    213213                                sscanf( (char *)str.c_str(), "%llx", &v );
    214214#endif // __SIZEOF_INT128__
     
    309309//                      ret = new CastExpr( ret, new BasicType( Type::Qualifiers(), kind[Unsigned][type] ), false );
    310310                        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 ) );
     311                        ret = build_compoundLiteral(
     312                                DeclarationNode::newBasicType( DeclarationNode::Int128 )->addType( DeclarationNode::newSignedNess( DeclarationNode::Unsigned ) ),
     313                                new InitializerNode( (InitializerNode *)(new InitializerNode( new ExpressionNode( v2 == 0 ? ret2 : ret ) ))->set_last( new InitializerNode( new ExpressionNode( v2 == 0 ? ret : ret2 ) ) ), true ) );
    313314                } else {                                                                                // explicit length, (length_type)constant
    314315                        ret = new CastExpr( ret, new TypeInstType( Type::Qualifiers(), lnthsInt[Unsigned][ltype], false ), false );
     
    435436        Type * strtype;
    436437        switch ( str[0] ) {                                                                     // str has >= 2 characters, i.e, null string "" => safe to look at subscripts 0/1
    437           case 'u':
     438        case 'u':
    438439                if ( str[1] == '8' ) goto Default;                              // utf-8 characters => array of char
    439440                // lookup type of associated typedef
    440441                strtype = new TypeInstType( Type::Qualifiers( ), "char16_t", false );
    441442                break;
    442           case 'U':
     443        case 'U':
    443444                strtype = new TypeInstType( Type::Qualifiers( ), "char32_t", false );
    444445                break;
    445           case 'L':
     446        case 'L':
    446447                strtype = new TypeInstType( Type::Qualifiers( ), "wchar_t", false );
    447448                break;
    448           Default:                                                                                      // char default string type
    449           default:
     449        Default:                                                                                        // char default string type
     450        default:
    450451                strtype = new BasicType( Type::Qualifiers( ), BasicType::Char );
    451452        } // switch
     
    500501
    501502Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts ) {
    502         return make_field_name_fraction_constants( fieldName, maybeMoveBuild< Expression >( fracts ) );
     503        return make_field_name_fraction_constants( fieldName, maybeMoveBuild( fracts ) );
    503504} // build_field_name_fraction_constants
    504505
     
    510511
    511512QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name ) {
    512         Declaration * newDecl = maybeBuild< Declaration >(decl_node);
     513        Declaration * newDecl = maybeBuild(decl_node);
    513514        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) {
    514515                const Type * t = newDeclWithType->get_type();
     
    548549        if ( dynamic_cast< VoidType * >( targetType ) ) {
    549550                delete targetType;
    550                 return new CastExpr( maybeMoveBuild< Expression >(expr_node), false );
     551                return new CastExpr( maybeMoveBuild( expr_node ), false );
    551552        } else {
    552                 return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType, false );
     553                return new CastExpr( maybeMoveBuild( expr_node ), targetType, false );
    553554        } // if
    554555} // build_cast
    555556
    556557Expression * build_keyword_cast( AggregateDecl::Aggregate target, ExpressionNode * expr_node ) {
    557         return new KeywordCastExpr( maybeMoveBuild< Expression >(expr_node), target );
     558        return new KeywordCastExpr( maybeMoveBuild( expr_node ), target );
    558559}
    559560
    560561Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
    561         return new VirtualCastExpr( maybeMoveBuild< Expression >( expr_node ), maybeMoveBuildType( decl_node ) );
     562        return new VirtualCastExpr( maybeMoveBuild( expr_node ), maybeMoveBuildType( decl_node ) );
    562563} // build_virtual_cast
    563564
    564565Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ) {
    565         return new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
     566        return new UntypedMemberExpr( member, maybeMoveBuild( expr_node ) );
    566567} // build_fieldSel
    567568
     
    569570        UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
    570571        deref->location = expr_node->location;
    571         deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) );
     572        deref->get_args().push_back( maybeMoveBuild( expr_node ) );
    572573        UntypedMemberExpr * ret = new UntypedMemberExpr( member, deref );
    573574        return ret;
     
    581582
    582583Expression * 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 );
     584        return new LogicalExpr( notZeroExpr( maybeMoveBuild( expr_node1 ) ), notZeroExpr( maybeMoveBuild( expr_node2 ) ), kind );
    584585} // build_and_or
    585586
    586587Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) {
    587588        list< Expression * > args;
    588         args.push_back( maybeMoveBuild< Expression >(expr_node) );
     589        args.push_back( maybeMoveBuild( expr_node ) );
    589590        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    590591} // build_unary_val
    591592
    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_ptr
    597 
    598593Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    599594        list< Expression * > args;
    600         args.push_back( maybeMoveBuild< Expression >(expr_node1) );
    601         args.push_back( maybeMoveBuild< Expression >(expr_node2) );
     595        args.push_back( maybeMoveBuild( expr_node1 ) );
     596        args.push_back( maybeMoveBuild( expr_node2 ) );
    602597        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    603598} // build_binary_val
     
    605600Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    606601        list< Expression * > args;
    607         args.push_back( maybeMoveBuild< Expression >(expr_node1) );
    608         args.push_back( maybeMoveBuild< Expression >(expr_node2) );
     602        args.push_back( maybeMoveBuild( expr_node1 ) );
     603        args.push_back( maybeMoveBuild( expr_node2 ) );
    609604        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    610605} // build_binary_ptr
    611606
    612607Expression * 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) );
     608        return new ConditionalExpr( notZeroExpr( maybeMoveBuild( expr_node1 ) ), maybeMoveBuild( expr_node2 ), maybeMoveBuild( expr_node3 ) );
    614609} // build_cond
    615610
     
    623618        list< Expression * > args;
    624619        buildMoveList( expr_node, args );
    625         return new UntypedExpr( maybeMoveBuild< Expression >(function), args );
     620        return new UntypedExpr( maybeMoveBuild( function ), args );
    626621} // build_func
    627622
    628623Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ) {
    629         Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type
     624        Declaration * newDecl = maybeBuild( decl_node ); // compound literal type
    630625        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
    631                 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeMoveBuild< Initializer >(kids) );
     626                return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeMoveBuild( kids ) );
    632627        // these types do not have associated type information
    633628        } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl )  ) {
    634629                if ( newDeclStructDecl->has_body() ) {
    635                         return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl ), maybeMoveBuild< Initializer >(kids) );
     630                        return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl ), maybeMoveBuild( kids ) );
    636631                } else {
    637                         return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
     632                        return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeMoveBuild( kids ) );
    638633                } // if
    639634        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl )  ) {
    640635                if ( newDeclUnionDecl->has_body() ) {
    641                         return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl ), maybeMoveBuild< Initializer >(kids) );
     636                        return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl ), maybeMoveBuild( kids ) );
    642637                } else {
    643                         return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
     638                        return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeMoveBuild( kids ) );
    644639                } // if
    645640        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl )  ) {
    646641                if ( newDeclEnumDecl->has_body() ) {
    647                         return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl ), maybeMoveBuild< Initializer >(kids) );
     642                        return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl ), maybeMoveBuild( kids ) );
    648643                } else {
    649                         return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeMoveBuild< Initializer >(kids) );
     644                        return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeMoveBuild( kids ) );
    650645                } // if
    651646        } else {
     
    656651// Local Variables: //
    657652// tab-width: 4 //
    658 // mode: c++ //
    659 // compile-command: "make install" //
    660653// End: //
  • src/Parser/InitializerNode.cc

    r5217569 rdbae916  
    102102                if ( get_expression() ) {
    103103                        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 );
    105105                } // if
    106106        } // if
  • src/Parser/ParseNode.h

    r5217569 rdbae916  
    137137        bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr.get()); }
    138138
    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        }
    140145
    141146        std::unique_ptr<Expression> expr;                                       // public because of lifetime implications
     
    143148        bool extension = false;
    144149}; // 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                 } // if
    157         }
    158 };
    159150
    160151// Must harmonize with OperName.
     
    199190Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind );
    200191Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node );
    201 Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node );
    202192Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
    203193Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
     
    213203struct DeclarationNode : public ParseNode {
    214204        // 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        };
    218211        static const char * basicTypeNames[];
    219212        enum ComplexType { Complex, NoComplexType, Imaginary }; // Imaginary unsupported => parse, but make invisible and print error message
     
    401394
    402395struct ForCtrl {
    403         ForCtrl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :
    404                 init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {}
    405         ForCtrl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :
    406                 init( new StatementNode( decl ) ), condition( condition ), change( change ) {}
     396        ForCtrl( StatementNode * stmt, ExpressionNode * condition, ExpressionNode * change ) :
     397                init( stmt ), condition( condition ), change( change ) {}
    407398
    408399        StatementNode * init;
     
    451442        while ( cur ) {
    452443                try {
    453                         SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) );
     444                        SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild( cur ) );
    454445                        if ( result ) {
    455446                                result->location = cur->location;
  • src/Parser/StatementNode.cc

    r5217569 rdbae916  
    3838        DeclarationNode * agg = decl->extractAggregate();
    3939        if ( agg ) {
    40                 StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild< Declaration >( decl ) ) );
     40                StatementNode * nextStmt = new StatementNode( new DeclStmt( maybeBuild( decl ) ) );
    4141                set_next( nextStmt );
    4242                if ( decl->get_next() ) {
     
    5151                agg = decl;
    5252        } // if
    53         stmt.reset( new DeclStmt( maybeMoveBuild< Declaration >(agg) ) );
     53        stmt.reset( new DeclStmt( maybeMoveBuild( agg ) ) );
    5454} // StatementNode::StatementNode
    5555
     
    7373
    7474Statement * build_expr( ExpressionNode * ctl ) {
    75         Expression * e = maybeMoveBuild< Expression >( ctl );
     75        Expression * e = maybeMoveBuild( ctl );
    7676
    7777        if ( e ) return new ExprStmt( e );
     
    8787        if ( ctl->condition ) {
    8888                // compare the provided condition against 0
    89                 cond = notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) );
     89                cond = notZeroExpr( maybeMoveBuild( ctl->condition ) );
    9090        } else {
    9191                for ( Statement * stmt : init ) {
     
    134134        } // if
    135135        // 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 );
    137137} // build_switch
    138138
    139139Statement * build_case( ExpressionNode * ctl ) {
    140         return new CaseStmt( maybeMoveBuild< Expression >(ctl), {} ); // stmt starts empty and then added to
     140        return new CaseStmt( maybeMoveBuild( ctl ), {} ); // stmt starts empty and then added to
    141141} // build_case
    142142
     
    168168
    169169        // 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 );
    171171} // build_do_while
    172172
     
    176176
    177177        Expression * astcond = nullptr;                                         // maybe empty
    178         astcond = notZeroExpr( maybeMoveBuild< Expression >(forctl->condition) );
     178        astcond = notZeroExpr( maybeMoveBuild( forctl->condition ) );
    179179
    180180        Expression * astincr = nullptr;                                         // maybe empty
    181         astincr = maybeMoveBuild< Expression >(forctl->change);
     181        astincr = maybeMoveBuild( forctl->change );
    182182        delete forctl;
    183183
     
    199199Statement * build_branch( string * identifier, BranchStmt::Type kind ) {
    200200        Statement * ret = new BranchStmt( * identifier, kind );
    201         delete identifier;                                                                      // allocated by lexer
     201        delete identifier;                                                                      // allocated by lexer
    202202        return ret;
    203203} // build_branch
    204204
    205205Statement * build_computedgoto( ExpressionNode * ctl ) {
    206         return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto );
     206        return new BranchStmt( maybeMoveBuild( ctl ), BranchStmt::Goto );
    207207} // build_computedgoto
    208208
     
    236236        list< CatchStmt * > aststmt;
    237237        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_ ) );
    240240        return new TryStmt( tryBlock, aststmt, finallyBlock );
    241241} // build_try
     
    245245        buildMoveList< Statement, StatementNode >( body, aststmt );
    246246        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() );
    248248} // build_catch
    249249
     
    274274
    275275        WaitForStmt::Target target;
    276         target.function = maybeBuild<Expression>( targetExpr );
     276        target.function = maybeBuild( targetExpr );
    277277
    278278        ExpressionNode * next = dynamic_cast<ExpressionNode *>( targetExpr->get_next() );
     
    284284        node->clauses.push_back( WaitForStmt::Clause{
    285285                target,
    286                 maybeMoveBuild<Statement >( stmt ),
    287                 notZeroExpr( maybeMoveBuild<Expression>( when ) )
     286                maybeMoveBuild( stmt ),
     287                notZeroExpr( maybeMoveBuild( when ) )
    288288        });
    289289
     
    293293WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when, WaitForStmt * node ) {
    294294        WaitForStmt::Target target;
    295         target.function = maybeBuild<Expression>( targetExpr );
     295        target.function = maybeBuild( targetExpr );
    296296
    297297        ExpressionNode * next = dynamic_cast<ExpressionNode *>( targetExpr->get_next() );
     
    303303        node->clauses.insert( node->clauses.begin(), WaitForStmt::Clause{
    304304                std::move( target ),
    305                 maybeMoveBuild<Statement >( stmt ),
    306                 notZeroExpr( maybeMoveBuild<Expression>( when ) )
     305                maybeMoveBuild( stmt ),
     306                notZeroExpr( maybeMoveBuild( when ) )
    307307        });
    308308
     
    314314
    315315        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 ) );
    319319        } 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 ) );
    322322        } // if
    323323
     
    328328        auto node = new WaitForStmt();
    329329
    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 ) );
    336336
    337337        return node;
     
    341341        list< Expression * > e;
    342342        buildMoveList( exprs, e );
    343         Statement * s = maybeMoveBuild<Statement>( stmt );
     343        Statement * s = maybeMoveBuild( stmt );
    344344        return new DeclStmt( new WithStmt( e, s ) );
    345345} // build_with
     
    384384        list< Expression * > expList;
    385385        buildMoveList( exprs, expList );
    386         Statement * body = maybeMoveBuild<Statement>( stmt );
     386        Statement * body = maybeMoveBuild( stmt );
    387387        return new MutexStmt( body, expList );
    388388} // build_mutex
  • src/Parser/TypeData.cc

    r5217569 rdbae916  
    3333TypeData::TypeData( Kind k ) : location( yylloc ), kind( k ), base( nullptr ), forall( nullptr ) /*, PTR1( (void*)(0xdeadbeefdeadbeef)), PTR2( (void*)(0xdeadbeefdeadbeef) ) */ {
    3434        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:
    4744                array.dimension = nullptr;
    4845                array.isVarLen = false;
    4946                array.isStatic = false;
    5047                break;
    51           case Function:
    52                 // function = new Function_t;
     48        case Function:
    5349                function.params = nullptr;
    5450                function.idList = nullptr;
     
    5753                function.withExprs = nullptr;
    5854                break;
    59                 // Enum is an Aggregate, so both structures are initialized together.
    60           case Enum:
    61                 // enumeration = new Enumeration_t;
     55        case Enum:
    6256                enumeration.name = nullptr;
    6357                enumeration.constants = nullptr;
     
    6559                enumeration.anon = false;
    6660                break;
    67           case Aggregate:
    68                 // aggregate = new Aggregate_t;
     61        case Aggregate:
    6962                aggregate.kind = AggregateDecl::NoAggregate;
    7063                aggregate.name = nullptr;
     
    7770                aggregate.anon = false;
    7871                break;
    79           case AggregateInst:
    80                 // aggInst = new AggInst_t;
     72        case AggregateInst:
    8173                aggInst.aggregate = nullptr;
    8274                aggInst.params = nullptr;
    8375                aggInst.hoistType = false;
    8476                break;
    85           case Symbolic:
    86           case SymbolicInst:
    87                 // symbolic = new Symbolic_t;
     77        case Symbolic:
     78        case SymbolicInst:
    8879                symbolic.name = nullptr;
    8980                symbolic.params = nullptr;
     
    9182                symbolic.assertions = nullptr;
    9283                break;
    93           case Tuple:
    94                 // tuple = new Tuple_t;
     84        case Tuple:
    9585                tuple = nullptr;
    9686                break;
    97           case Typeof:
    98           case Basetypeof:
    99                 // typeexpr = new Typeof_t;
     87        case Typeof:
     88        case Basetypeof:
    10089                typeexpr = nullptr;
    10190                break;
    102           case Vtable:
    103                 break;
    104           case Builtin:
    105                 // builtin = new Builtin_t;
    106                 case Qualified:
     91        case Builtin:
     92        case Vtable:
     93                // No unique data to initialize.
     94                break;
     95        case Qualified:
    10796                qualified.parent = nullptr;
    10897                qualified.child = nullptr;
     
    117106
    118107        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:
    130118                delete array.dimension;
    131                 // delete array;
    132                 break;
    133           case Function:
     119                break;
     120        case Function:
    134121                delete function.params;
    135122                delete function.idList;
     
    137124                delete function.body;
    138125                delete function.withExprs;
    139                 // delete function;
    140                 break;
    141           case Aggregate:
     126                break;
     127        case Aggregate:
    142128                delete aggregate.name;
    143129                delete aggregate.params;
    144130                delete aggregate.actuals;
    145131                delete aggregate.fields;
    146                 // delete aggregate;
    147                 break;
    148           case AggregateInst:
     132                break;
     133        case AggregateInst:
    149134                delete aggInst.aggregate;
    150135                delete aggInst.params;
    151                 // delete aggInst;
    152                 break;
    153           case Enum:
     136                break;
     137        case Enum:
    154138                delete enumeration.name;
    155139                delete enumeration.constants;
    156                 // delete enumeration;
    157                 break;
    158           case Symbolic:
    159           case SymbolicInst:
     140                break;
     141        case Symbolic:
     142        case SymbolicInst:
    160143                delete symbolic.name;
    161144                delete symbolic.params;
    162145                delete symbolic.actuals;
    163146                delete symbolic.assertions;
    164                 // delete symbolic;
    165                 break;
    166           case Tuple:
    167                 // delete tuple->members;
     147                break;
     148        case Tuple:
    168149                delete tuple;
    169150                break;
    170           case Typeof:
    171           case Basetypeof:
    172                 // delete typeexpr->expr;
     151        case Typeof:
     152        case Basetypeof:
    173153                delete typeexpr;
    174154                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:
    181160                delete qualified.parent;
    182161                delete qualified.child;
     162                break;
    183163        } // switch
    184164} // TypeData::~TypeData
     
    192172
    193173        switch ( kind ) {
    194           case Unknown:
    195           case EnumConstant:
    196           case Pointer:
    197           case Reference:
    198           case GlobalScope:
     174        case Unknown:
     175        case EnumConstant:
     176        case Pointer:
     177        case Reference:
     178        case GlobalScope:
    199179                // nothing else to copy
    200180                break;
    201           case Basic:
     181        case Basic:
    202182                newtype->basictype = basictype;
    203183                newtype->complextype = complextype;
     
    205185                newtype->length = length;
    206186                break;
    207           case Array:
     187        case Array:
    208188                newtype->array.dimension = maybeClone( array.dimension );
    209189                newtype->array.isVarLen = array.isVarLen;
    210190                newtype->array.isStatic = array.isStatic;
    211191                break;
    212           case Function:
     192        case Function:
    213193                newtype->function.params = maybeClone( function.params );
    214194                newtype->function.idList = maybeClone( function.idList );
     
    217197                newtype->function.withExprs = maybeClone( function.withExprs );
    218198                break;
    219           case Aggregate:
     199        case Aggregate:
    220200                newtype->aggregate.kind = aggregate.kind;
    221201                newtype->aggregate.name = aggregate.name ? new string( *aggregate.name ) : nullptr;
     
    228208                newtype->aggregate.parent = aggregate.parent ? new string( *aggregate.parent ) : nullptr;
    229209                break;
    230           case AggregateInst:
     210        case AggregateInst:
    231211                newtype->aggInst.aggregate = maybeClone( aggInst.aggregate );
    232212                newtype->aggInst.params = maybeClone( aggInst.params );
    233213                newtype->aggInst.hoistType = aggInst.hoistType;
    234214                break;
    235           case Enum:
     215        case Enum:
    236216                newtype->enumeration.name = enumeration.name ? new string( *enumeration.name ) : nullptr;
    237217                newtype->enumeration.constants = maybeClone( enumeration.constants );
     
    239219                newtype->enumeration.anon = enumeration.anon;
    240220                break;
    241           case Symbolic:
    242           case SymbolicInst:
     221        case Symbolic:
     222        case SymbolicInst:
    243223                newtype->symbolic.name = symbolic.name ? new string( *symbolic.name ) : nullptr;
    244224                newtype->symbolic.params = maybeClone( symbolic.params );
     
    247227                newtype->symbolic.isTypedef = symbolic.isTypedef;
    248228                break;
    249           case Tuple:
     229        case Tuple:
    250230                newtype->tuple = maybeClone( tuple );
    251231                break;
    252           case Typeof:
    253           case Basetypeof:
     232        case Typeof:
     233        case Basetypeof:
    254234                newtype->typeexpr = maybeClone( typeexpr );
    255235                break;
    256           case Vtable:
    257                 break;
    258           case Builtin:
     236        case Vtable:
     237                break;
     238        case Builtin:
    259239                assert( builtintype == DeclarationNode::Zero || builtintype == DeclarationNode::One );
    260240                newtype->builtintype = builtintype;
    261241                break;
    262                 case Qualified:
     242        case Qualified:
    263243                newtype->qualified.parent = maybeClone( qualified.parent );
    264244                newtype->qualified.child = maybeClone( qualified.child );
     
    280260
    281261        switch ( kind ) {
    282           case Basic:
     262        case Basic:
    283263                if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessNames[ signedness ] << " ";
    284264                if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthNames[ length ] << " ";
     
    286266                if ( basictype != DeclarationNode::NoBasicType ) os << DeclarationNode::basicTypeNames[ basictype ] << " ";
    287267                break;
    288           case Pointer:
     268        case Pointer:
    289269                os << "pointer ";
    290270                if ( base ) {
     
    293273                } // if
    294274                break;
    295           case Reference:
     275        case Reference:
    296276                os << "reference ";
    297277                if ( base ) {
     
    300280                } // if
    301281                break;
    302           case Array:
     282        case Array:
    303283                if ( array.isStatic ) {
    304284                        os << "static ";
     
    316296                } // if
    317297                break;
    318           case Function:
     298        case Function:
    319299                os << "function" << endl;
    320300                if ( function.params ) {
     
    344324                } // if
    345325                break;
    346           case Aggregate:
     326        case Aggregate:
    347327                os << AggregateDecl::aggrString( aggregate.kind ) << ' ' << *aggregate.name << endl;
    348328                if ( aggregate.params ) {
     
    362342                } // if
    363343                break;
    364           case AggregateInst:
     344        case AggregateInst:
    365345                if ( aggInst.aggregate ) {
    366346                        os << "instance of " ;
     
    374354                } // if
    375355                break;
    376           case Enum:
     356        case Enum:
    377357                os << "enumeration " << *enumeration.name << endl;;
    378358                if ( enumeration.constants ) {
     
    388368                } // if
    389369                break;
    390           case EnumConstant:
     370        case EnumConstant:
    391371                os << "enumeration constant ";
    392372                break;
    393           case Symbolic:
     373        case Symbolic:
    394374                if ( symbolic.isTypedef ) {
    395375                        os << "typedef definition ";
     
    411391                } // if
    412392                break;
    413           case SymbolicInst:
     393        case SymbolicInst:
    414394                os << *symbolic.name;
    415395                if ( symbolic.actuals ) {
     
    419399                } // if
    420400                break;
    421           case Tuple:
     401        case Tuple:
    422402                os << "tuple ";
    423403                if ( tuple ) {
     
    426406                } // if
    427407                break;
    428           case Basetypeof:
     408        case Basetypeof:
    429409                os << "base-";
    430410                #if defined(__GNUC__) && __GNUC__ >= 7
     
    432412                #endif
    433413                // FALL THROUGH
    434           case Typeof:
     414        case Typeof:
    435415                os << "type-of expression ";
    436416                if ( typeexpr ) {
     
    438418                } // if
    439419                break;
    440           case Vtable:
     420        case Vtable:
    441421                os << "vtable";
    442422                break;
    443           case Builtin:
     423        case Builtin:
    444424                os << DeclarationNode::builtinTypeNames[builtintype];
    445425                break;
    446           case GlobalScope:
    447                 break;
    448           case Qualified:
     426        case GlobalScope:
     427                break;
     428        case Qualified:
    449429                qualified.parent->print( os );
    450430                os << ".";
    451431                qualified.child->print( os );
    452432                break;
    453           case Unknown:
     433        case Unknown:
    454434                os << "entity of unknown type ";
    455435                break;
    456           default:
     436        default:
    457437                os << "internal error: TypeData::print " << kind << endl;
    458438                assert( false );
     
    462442const std::string * TypeData::leafName() const {
    463443        switch ( kind ) {
    464           case Unknown:
    465           case Pointer:
    466           case Reference:
    467           case EnumConstant:
    468           case GlobalScope:
    469           case Array:
    470           case Basic:
    471           case Function:
    472           case AggregateInst:
    473           case Tuple:
    474           case Typeof:
    475           case Basetypeof:
    476           case Builtin:
    477           case Vtable:
     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:
    478458                assertf(false, "Tried to get leaf name from kind without a name: %d", kind);
    479459                break;
    480           case Aggregate:
     460        case Aggregate:
    481461                return aggregate.name;
    482           case Enum:
     462        case Enum:
    483463                return enumeration.name;
    484           case Symbolic:
    485           case SymbolicInst:
     464        case Symbolic:
     465        case SymbolicInst:
    486466                return symbolic.name;
    487           case Qualified:
     467        case Qualified:
    488468                return qualified.child->leafName();
    489469        } // switch
     
    530510        assert( td );
    531511        switch ( td->kind ) {
    532           case TypeData::Unknown:
     512        case TypeData::Unknown:
    533513                // fill in implicit int
    534514                return new BasicType( buildQualifiers( td ), BasicType::SignedInt );
    535           case TypeData::Basic:
     515        case TypeData::Basic:
    536516                return buildBasicType( td );
    537           case TypeData::Pointer:
     517        case TypeData::Pointer:
    538518                return buildPointer( td );
    539           case TypeData::Array:
     519        case TypeData::Array:
    540520                return buildArray( td );
    541           case TypeData::Reference:
     521        case TypeData::Reference:
    542522                return buildReference( td );
    543           case TypeData::Function:
     523        case TypeData::Function:
    544524                return buildFunction( td );
    545           case TypeData::AggregateInst:
     525        case TypeData::AggregateInst:
    546526                return buildAggInst( td );
    547           case TypeData::EnumConstant:
     527        case TypeData::EnumConstant:
    548528                return new EnumInstType( buildQualifiers( td ), "" );
    549           case TypeData::SymbolicInst:
     529        case TypeData::SymbolicInst:
    550530                return buildSymbolicInst( td );
    551           case TypeData::Tuple:
     531        case TypeData::Tuple:
    552532                return buildTuple( td );
    553           case TypeData::Typeof:
    554           case TypeData::Basetypeof:
     533        case TypeData::Typeof:
     534        case TypeData::Basetypeof:
    555535                return buildTypeof( td );
    556           case TypeData::Vtable:
     536        case TypeData::Vtable:
    557537                return buildVtable( td );
    558           case TypeData::Builtin:
     538        case TypeData::Builtin:
    559539                switch ( td->builtintype ) {
    560                   case DeclarationNode::Zero:
     540                case DeclarationNode::Zero:
    561541                        return new ZeroType( noQualifiers );
    562                   case DeclarationNode::One:
     542                case DeclarationNode::One:
    563543                        return new OneType( noQualifiers );
    564                   default:
     544                default:
    565545                        return new VarArgsType( buildQualifiers( td ) );
    566546                } // switch
    567           case TypeData::GlobalScope:
     547        case TypeData::GlobalScope:
    568548                return new GlobalScopeType();
    569           case TypeData::Qualified:
     549        case TypeData::Qualified:
    570550                return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) );
    571           case TypeData::Symbolic:
    572           case TypeData::Enum:
    573           case TypeData::Aggregate:
     551        case TypeData::Symbolic:
     552        case TypeData::Enum:
     553        case TypeData::Aggregate:
    574554                assert( false );
    575555        } // switch
     
    583563
    584564        switch ( td->kind ) {
    585           case TypeData::Aggregate:
     565        case TypeData::Aggregate:
    586566                if ( ! toplevel && td->aggregate.body ) {
    587567                        ret = td->clone();
    588568                } // if
    589569                break;
    590           case TypeData::Enum:
     570        case TypeData::Enum:
    591571                if ( ! toplevel && td->enumeration.body ) {
    592572                        ret = td->clone();
    593573                } // if
    594574                break;
    595           case TypeData::AggregateInst:
     575        case TypeData::AggregateInst:
    596576                if ( td->aggInst.aggregate ) {
    597577                        ret = typeextractAggregate( td->aggInst.aggregate, false );
    598578                } // if
    599579                break;
    600           default:
     580        default:
    601581                if ( td->base ) {
    602582                        ret = typeextractAggregate( td->base, false );
     
    620600
    621601        switch ( td->basictype ) {
    622           case DeclarationNode::Void:
     602        case DeclarationNode::Void:
    623603                if ( td->signedness != DeclarationNode::NoSignedness ) {
    624604                        genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );
     
    630610                break;
    631611
    632           case DeclarationNode::Bool:
     612        case DeclarationNode::Bool:
    633613                if ( td->signedness != DeclarationNode::NoSignedness ) {
    634614                        genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );
     
    641621                break;
    642622
    643           case DeclarationNode::Char:
     623        case DeclarationNode::Char:
    644624                // C11 Standard 6.2.5.15: The three types char, signed char, and unsigned char are collectively called the
    645625                // character types. The implementation shall define char to have the same range, representation, and behavior as
     
    654634                break;
    655635
    656           case DeclarationNode::Int:
     636        case DeclarationNode::Int:
    657637                static BasicType::Kind inttype[2][4] = {
    658638                        { BasicType::ShortSignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt, BasicType::SignedInt },
     
    660640                };
    661641
    662           Integral: ;
     642        Integral: ;
    663643                if ( td->signedness == DeclarationNode::NoSignedness ) {
    664644                        const_cast<TypeData *>(td)->signedness = DeclarationNode::Signed;
     
    667647                break;
    668648
    669           case DeclarationNode::Int128:
     649        case DeclarationNode::Int128:
    670650                ret = td->signedness == DeclarationNode::Unsigned ? BasicType::UnsignedInt128 : BasicType::SignedInt128;
    671651                if ( td->length != DeclarationNode::NoLength ) {
     
    674654                break;
    675655
    676           case DeclarationNode::Float:
    677           case DeclarationNode::Double:
    678           case DeclarationNode::LongDouble:                                     // not set until below
    679           case DeclarationNode::uuFloat80:
    680           case DeclarationNode::uuFloat128:
    681           case DeclarationNode::uFloat16:
    682           case DeclarationNode::uFloat32:
    683           case DeclarationNode::uFloat32x:
    684           case DeclarationNode::uFloat64:
    685           case DeclarationNode::uFloat64x:
    686           case DeclarationNode::uFloat128:
    687           case DeclarationNode::uFloat128x:
     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:
    688668                static BasicType::Kind floattype[2][12] = {
    689669                        { 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, },
     
    691671                };
    692672
    693           FloatingPoint: ;
     673        FloatingPoint: ;
    694674                if ( td->signedness != DeclarationNode::NoSignedness ) {
    695675                        genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );
     
    715695                break;
    716696
    717           case DeclarationNode::NoBasicType:
     697        case DeclarationNode::NoBasicType:
    718698                // No basic type in declaration => default double for Complex/Imaginary and int type for integral types
    719699                if ( td->complextype == DeclarationNode::Complex || td->complextype == DeclarationNode::Imaginary ) {
     
    724704                const_cast<TypeData *>(td)->basictype = DeclarationNode::Int;
    725705                goto Integral;
    726           default:
    727                 assertf( false, "unknown basic type" );
     706        default:
     707                assertf( false, "unknown basic type" );
    728708                return nullptr;
    729709        } // switch
     
    750730        ArrayType * at;
    751731        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 ),
    753733                                                        td->array.isVarLen, td->array.isStatic );
    754734        } else {
    755735                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 );
    757737        } // if
    758738        buildForall( td->forall, at->get_forall() );
     
    777757        AggregateDecl * at;
    778758        switch ( td->aggregate.kind ) {
    779           case AggregateDecl::Struct:
    780           case AggregateDecl::Coroutine:
    781           case AggregateDecl::Exception:
    782           case AggregateDecl::Generator:
    783           case AggregateDecl::Monitor:
    784           case AggregateDecl::Thread:
     759        case AggregateDecl::Struct:
     760        case AggregateDecl::Coroutine:
     761        case AggregateDecl::Exception:
     762        case AggregateDecl::Generator:
     763        case AggregateDecl::Monitor:
     764        case AggregateDecl::Thread:
    785765                at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes, linkage );
    786766                buildForall( td->aggregate.params, at->get_parameters() );
    787767                break;
    788           case AggregateDecl::Union:
     768        case AggregateDecl::Union:
    789769                at = new UnionDecl( *td->aggregate.name, attributes, linkage );
    790770                buildForall( td->aggregate.params, at->get_parameters() );
    791771                break;
    792           case AggregateDecl::Trait:
     772        case AggregateDecl::Trait:
    793773                at = new TraitDecl( *td->aggregate.name, attributes, linkage );
    794774                buildList( td->aggregate.params, at->get_parameters() );
    795775                break;
    796           default:
     776        default:
    797777                assert( false );
    798778        } // switch
     
    807787ReferenceToType * buildComAggInst( const TypeData * type, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) {
    808788        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:
    859831                assert( false );
    860832        } // switch
     
    869841        TypeData * type = td->aggInst.aggregate;
    870842        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:
    894864                assert( false );
    895865        } // switch
     
    931901                } else if ( cur->has_enumeratorValue() ) {
    932902                        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() ) ) );
    934904                } else if ( !cur->initializer ) {
    935905                        if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isInteger())) {
     
    985955
    986956                FunctionDecl * decl;
    987                 Statement * stmt = maybeBuild<Statement>( td->function.body );
     957                Statement * stmt = maybeBuild( td->function.body );
    988958                CompoundStmt * body = dynamic_cast< CompoundStmt * >( stmt );
    989959                decl = new FunctionDecl( name, scs, linkage, buildFunction( td ), body, attributes, funcSpec );
     
    1010980        if ( td->base ) {
    1011981                switch ( td->base->kind ) {
    1012                   case TypeData::Tuple:
     982                case TypeData::Tuple:
    1013983                        buildList( td->base->tuple, ft->returnVals );
    1014984                        break;
    1015                   default:
     985                default:
    1016986                        ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType * >( buildDecl( td->base, "", Type::StorageClasses(), nullptr, Type::FuncSpecifiers(), LinkageSpec::Cforall, nullptr ) ) );
    1017987                } // switch
  • src/Parser/TypeData.h

    r5217569 rdbae916  
    130130TypeofType * buildTypeof( const TypeData * );
    131131VTableType * 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 * >() );
     132Declaration * 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 * >() );
    134136FunctionType * buildFunction( const TypeData * );
    135137Declaration * addEnumBase( Declaration *, const TypeData * );
  • src/Parser/TypedefTable.cc

    r5217569 rdbae916  
    3131        static const char *kindName( int kind ) {
    3232                switch ( kind ) {
    33                   case IDENTIFIER: return "identifier";
    34                   case TYPEDIMname: return "typedim";
    35                   case TYPEDEFname: return "typedef";
    36                   case TYPEGENname: return "typegen";
    37                   default:
     33                case IDENTIFIER: return "identifier";
     34                case TYPEDIMname: return "typedim";
     35                case TYPEDEFname: return "typedef";
     36                case TYPEGENname: return "typegen";
     37                default:
    3838                        cerr << "Error: cfa-cpp internal error, invalid kind of identifier" << endl;
    3939                        abort();
  • src/Parser/parser.yy

    r5217569 rdbae916  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb 25 13:23:16 2023
    13 // Update Count     : 5989
     12// Last Modified On : Tue Mar 14 09:37:58 2023
     13// Update Count     : 5990
    1414//
    1515
     
    206206#define MISSING_HIGH "Missing high value for down-to range so index is uninitialized."
    207207
     208static ForCtrl * makeForCtrl(
     209                DeclarationNode * init,
     210                enum OperKinds compop,
     211                ExpressionNode * comp,
     212                ExpressionNode * inc ) {
     213        // Wrap both comp/inc if they are non-null.
     214        if ( comp ) comp = new ExpressionNode( build_binary_val(
     215                compop,
     216                new ExpressionNode( build_varref( new string( *init->name ) ) ),
     217                comp ) );
     218        if ( inc ) inc = new ExpressionNode( build_binary_val(
     219                // choose += or -= for upto/downto
     220                compop == OperKinds::LThan || compop == OperKinds::LEThan ? OperKinds::PlusAssn : OperKinds::MinusAssn,
     221                new ExpressionNode( build_varref( new string( *init->name ) ) ),
     222                inc ) );
     223        // The StatementNode call frees init->name, it must happen later.
     224        return new ForCtrl( new StatementNode( init ), comp, inc );
     225}
     226
    208227ForCtrl * forCtrl( DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    209228        if ( index->initializer ) {
     
    213232                SemanticError( yylloc, "Multiple loop indexes disallowed in for-loop declaration." );
    214233        } // if
    215         return new ForCtrl( index->addInitializer( new InitializerNode( start ) ),
    216                 // NULL comp/inc => leave blank
    217                 comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index->name ) ) ), comp ) ) : nullptr,
    218                 inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto
    219                                                         OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index->name ) ) ), inc ) ) : nullptr );
     234        DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) );
     235        return makeForCtrl( initDecl, compop, comp, inc );
    220236} // forCtrl
    221237
     
    223239        ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get());
    224240        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 ) ) );
     241                type = new ExpressionNode( new CastExpr( maybeMoveBuild( type ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
    226242        } // if
    227 //      type = new ExpressionNode( build_func( new ExpressionNode( build_varref( new string( "__for_control_index_constraints__" ) ) ), type ) );
    228         return new ForCtrl(
    229                 distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
    230                 // NULL comp/inc => leave blank
    231                 comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ) : nullptr,
    232                 inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto
    233                                                         OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) : nullptr );
     243        DeclarationNode * initDecl = distAttr(
     244                DeclarationNode::newTypeof( type, true ),
     245                DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) )
     246        );
     247        return makeForCtrl( initDecl, compop, comp, inc );
    234248} // forCtrl
    235249
     
    649663                { $$ = $2; }
    650664        | '(' compound_statement ')'                                            // GCC, lambda expression
    651                 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); }
     665                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild( $2 ) ) ) ); }
    652666        | type_name '.' identifier                                                      // CFA, nested type
    653667                { $$ = new ExpressionNode( build_qualified_expr( $1, build_varref( $3 ) ) ); }
     
    657671                {
    658672                        // add the missing control expression to the GenericExpr and return it
    659                         $5->control = maybeMoveBuild<Expression>( $3 );
     673                        $5->control = maybeMoveBuild( $3 );
    660674                        $$ = new ExpressionNode( $5 );
    661675                }
     
    693707                {
    694708                        // create a GenericExpr wrapper with one association pair
    695                         $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>( $3 ) } } );
     709                        $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild( $3 ) } } );
    696710                }
    697711        | DEFAULT ':' assignment_expression
    698                 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>( $3 ) } } ); }
     712                { $$ = new GenericExpr( nullptr, { { maybeMoveBuild( $3 ) } } ); }
    699713        ;
    700714
     
    751765                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
    752766        | postfix_expression ICR
    753                 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); }
     767                { $$ = new ExpressionNode( build_unary_val( OperKinds::IncrPost, $1 ) ); }
    754768        | postfix_expression DECR
    755                 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
     769                { $$ = new ExpressionNode( build_unary_val( OperKinds::DecrPost, $1 ) ); }
    756770        | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal
    757771                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
     
    793807        field_name
    794808        | FLOATING_DECIMALconstant field
    795                 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
     809                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild( $2 ) ) ); }
    796810        | FLOATING_DECIMALconstant '[' field_name_list ']'
    797811                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); }
    798812        | field_name '.' field
    799                 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
     813                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild( $3 ) ) ); }
    800814        | field_name '.' '[' field_name_list ']'
    801815                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    802816        | field_name ARROW field
    803                 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
     817                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild( $3 ) ) ); }
    804818        | field_name ARROW '[' field_name_list ']'
    805819                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
     
    843857                        switch ( $1 ) {
    844858                          case OperKinds::AddressOf:
    845                                 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) );
     859                                $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild( $2 ) ) );
    846860                                break;
    847861                          case OperKinds::PointTo:
     
    849863                                break;
    850864                          case OperKinds::And:
    851                                 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) ) );
     865                                $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild( $2 ) ) ) );
    852866                                break;
    853867                          default:
     
    858872                { $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); }
    859873        | ICR unary_expression
    860                 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Incr, $2 ) ); }
     874                { $$ = new ExpressionNode( build_unary_val( OperKinds::Incr, $2 ) ); }
    861875        | DECR unary_expression
    862                 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); }
     876                { $$ = new ExpressionNode( build_unary_val( OperKinds::Decr, $2 ) ); }
    863877        | SIZEOF unary_expression
    864                 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }
     878                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild( $2 ) ) ); }
    865879        | SIZEOF '(' type_no_function ')'
    866880                { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuildType( $3 ) ) ); }
    867881        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    868                 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }
     882                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild( $2 ) ) ); }
    869883        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    870884                { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); }
     
    901915                { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }
    902916        | '(' VIRTUAL ')' cast_expression                                       // CFA
    903                 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); }
     917                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild( $4 ), maybeMoveBuildType( nullptr ) ) ); }
    904918        | '(' VIRTUAL type_no_function ')' cast_expression      // CFA
    905                 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); }
     919                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); }
    906920        | '(' RETURN type_no_function ')' cast_expression       // CFA
    907921                { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; }
     
    10921106        assignment_expression
    10931107        | comma_expression ',' assignment_expression
    1094                 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
     1108                { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
    10951109        ;
    10961110
     
    12301244        constant_expression                                                     { $$ = $1; }
    12311245        | constant_expression ELLIPSIS constant_expression      // GCC, subrange
    1232                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
     1246                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
    12331247        | subrange                                                                                      // CFA, subrange
    12341248        ;
     
    12981312                { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ), $8 ) ); }
    12991313        | FOR '(' ')' statement                                                         %prec THEN // CFA => for ( ;; )
    1300                 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); }
     1314                { $$ = new StatementNode( build_for( new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound( $4 ) ) ); }
    13011315        | FOR '(' ')' statement ELSE statement                          // CFA
    13021316                {
    1303                         $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) );
     1317                        $$ = new StatementNode( build_for( new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound( $4 ) ) );
    13041318                        SemanticWarning( yylloc, Warning::SuperfluousElse );
    13051319                }
     
    13351349for_control_expression:
    13361350        ';' comma_expression_opt ';' comma_expression_opt
    1337                 { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); }
     1351                { $$ = new ForCtrl( nullptr, $2, $4 ); }
    13381352        | comma_expression ';' comma_expression_opt ';' comma_expression_opt
    1339                 { $$ = new ForCtrl( $1, $3, $5 ); }
     1353                {
     1354                        StatementNode * init = $1 ? new StatementNode( new ExprStmt( maybeMoveBuild( $1 ) ) ) : nullptr;
     1355                        $$ = new ForCtrl( init, $3, $5 );
     1356                }
    13401357        | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';'
    1341                 { $$ = new ForCtrl( $1, $2, $4 ); }
     1358                { $$ = new ForCtrl( new StatementNode( $1 ), $2, $4 ); }
    13421359
    13431360        | '@' ';' comma_expression                                                      // CFA, empty loop-index
    1344                 { $$ = new ForCtrl( (ExpressionNode *)nullptr, $3, nullptr ); }
     1361                { $$ = new ForCtrl( nullptr, $3, nullptr ); }
    13451362        | '@' ';' comma_expression ';' comma_expression         // CFA, empty loop-index
    1346                 { $$ = new ForCtrl( (ExpressionNode *)nullptr, $3, $5 ); }
     1363                { $$ = new ForCtrl( nullptr, $3, $5 ); }
    13471364
    13481365        | comma_expression                                                                      // CFA, anonymous loop-index
     
    17321749asm_operand:                                                                                    // GCC
    17331750        string_literal '(' constant_expression ')'
    1734                 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild<Expression>( $3 ) ) ); }
     1751                { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild( $3 ) ) ); }
    17351752        | '[' IDENTIFIER ']' string_literal '(' constant_expression ')'
    1736                 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild<Expression>( $6 ) ) ); }
     1753                { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild( $6 ) ) ); }
    17371754        ;
    17381755
     
    20382055        basic_type_specifier
    20392056        | sue_type_specifier
    2040                 {
    2041                         // printf( "sue_type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2042                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    2043                         //   printf( "\tattr %s\n", attr->name.c_str() );
    2044                         // } // for
    2045                 }
    20462057        | type_type_specifier
    20472058        ;
     
    23832394          '{' field_declaration_list_opt '}' type_parameters_opt
    23842395                {
    2385                         // printf( "aggregate_type1 %s\n", $3.str->c_str() );
    2386                         // if ( $2 )
    2387                         //      for ( Attribute * attr: reverseIterate( $2->attributes ) ) {
    2388                         //              printf( "copySpecifiers12 %s\n", attr->name.c_str() );
    2389                         //      } // for
    23902396                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
    2391                         // printf( "aggregate_type2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );
    2392                         // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {
    2393                         //      printf( "aggregate_type3 %s\n", attr->name.c_str() );
    2394                         // } // for
    23952397                }
    23962398        | aggregate_key attribute_list_opt TYPEDEFname          // unqualified type name
     
    24012403          '{' field_declaration_list_opt '}' type_parameters_opt
    24022404                {
    2403                         // printf( "AGG3\n" );
    24042405                        DeclarationNode::newFromTypedef( $3 );
    24052406                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     
    24122413          '{' field_declaration_list_opt '}' type_parameters_opt
    24132414                {
    2414                         // printf( "AGG4\n" );
    24152415                        DeclarationNode::newFromTypeGen( $3, nullptr );
    24162416                        $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 );
     
    24392439                        // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and
    24402440                        // delete newFromTypeGen.
    2441                         $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $3->type->symbolic.actuals, nullptr, false )->addQualifiers( $2 );
    2442                         $3->type->symbolic.name = nullptr;
    2443                         $3->type->symbolic.actuals = nullptr;
    2444                         delete $3;
     2441                        if ( $3->type->kind == TypeData::SymbolicInst && ! $3->type->symbolic.isTypedef ) {
     2442                                $$ = $3->addQualifiers( $2 );
     2443                        } else {
     2444                                $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $3->type->symbolic.actuals, nullptr, false )->addQualifiers( $2 );
     2445                                $3->type->symbolic.name = nullptr;                      // copied to $$
     2446                                $3->type->symbolic.actuals = nullptr;
     2447                                delete $3;
     2448                        }
    24452449                }
    24462450        ;
     
    27792783type_no_function:                                                                               // sizeof, alignof, cast (constructor)
    27802784        cfa_abstract_declarator_tuple                                           // CFA
    2781         | type_specifier
     2785        | type_specifier                                                                        // cannot be type_specifier_nobody, e.g., (struct S {}){} is a thing
    27822786        | type_specifier abstract_declarator
    27832787                { $$ = $2->addType( $1 ); }
     
    28432847                { $$ = $3; }
    28442848        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
    2845                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $3 ), maybeMoveBuild<Expression>( $5 ) ) ); }
     2849                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $3 ), maybeMoveBuild( $5 ) ) ); }
    28462850        | '.' '[' push field_name_list pop ']'                          // CFA, tuple field selector
    28472851                { $$ = $4; }
     
    32313235subrange:
    32323236        constant_expression '~' constant_expression                     // CFA, integer subrange
    3233                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }
     3237                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }
    32343238        ;
    32353239
  • src/Parser/parserutility.h

    r5217569 rdbae916  
    1010// Created On       : Sat May 16 15:31:46 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Feb 16 12:34:00 2023
    13 // Update Count     : 5
     12// Last Modified On : Thr Mar  9 12:16:00 2023
     13// Update Count     : 6
    1414//
    1515
     
    2020Expression *notZeroExpr( Expression *orig );
    2121
    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);
     22template< typename T >
     23static inline auto maybeBuild( const T *orig ) -> decltype(orig->build()) {
     24        return (orig) ? orig->build() : nullptr;
    3625}
    3726
    38 template< typename T, typename U >
    39 static inline T * maybeMoveBuild( const U *orig ) {
    40         T* ret = maybeBuild<T>(orig);
     27template< typename T >
     28static inline auto maybeMoveBuild( const T *orig ) -> decltype(orig->build()) {
     29        auto ret = maybeBuild<T>(orig);
    4130        delete orig;
    4231        return ret;
Note: See TracChangeset for help on using the changeset viewer.