Changes in / [0362d42:1ced874]


Ignore:
Location:
src
Files:
3 added
2 deleted
27 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r0362d42 r1ced874  
    260260};
    261261
     262template< typename T >
     263struct reverseIterate_t {
     264        T& ref;
     265
     266        reverseIterate_t( T & ref ) : ref(ref) {}
     267
     268        typedef typename T::reverse_iterator iterator;
     269        iterator begin() { return ref.rbegin(); }
     270        iterator end() { return ref.rend(); }
     271};
     272
     273template< typename T >
     274reverseIterate_t< T > reverseIterate( T & ref ) {
     275        return reverseIterate_t< T >( ref );
     276}
     277
    262278#endif // _UTILITY_H
    263279
  • src/GenPoly/Box.cc

    r0362d42 r1ced874  
    158158                class PolyGenericCalculator : public PolyMutator {
    159159                public:
     160                        typedef PolyMutator Parent;
     161                        using Parent::mutate;
     162
    160163                        template< typename DeclClass >
    161164                        DeclClass *handleDecl( DeclClass *decl, Type *type );
     
    16751678                DeclClass * PolyGenericCalculator::handleDecl( DeclClass *decl, Type *type ) {
    16761679                        beginTypeScope( type );
     1680                        // knownLayouts.beginScope();
     1681                        // knownOffsets.beginScope();
     1682
     1683                        DeclClass *ret = static_cast< DeclClass *>( Parent::mutate( decl ) );
     1684
     1685                        // knownOffsets.endScope();
     1686                        // knownLayouts.endScope();
     1687                        endTypeScope();
     1688                        return ret;
     1689                }
     1690
     1691                ObjectDecl * PolyGenericCalculator::mutate( ObjectDecl *objectDecl ) {
     1692                        return handleDecl( objectDecl, objectDecl->get_type() );
     1693                }
     1694
     1695                DeclarationWithType * PolyGenericCalculator::mutate( FunctionDecl *functionDecl ) {
    16771696                        knownLayouts.beginScope();
    16781697                        knownOffsets.beginScope();
    16791698
    1680                         DeclClass *ret = static_cast< DeclClass *>( Mutator::mutate( decl ) );
    1681 
     1699                        DeclarationWithType * decl = handleDecl( functionDecl, functionDecl->get_functionType() );
    16821700                        knownOffsets.endScope();
    16831701                        knownLayouts.endScope();
    1684                         endTypeScope();
    1685                         return ret;
    1686                 }
    1687 
    1688                 ObjectDecl * PolyGenericCalculator::mutate( ObjectDecl *objectDecl ) {
    1689                         return handleDecl( objectDecl, objectDecl->get_type() );
    1690                 }
    1691 
    1692                 DeclarationWithType * PolyGenericCalculator::mutate( FunctionDecl *functionDecl ) {
    1693                         return handleDecl( functionDecl, functionDecl->get_functionType() );
     1702                        return decl;
    16941703                }
    16951704
     
    17001709                TypeDecl * PolyGenericCalculator::mutate( TypeDecl *typeDecl ) {
    17011710                        scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
    1702                         return Mutator::mutate( typeDecl );
     1711                        return Parent::mutate( typeDecl );
    17031712                }
    17041713
     
    17061715                        beginTypeScope( pointerType );
    17071716
    1708                         Type *ret = Mutator::mutate( pointerType );
     1717                        Type *ret = Parent::mutate( pointerType );
    17091718
    17101719                        endTypeScope();
     
    17241733                        }
    17251734
    1726                         Type *ret = Mutator::mutate( funcType );
     1735                        Type *ret = Parent::mutate( funcType );
    17271736
    17281737                        endTypeScope();
     
    17451754                                }
    17461755                        }
    1747                         return Mutator::mutate( declStmt );
     1756                        return Parent::mutate( declStmt );
    17481757                }
    17491758
     
    17871796                Expression *PolyGenericCalculator::mutate( MemberExpr *memberExpr ) {
    17881797                        // mutate, exiting early if no longer MemberExpr
    1789                         Expression *expr = Mutator::mutate( memberExpr );
     1798                        Expression *expr = Parent::mutate( memberExpr );
    17901799                        memberExpr = dynamic_cast< MemberExpr* >( expr );
    17911800                        if ( ! memberExpr ) return expr;
     
    19721981                Expression *PolyGenericCalculator::mutate( OffsetofExpr *offsetofExpr ) {
    19731982                        // mutate, exiting early if no longer OffsetofExpr
    1974                         Expression *expr = Mutator::mutate( offsetofExpr );
     1983                        Expression *expr = Parent::mutate( offsetofExpr );
    19751984                        offsetofExpr = dynamic_cast< OffsetofExpr* >( expr );
    19761985                        if ( ! offsetofExpr ) return expr;
  • src/GenPoly/PolyMutator.cc

    r0362d42 r1ced874  
    3030
    3131        void PolyMutator::mutateStatementList( std::list< Statement* > &statements ) {
     32                SemanticError errors;
     33
    3234                for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
    3335                        if ( ! stmtsToAddAfter.empty() ) {
    3436                                statements.splice( i, stmtsToAddAfter );
    3537                        } // if
    36                         *i = (*i)->acceptMutator( *this );
     38                        try {
     39                                *i = (*i)->acceptMutator( *this );
     40                        } catch ( SemanticError &e ) {
     41                                errors.append( e );
     42                        } // try
    3743                        if ( ! stmtsToAdd.empty() ) {
    3844                                statements.splice( i, stmtsToAdd );
     
    4248                        statements.splice( statements.end(), stmtsToAddAfter );
    4349                } // if
     50                if ( ! errors.isEmpty() ) {
     51                        throw errors;
     52                }
    4453        }
    4554
  • src/GenPoly/PolyMutator.h

    r0362d42 r1ced874  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // PolyMutator.h -- 
     7// PolyMutator.h --
    88//
    99// Author           : Richard C. Bilson
     
    3030        class PolyMutator : public Mutator {
    3131          public:
     32                typedef Mutator Parent;
     33                using Parent::mutate;
     34
    3235                PolyMutator();
    3336
     
    4245                virtual Statement* mutate(ExprStmt *catchStmt);
    4346                virtual Statement* mutate(ReturnStmt *catchStmt);
    44  
     47
    4548                virtual Expression* mutate(UntypedExpr *untypedExpr);
    4649
     
    5457                Statement* mutateStatement( Statement *stmt );
    5558                Expression* mutateExpression( Expression *expr );
    56  
     59
    5760                TyVarMap scopeTyVars;
    5861                TypeSubstitution *env;
     
    6063                std::list< Statement* > stmtsToAddAfter;
    6164        };
    62 } // namespace 
     65} // namespace
    6366
    6467#endif // _POLYMUTATOR_H
  • src/InitTweak/FixInit.cc

    r0362d42 r1ced874  
    200200                        ObjectDecl * thisParam = 0;
    201201                        bool isCtor = false; // true if current function is a constructor
     202                        StructDecl * structDecl = 0;
    202203                };
    203204
     
    744745                        ValueGuard< ObjectDecl * > oldThisParam( thisParam );
    745746                        ValueGuard< bool > oldIsCtor( isCtor );
     747                        ValueGuard< StructDecl * > oldStructDecl( structDecl );
    746748
    747749                        // need to start with fresh sets
     
    758760                                StructInstType * structType = dynamic_cast< StructInstType * >( ptrType->get_base() );
    759761                                if ( structType ) {
    760                                         StructDecl * structDecl = structType->get_baseStruct();
     762                                        structDecl = structType->get_baseStruct();
    761763                                        for ( Declaration * member : structDecl->get_members() ) {
    762764                                                if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) {
     
    775777                        std::set_difference( usedUninit.begin(), usedUninit.end(), unhandled.begin(), unhandled.end(), std::inserter( diff, diff.begin() ) );
    776778                        for ( DeclarationWithType * member : diff ) {
    777                                 emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", member ", member->get_name(), " used before being constructed" );
     779                                emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", field ", member->get_name(), " used before being constructed" );
    778780                        }
    779781
     
    781783                                // need to explicitly re-add function parameters in order to resolve copy constructors
    782784                                enterScope();
    783                                 // maybeAccept( function->get_functionType(), *this );
    784                                 for ( DeclarationWithType * member : unhandled ) {
    785                                         // insert and resolve default/copy constructor call for each member that's unhandled
     785                                maybeAccept( function->get_functionType(), *this );
     786
     787                                // need to iterate through members in reverse in order for
     788                                // ctor/dtor statements to come out in the right order
     789                                for ( Declaration * member : reverseIterate( structDecl->get_members() ) ) {
     790                                        DeclarationWithType * field = dynamic_cast< DeclarationWithType * >( member );
     791                                        // skip non-DWT members
     792                                        if ( ! field ) continue;
     793                                        // skip handled members
     794                                        if ( ! unhandled.count( field ) ) continue;
     795
     796                                        // insert and resolve default/copy constructor call for each field that's unhandled
    786797                                        std::list< Statement * > stmt;
    787798                                        UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
    788799                                        deref->get_args().push_back( new VariableExpr( thisParam ) );
    789                                         InitExpander srcParam( (Initializer *)NULL ); // xxx - if copy ctor, need to pass appropriate argument - second param of this function dot member
    790                                         SymTab::genImplicitCall( srcParam, new MemberExpr( member, deref ), function->get_name(), back_inserter( stmt ), member, isCtor );
     800
     801                                        Expression * arg2 = 0;
     802                                        if ( isCopyConstructor( function ) ) {
     803                                                // if copy ctor, need to pass second-param-of-this-function.field
     804                                                std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters();
     805                                                assert( params.size() == 2 );
     806                                                arg2 = new MemberExpr( field, new VariableExpr( params.back() ) );
     807                                        }
     808                                        InitExpander srcParam( arg2 );
     809                                        SymTab::genImplicitCall( srcParam, new MemberExpr( field, deref ), function->get_name(), back_inserter( stmt ), field, isCtor );
    791810
    792811                                        assert( stmt.size() <= 1 );
     
    796815                                                MutatingResolver resolver( *this );
    797816                                                try {
    798                                                         // xxx - these should be in field declaration order
    799817                                                        callStmt->acceptMutator( resolver );
    800818                                                        if ( isCtor ) {
     
    805823                                                        }
    806824                                                } catch ( SemanticError & error ) {
    807                                                         emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", member ", member->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed",  " and no ", isCtor ? "default constructor" : "destructor", " found" );
     825                                                        emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", field ", field->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed",  " and no ", isCtor ? "default constructor" : "destructor", " found" );
    808826                                                }
    809827                                        }
     
    832850                                        handleFirstParam( firstParam );
    833851                                }
    834                         } else if ( fname == "?=?" && isIntrinsicCallExpr( appExpr ) ) {
    835                                 // forgive use of intrinsic assignment to construct, since instrinsic constructors
    836                                 // codegen as assignment anyway.
    837                                 assert( appExpr->get_args().size() == 2 );
    838                                 handleFirstParam( appExpr->get_args().front() );
    839852                        }
    840853
  • src/InitTweak/GenInit.cc

    r0362d42 r1ced874  
    2525#include "SynTree/Mutator.h"
    2626#include "SymTab/Autogen.h"
     27#include "SymTab/Mangler.h"
    2728#include "GenPoly/PolyMutator.h"
    2829#include "GenPoly/DeclMutator.h"
     30#include "GenPoly/ScopedSet.h"
    2931
    3032namespace InitTweak {
     
    5557        class CtorDtor : public GenPoly::PolyMutator {
    5658          public:
     59                typedef GenPoly::PolyMutator Parent;
     60                using Parent::mutate;
    5761                /// create constructor and destructor statements for object declarations.
    5862                /// the actual call statements will be added in after the resolver has run
     
    6569                // should not traverse into any of these declarations to find objects
    6670                // that need to be constructed or destructed
    67                 virtual Declaration* mutate( StructDecl *aggregateDecl ) { return aggregateDecl; }
     71                virtual Declaration* mutate( StructDecl *aggregateDecl );
    6872                virtual Declaration* mutate( UnionDecl *aggregateDecl ) { return aggregateDecl; }
    6973                virtual Declaration* mutate( EnumDecl *aggregateDecl ) { return aggregateDecl; }
     
    7478                virtual Type * mutate( FunctionType *funcType ) { return funcType; }
    7579
    76           protected:
     80                virtual CompoundStmt * mutate( CompoundStmt * compoundStmt );
     81
     82          private:
     83                // set of mangled type names for which a constructor or destructor exists in the current scope.
     84                // these types require a ConstructorInit node to be generated, anything else is a POD type and thus
     85                // should not have a ConstructorInit generated.
     86
     87                bool isManaged( ObjectDecl * objDecl ) const ; // determine if object is managed
     88                void handleDWT( DeclarationWithType * dwt ); // add type to managed if ctor/dtor
     89                GenPoly::ScopedSet< std::string > managedTypes;
     90                bool inFunction = false;
    7791        };
    7892
     
    142156
    143157        DeclarationWithType* ReturnFixer::mutate( FunctionDecl *functionDecl ) {
    144                 std::list<DeclarationWithType*> oldReturnVals = returnVals;
    145                 std::string oldFuncName = funcName;
     158                ValueGuard< std::list<DeclarationWithType*> > oldReturnVals( returnVals );
     159                ValueGuard< std::string > oldFuncName( funcName );
    146160
    147161                FunctionType * type = functionDecl->get_functionType();
     
    149163                funcName = functionDecl->get_name();
    150164                DeclarationWithType * decl = Mutator::mutate( functionDecl );
    151                 returnVals = oldReturnVals;
    152                 funcName = oldFuncName;
    153165                return decl;
    154166        }
     
    197209
    198210        DeclarationWithType * HoistArrayDimension::mutate( FunctionDecl *functionDecl ) {
    199                 bool oldInFunc = inFunction;
     211                ValueGuard< bool > oldInFunc( inFunction );
    200212                inFunction = true;
    201213                DeclarationWithType * decl = Parent::mutate( functionDecl );
    202                 inFunction = oldInFunc;
    203214                return decl;
    204215        }
     
    209220        }
    210221
     222        bool CtorDtor::isManaged( ObjectDecl * objDecl ) const {
     223                Type * type = objDecl->get_type();
     224                while ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
     225                        type = at->get_base();
     226                }
     227                return managedTypes.find( SymTab::Mangler::mangle( type ) ) != managedTypes.end();
     228        }
     229
     230        void CtorDtor::handleDWT( DeclarationWithType * dwt ) {
     231                // if this function is a user-defined constructor or destructor, mark down the type as "managed"
     232                if ( ! LinkageSpec::isOverridable( dwt->get_linkage() ) && isCtorDtor( dwt->get_name() ) ) {
     233                        std::list< DeclarationWithType * > & params = GenPoly::getFunctionType( dwt->get_type() )->get_parameters();
     234                        assert( ! params.empty() );
     235                        PointerType * type = safe_dynamic_cast< PointerType * >( params.front()->get_type() );
     236                        managedTypes.insert( SymTab::Mangler::mangle( type->get_base() ) );
     237                }
     238        }
     239
    211240        DeclarationWithType * CtorDtor::mutate( ObjectDecl * objDecl ) {
    212                 // hands off if designated, if @=, or if extern
    213                 if ( tryConstruct( objDecl ) ) {
     241                handleDWT( objDecl );
     242                // hands off if @=, extern, builtin, etc.
     243                // if global but initializer is not constexpr, always try to construct, since this is not legal C
     244                if ( ( tryConstruct( objDecl ) && isManaged( objDecl ) ) || (! inFunction && ! isConstExpr( objDecl->get_init() ) ) ) {
     245                        // constructed objects cannot be designated
     246                        if ( isDesignated( objDecl->get_init() ) ) throw SemanticError( "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.", objDecl );
     247                        // constructed objects should not have initializers nested too deeply
     248                        if ( ! checkInitDepth( objDecl ) ) throw SemanticError( "Managed object's initializer is too deep ", objDecl );
     249
    214250                        // call into genImplicitCall from Autogen.h to generate calls to ctor/dtor
    215251                        // for each constructable object
     
    241277                        }
    242278                }
    243                 return Mutator::mutate( objDecl );
     279                return Parent::mutate( objDecl );
    244280        }
    245281
    246282        DeclarationWithType * CtorDtor::mutate( FunctionDecl *functionDecl ) {
     283                ValueGuard< bool > oldInFunc = inFunction;
     284                inFunction = true;
     285
     286                handleDWT( functionDecl );
     287
     288                managedTypes.beginScope();
     289                // go through assertions and recursively add seen ctor/dtors
     290                for ( TypeDecl * tyDecl : functionDecl->get_functionType()->get_forall() ) {
     291                        for ( DeclarationWithType *& assertion : tyDecl->get_assertions() ) {
     292                                assertion = assertion->acceptMutator( *this );
     293                        }
     294                }
    247295                // parameters should not be constructed and destructed, so don't mutate FunctionType
    248296                mutateAll( functionDecl->get_oldDecls(), *this );
    249297                functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
     298
     299                managedTypes.endScope();
    250300                return functionDecl;
    251301        }
     302
     303        Declaration* CtorDtor::mutate( StructDecl *aggregateDecl ) {
     304                // don't construct members, but need to take note if there is a managed member,
     305                // because that means that this type is also managed
     306                for ( Declaration * member : aggregateDecl->get_members() ) {
     307                        if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) {
     308                                if ( isManaged( field ) ) {
     309                                        managedTypes.insert( SymTab::Mangler::mangle( aggregateDecl ) );
     310                                        break;
     311                                }
     312                        }
     313                }
     314                return aggregateDecl;
     315        }
     316
     317        CompoundStmt * CtorDtor::mutate( CompoundStmt * compoundStmt ) {
     318                managedTypes.beginScope();
     319                CompoundStmt * stmt = Parent::mutate( compoundStmt );
     320                managedTypes.endScope();
     321                return stmt;
     322        }
     323
    252324} // namespace InitTweak
    253325
  • src/InitTweak/InitTweak.cc

    r0362d42 r1ced874  
    77#include "SynTree/Attribute.h"
    88#include "GenPoly/GenPoly.h"
     9#include "ResolvExpr/typeops.h"
    910
    1011namespace InitTweak {
     
    2223                };
    2324
     25                class InitDepthChecker : public Visitor {
     26                public:
     27                        bool depthOkay = true;
     28                        Type * type;
     29                        int curDepth = 0, maxDepth = 0;
     30                        InitDepthChecker( Type * type ) : type( type ) {
     31                                Type * t = type;
     32                                while ( ArrayType * at = dynamic_cast< ArrayType * >( t ) ) {
     33                                        maxDepth++;
     34                                        t = at->get_base();
     35                                }
     36                                maxDepth++;
     37                        }
     38                        virtual void visit( ListInit * listInit ) {
     39                                curDepth++;
     40                                if ( curDepth > maxDepth ) depthOkay = false;
     41                                Visitor::visit( listInit );
     42                                curDepth--;
     43                        }
     44                };
     45
    2446                class InitFlattener : public Visitor {
    2547                        public:
     
    5274                maybeAccept( init, finder );
    5375                return finder.hasDesignations;
     76        }
     77
     78        bool checkInitDepth( ObjectDecl * objDecl ) {
     79                InitDepthChecker checker( objDecl->get_type() );
     80                maybeAccept( objDecl->get_init(), checker );
     81                return checker.depthOkay;
    5482        }
    5583
     
    231259                return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) &&
    232260                        (objDecl->get_init() == NULL ||
    233                                 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) &&
    234                         ! isDesignated( objDecl->get_init() )
     261                                ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() ))
    235262                        && objDecl->get_storageClass() != DeclarationNode::Extern;
    236263        }
     
    390417                virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; }
    391418                virtual void visit( UntypedExpr *untypedExpr ) { isConstExpr = false; }
    392                 virtual void visit( NameExpr *nameExpr ) { isConstExpr = false; }
    393                 virtual void visit( CastExpr *castExpr ) { isConstExpr = false; }
     419                virtual void visit( NameExpr *nameExpr ) {
     420                        // xxx - temporary hack, because 0 and 1 really should be constexprs, even though they technically aren't in Cforall today
     421                        if ( nameExpr->get_name() != "0" && nameExpr->get_name() != "1" ) isConstExpr = false;
     422                }
     423                // virtual void visit( CastExpr *castExpr ) { isConstExpr = false; }
     424                virtual void visit( AddressExpr *addressExpr ) {
     425                        // address of a variable or member expression is constexpr
     426                        Expression * arg = addressExpr->get_arg();
     427                        if ( ! dynamic_cast< NameExpr * >( arg) && ! dynamic_cast< VariableExpr * >( arg ) && ! dynamic_cast< MemberExpr * >( arg ) && ! dynamic_cast< UntypedMemberExpr * >( arg ) ) isConstExpr = false;
     428                }
    394429                virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; }
    395430                virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; }
    396431                virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; }
    397432                virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; }
    398                 virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ }
    399433                // these might be okay?
    400434                // virtual void visit( SizeofExpr *sizeofExpr );
     
    439473        bool isDestructor( const std::string & str ) { return str == "^?{}"; }
    440474        bool isCtorDtor( const std::string & str ) { return isConstructor( str ) || isDestructor( str ); }
     475
     476        FunctionDecl * isCopyConstructor( Declaration * decl ) {
     477                FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl );
     478                if ( ! function ) return 0;
     479                if ( ! isConstructor( function->get_name() ) ) return 0;
     480                FunctionType * ftype = function->get_functionType();
     481                if ( ftype->get_parameters().size() != 2 ) return 0;
     482
     483                Type * t1 = ftype->get_parameters().front()->get_type();
     484                Type * t2 = ftype->get_parameters().back()->get_type();
     485                PointerType * ptrType = dynamic_cast< PointerType * > ( t1 );
     486                assert( ptrType );
     487
     488                if ( ResolvExpr::typesCompatible( ptrType->get_base(), t2, SymTab::Indexer() ) ) {
     489                        return function;
     490                } else {
     491                        return 0;
     492                }
     493        }
    441494}
  • src/InitTweak/InitTweak.h

    r0362d42 r1ced874  
    3030        bool isCtorDtor( const std::string & );
    3131
     32        FunctionDecl * isCopyConstructor( Declaration * decl );
     33
    3234        /// transform Initializer into an argument list that can be passed to a call expression
    3335        std::list< Expression * > makeInitList( Initializer * init );
     
    3840        /// True if the Initializer contains designations
    3941        bool isDesignated( Initializer * init );
     42
     43        /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its
     44        /// type, where the depth of its type is the number of nested ArrayTypes + 1
     45        bool checkInitDepth( ObjectDecl * objDecl );
    4046
    4147  /// Non-Null if expr is a call expression whose target function is intrinsic
  • src/Parser/DeclarationNode.cc

    r0362d42 r1ced874  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 28 22:12:44 2016
    13 // Update Count     : 278
     12// Last Modified On : Mon Aug 29 22:30:56 2016
     13// Update Count     : 327
    1414//
    1515
     
    4242
    4343extern LinkageSpec::Spec linkage;                                               // defined in parser.yy
     44
     45DeclarationNode::DeclarationNode()
     46                : type( 0 )
     47                , storageClass( NoStorageClass )
     48                , isInline( false )
     49                , isNoreturn( false )
     50                , bitfieldWidth( 0 )
     51                , initializer( 0 )
     52                , hasEllipsis( false )
     53                , linkage( ::linkage )
     54                , extension( false )
     55                , error() {
     56        attr.expr = nullptr;
     57        attr.type = nullptr;
     58
     59        variable.tyClass = DeclarationNode::Type;
     60        variable.assertions = nullptr;
     61}
     62
     63DeclarationNode::~DeclarationNode() {
     64        delete attr.expr;
     65        delete attr.type;
     66        delete type;
     67        delete bitfieldWidth;
     68        delete initializer;
     69}
    4470
    4571DeclarationNode *DeclarationNode::clone() const {
     
    5581        newnode->set_next( maybeClone( get_next() ) );
    5682        newnode->linkage = linkage;
     83
     84        newnode->variable.assertions = maybeClone( variable.assertions );
     85        newnode->variable.name = variable.name;
     86        newnode->variable.tyClass = variable.tyClass;
     87
     88        newnode->attr.expr = maybeClone( attr.expr );
     89        newnode->attr.type = maybeClone( attr.type );
    5790        return newnode;
    5891} // DeclarationNode::clone
    59 
    60 DeclarationNode::DeclarationNode()
    61         : type( 0 )
    62         , storageClass( NoStorageClass )
    63         , isInline( false )
    64         , isNoreturn( false )
    65         , bitfieldWidth( 0 )
    66         , initializer( 0 )
    67         , hasEllipsis( false )
    68         , linkage( ::linkage )
    69         , extension( false )
    70         , error() {
    71 }
    72 
    73 DeclarationNode::~DeclarationNode() {
    74         delete type;
    75         delete bitfieldWidth;
    76         delete initializer;
    77 }
    7892
    7993bool DeclarationNode::get_hasEllipsis() const {
     
    129143
    130144        newnode->type = new TypeData( TypeData::Function );
    131         newnode->type->function->params = param;
    132         newnode->type->function->newStyle = newStyle;
    133         newnode->type->function->body = body;
     145        newnode->type->function.params = param;
     146        newnode->type->function.newStyle = newStyle;
     147        newnode->type->function.body = body;
    134148        typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
    135149
    136150        if ( body ) {
    137                 newnode->type->function->hasBody = true;
     151                newnode->type->function.hasBody = true;
    138152        } // if
    139153
     
    175189        DeclarationNode *newnode = new DeclarationNode;
    176190        newnode->type = new TypeData( TypeData::Basic );
    177         newnode->type->basic->typeSpec.push_back( bt );
     191        newnode->type->basic.typeSpec.push_back( bt );
    178192        return newnode;
    179193} // DeclarationNode::newBasicType
     
    182196        DeclarationNode *newnode = new DeclarationNode;
    183197        newnode->type = new TypeData( TypeData::Basic );
    184         newnode->type->basic->modifiers.push_back( mod );
     198        newnode->type->basic.modifiers.push_back( mod );
    185199        return newnode;
    186200} // DeclarationNode::newModifier
    187201
    188 DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {
    189         DeclarationNode *newnode = new DeclarationNode;
    190         newnode->type = new TypeData( TypeData::Builtin );
    191         newnode->type->builtin->type = bt;
    192         return newnode;
    193 } // DeclarationNode::newBuiltinType
    194 
    195202DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) {
    196203        DeclarationNode *newnode = new DeclarationNode;
    197204        newnode->type = new TypeData( TypeData::SymbolicInst );
    198         newnode->type->symbolic->name = assign_strptr( name );
    199         newnode->type->symbolic->isTypedef = true;
    200         newnode->type->symbolic->params = 0;
     205        newnode->type->symbolic.name = assign_strptr( name );
     206        newnode->type->symbolic.isTypedef = true;
     207        newnode->type->symbolic.params = 0;
    201208        return newnode;
    202209} // DeclarationNode::newFromTypedef
     
    205212        DeclarationNode *newnode = new DeclarationNode;
    206213        newnode->type = new TypeData( TypeData::Aggregate );
    207         newnode->type->aggregate->kind = kind;
    208         newnode->type->aggregate->name = assign_strptr( name );
    209         if ( newnode->type->aggregate->name == "" ) {           // anonymous aggregate ?
    210                 newnode->type->aggregate->name = anonymous.newName();
    211         } // if
    212         newnode->type->aggregate->actuals = actuals;
    213         newnode->type->aggregate->fields = fields;
    214         newnode->type->aggregate->body = body;
     214        newnode->type->aggregate.kind = kind;
     215        newnode->type->aggregate.name = assign_strptr( name );
     216        if ( newnode->type->aggregate.name == "" ) {            // anonymous aggregate ?
     217                newnode->type->aggregate.name = anonymous.newName();
     218        } // if
     219        newnode->type->aggregate.actuals = actuals;
     220        newnode->type->aggregate.fields = fields;
     221        newnode->type->aggregate.body = body;
    215222        return newnode;
    216223} // DeclarationNode::newAggregate
     
    220227        newnode->name = assign_strptr( name );
    221228        newnode->type = new TypeData( TypeData::Enum );
    222         newnode->type->enumeration->name = newnode->name;
    223         if ( newnode->type->enumeration->name == "" ) {         // anonymous enumeration ?
    224                 newnode->type->enumeration->name = DeclarationNode::anonymous.newName();
    225         } // if
    226         newnode->type->enumeration->constants = constants;
     229        newnode->type->enumeration.name = newnode->name;
     230        if ( newnode->type->enumeration.name == "" ) {          // anonymous enumeration ?
     231                newnode->type->enumeration.name = DeclarationNode::anonymous.newName();
     232        } // if
     233        newnode->type->enumeration.constants = constants;
    227234        return newnode;
    228235} // DeclarationNode::newEnum
     
    245252        DeclarationNode *newnode = new DeclarationNode;
    246253        newnode->type = new TypeData( TypeData::SymbolicInst );
    247         newnode->type->symbolic->name = assign_strptr( name );
    248         newnode->type->symbolic->isTypedef = false;
    249         newnode->type->symbolic->actuals = params;
     254        newnode->type->symbolic.name = assign_strptr( name );
     255        newnode->type->symbolic.isTypedef = false;
     256        newnode->type->symbolic.actuals = params;
    250257        return newnode;
    251258} // DeclarationNode::newFromTypeGen
     
    255262        newnode->name = assign_strptr( name );
    256263        newnode->type = new TypeData( TypeData::Variable );
    257         newnode->type->variable->tyClass = tc;
    258         newnode->type->variable->name = newnode->name;
     264        newnode->variable.tyClass = tc;
     265        newnode->variable.name = newnode->name;
    259266        return newnode;
    260267} // DeclarationNode::newTypeParam
     
    263270        DeclarationNode *newnode = new DeclarationNode;
    264271        newnode->type = new TypeData( TypeData::Aggregate );
    265         newnode->type->aggregate->kind = Trait;
    266         newnode->type->aggregate->params = params;
    267         newnode->type->aggregate->fields = asserts;
    268         newnode->type->aggregate->name = assign_strptr( name );
     272        newnode->type->aggregate.kind = Trait;
     273        newnode->type->aggregate.params = params;
     274        newnode->type->aggregate.fields = asserts;
     275        newnode->type->aggregate.name = assign_strptr( name );
    269276        return newnode;
    270277} // DeclarationNode::newTrait
     
    273280        DeclarationNode *newnode = new DeclarationNode;
    274281        newnode->type = new TypeData( TypeData::AggregateInst );
    275         newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate );
    276         newnode->type->aggInst->aggregate->aggregate->kind = Trait;
    277         newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name );
    278         newnode->type->aggInst->params = params;
     282        newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
     283        newnode->type->aggInst.aggregate->aggregate.kind = Trait;
     284        newnode->type->aggInst.aggregate->aggregate.name = assign_strptr( name );
     285        newnode->type->aggInst.params = params;
    279286        return newnode;
    280287} // DeclarationNode::newTraitUse
     
    284291        newnode->name = assign_strptr( name );
    285292        newnode->type = new TypeData( TypeData::Symbolic );
    286         newnode->type->symbolic->isTypedef = false;
    287         newnode->type->symbolic->params = typeParams;
    288         newnode->type->symbolic->name = newnode->name;
     293        newnode->type->symbolic.isTypedef = false;
     294        newnode->type->symbolic.params = typeParams;
     295        newnode->type->symbolic.name = newnode->name;
    289296        return newnode;
    290297} // DeclarationNode::newTypeDecl
     
    299306        DeclarationNode *newnode = new DeclarationNode;
    300307        newnode->type = new TypeData( TypeData::Array );
    301         newnode->type->array->dimension = size;
    302         newnode->type->array->isStatic = isStatic;
    303         if ( newnode->type->array->dimension == 0 || newnode->type->array->dimension->isExpressionType<ConstantExpr *>() ) {
    304                 newnode->type->array->isVarLen = false;
     308        newnode->type->array.dimension = size;
     309        newnode->type->array.isStatic = isStatic;
     310        if ( newnode->type->array.dimension == 0 || newnode->type->array.dimension->isExpressionType<ConstantExpr *>() ) {
     311                newnode->type->array.isVarLen = false;
    305312        } else {
    306                 newnode->type->array->isVarLen = true;
     313                newnode->type->array.isVarLen = true;
    307314        } // if
    308315        return newnode->addQualifiers( qualifiers );
     
    312319        DeclarationNode *newnode = new DeclarationNode;
    313320        newnode->type = new TypeData( TypeData::Array );
    314         newnode->type->array->dimension = 0;
    315         newnode->type->array->isStatic = false;
    316         newnode->type->array->isVarLen = true;
     321        newnode->type->array.dimension = 0;
     322        newnode->type->array.isStatic = false;
     323        newnode->type->array.isVarLen = true;
    317324        return newnode->addQualifiers( qualifiers );
    318325}
     
    327334        DeclarationNode *newnode = new DeclarationNode;
    328335        newnode->type = new TypeData( TypeData::Tuple );
    329         newnode->type->tuple->members = members;
     336        newnode->type->tuple = members;
    330337        return newnode;
    331338}
     
    334341        DeclarationNode *newnode = new DeclarationNode;
    335342        newnode->type = new TypeData( TypeData::Typeof );
    336         newnode->type->typeexpr->expr = expr;
    337         return newnode;
    338 }
     343        newnode->type->typeexpr = expr;
     344        return newnode;
     345}
     346
     347DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {
     348        DeclarationNode *newnode = new DeclarationNode;
     349        newnode->type = new TypeData( TypeData::Builtin );
     350        newnode->builtin = bt;
     351        return newnode;
     352} // DeclarationNode::newBuiltinType
    339353
    340354DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) {
    341355        DeclarationNode *newnode = new DeclarationNode;
    342356        newnode->type = new TypeData( TypeData::Attr );
    343         newnode->type->attr->name = assign_strptr( name );
    344         newnode->type->attr->expr = expr;
     357        newnode->attr.name = assign_strptr( name );
     358        newnode->attr.expr = expr;
    345359        return newnode;
    346360}
     
    349363        DeclarationNode *newnode = new DeclarationNode;
    350364        newnode->type = new TypeData( TypeData::Attr );
    351         newnode->type->attr->name = assign_strptr( name );
    352         newnode->type->attr->type = type;
     365        newnode->attr.name = assign_strptr( name );
     366        newnode->attr.type = type;
    353367        return newnode;
    354368}
     
    407421                                } else {
    408422                                        if ( type->kind == TypeData::Aggregate ) {
    409                                                 type->aggregate->params = q->type->forall;
     423                                                type->aggregate.params = q->type->forall;
    410424                                                // change implicit typedef from TYPEDEFname to TYPEGENname
    411                                                 typedefTable.changeKind( type->aggregate->name, TypedefTable::TG );
     425                                                typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
    412426                                        } else {
    413427                                                type->forall = q->type->forall;
     
    457471                                if ( src->kind != TypeData::Unknown ) {
    458472                                        assert( src->kind == TypeData::Basic );
    459                                         dst->basic->modifiers.splice( dst->basic->modifiers.end(), src->basic->modifiers );
    460                                         dst->basic->typeSpec.splice( dst->basic->typeSpec.end(), src->basic->typeSpec );
     473                                        dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers );
     474                                        dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec );
    461475                                } // if
    462476                                break;
     
    466480                                  case TypeData::Enum:
    467481                                        dst->base = new TypeData( TypeData::AggregateInst );
    468                                         dst->base->aggInst->aggregate = src;
     482                                        dst->base->aggInst.aggregate = src;
    469483                                        if ( src->kind == TypeData::Aggregate ) {
    470                                                 dst->base->aggInst->params = maybeClone( src->aggregate->actuals );
     484                                                dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    471485                                        } // if
    472486                                        dst->base->qualifiers |= src->qualifiers;
     
    495509                                if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) {
    496510                                        type = new TypeData( TypeData::AggregateInst );
    497                                         type->aggInst->aggregate = o->type;
     511                                        type->aggInst.aggregate = o->type;
    498512                                        if ( o->type->kind == TypeData::Aggregate ) {
    499                                                 type->aggInst->params = maybeClone( o->type->aggregate->actuals );
     513                                                type->aggInst.params = maybeClone( o->type->aggregate.actuals );
    500514                                        } // if
    501515                                        type->qualifiers |= o->type->qualifiers;
     
    523537DeclarationNode *DeclarationNode::addTypedef() {
    524538        TypeData *newtype = new TypeData( TypeData::Symbolic );
    525         newtype->symbolic->params = 0;
    526         newtype->symbolic->isTypedef = true;
    527         newtype->symbolic->name = name;
     539        newtype->symbolic.params = 0;
     540        newtype->symbolic.isTypedef = true;
     541        newtype->symbolic.name = name;
    528542        newtype->base = type;
    529543        type = newtype;
     
    535549        switch ( type->kind ) {
    536550          case TypeData::Symbolic:
    537                 if ( type->symbolic->assertions ) {
    538                         type->symbolic->assertions->appendList( assertions );
     551                if ( type->symbolic.assertions ) {
     552                        type->symbolic.assertions->appendList( assertions );
    539553                } else {
    540                         type->symbolic->assertions = assertions;
     554                        type->symbolic.assertions = assertions;
    541555                } // if
    542556                break;
    543557          case TypeData::Variable:
    544                 if ( type->variable->assertions ) {
    545                         type->variable->assertions->appendList( assertions );
     558                if ( variable.assertions ) {
     559                        variable.assertions->appendList( assertions );
    546560                } else {
    547                         type->variable->assertions = assertions;
     561                        variable.assertions = assertions;
    548562                } // if
    549563                break;
     
    574588        assert( type );
    575589        assert( type->kind == TypeData::Function );
    576         assert( type->function->body == 0 );
    577         type->function->body = body;
    578         type->function->hasBody = true;
     590        assert( type->function.body == 0 );
     591        type->function.body = body;
     592        type->function.hasBody = true;
    579593        return this;
    580594}
     
    583597        assert( type );
    584598        assert( type->kind == TypeData::Function );
    585         assert( type->function->oldDeclList == 0 );
    586         type->function->oldDeclList = list;
     599        assert( type->function.oldDeclList == 0 );
     600        type->function.oldDeclList = list;
    587601        return this;
    588602}
     
    630644                          case TypeData::Enum:
    631645                                p->type->base = new TypeData( TypeData::AggregateInst );
    632                                 p->type->base->aggInst->aggregate = type;
     646                                p->type->base->aggInst.aggregate = type;
    633647                                if ( type->kind == TypeData::Aggregate ) {
    634                                         p->type->base->aggInst->params = maybeClone( type->aggregate->actuals );
     648                                        p->type->base->aggInst.params = maybeClone( type->aggregate.actuals );
    635649                                } // if
    636650                                p->type->base->qualifiers |= type->qualifiers;
     
    667681                          case TypeData::Enum:
    668682                                lastArray->base = new TypeData( TypeData::AggregateInst );
    669                                 lastArray->base->aggInst->aggregate = type;
     683                                lastArray->base->aggInst.aggregate = type;
    670684                                if ( type->kind == TypeData::Aggregate ) {
    671                                         lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals );
     685                                        lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals );
    672686                                } // if
    673687                                lastArray->base->qualifiers |= type->qualifiers;
     
    687701DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) {
    688702        TypeData *ftype = new TypeData( TypeData::Function );
    689         ftype->function->params = params;
     703        ftype->function.params = params;
    690704        setBase( type, ftype );
    691705        return this;
     
    697711                        type->base = addIdListToType( type->base, ids );
    698712                } else {
    699                         type->function->idList = ids;
     713                        type->function.idList = ids;
    700714                } // if
    701715                return type;
    702716        } else {
    703717                TypeData *newtype = new TypeData( TypeData::Function );
    704                 newtype->function->idList = ids;
     718                newtype->function.idList = ids;
    705719                return newtype;
    706720        } // if
     
    727741        if ( newnode->type->kind == TypeData::AggregateInst ) {
    728742                // don't duplicate members
    729                 if ( newnode->type->aggInst->aggregate->kind == TypeData::Enum ) {
    730                         delete newnode->type->aggInst->aggregate->enumeration->constants;
    731                         newnode->type->aggInst->aggregate->enumeration->constants = 0;
     743                if ( newnode->type->aggInst.aggregate->kind == TypeData::Enum ) {
     744                        delete newnode->type->aggInst.aggregate->enumeration.constants;
     745                        newnode->type->aggInst.aggregate->enumeration.constants = 0;
    732746                } else {
    733                         assert( newnode->type->aggInst->aggregate->kind == TypeData::Aggregate );
    734                         delete newnode->type->aggInst->aggregate->aggregate->fields;
    735                         newnode->type->aggInst->aggregate->aggregate->fields = 0;
     747                        assert( newnode->type->aggInst.aggregate->kind == TypeData::Aggregate );
     748                        delete newnode->type->aggInst.aggregate->aggregate.fields;
     749                        newnode->type->aggInst.aggregate->aggregate.fields = 0;
    736750                } // if
    737751        } // if
     
    753767                        if ( newType->kind == TypeData::AggregateInst ) {
    754768                                // don't duplicate members
    755                                 if ( newType->aggInst->aggregate->kind == TypeData::Enum ) {
    756                                         delete newType->aggInst->aggregate->enumeration->constants;
    757                                         newType->aggInst->aggregate->enumeration->constants = 0;
     769                                if ( newType->aggInst.aggregate->kind == TypeData::Enum ) {
     770                                        delete newType->aggInst.aggregate->enumeration.constants;
     771                                        newType->aggInst.aggregate->enumeration.constants = 0;
    758772                                } else {
    759                                         assert( newType->aggInst->aggregate->kind == TypeData::Aggregate );
    760                                         delete newType->aggInst->aggregate->aggregate->fields;
    761                                         newType->aggInst->aggregate->aggregate->fields = 0;
     773                                        assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
     774                                        delete newType->aggInst.aggregate->aggregate.fields;
     775                                        newType->aggInst.aggregate->aggregate.fields = 0;
    762776                                } // if
    763777                        } // if
     
    896910        if ( ! error.empty() ) throw SemanticError( error, this );
    897911        if ( type ) {
    898                 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     912                if ( type->kind == TypeData::Variable ) {
     913                        static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
     914                        TypeDecl * ret = new TypeDecl( variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ variable.tyClass ] );
     915                        buildList( variable.assertions, ret->get_assertions() );
     916                        return ret;
     917                } else {
     918                        return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     919                } // if
    899920        } // if
    900921        if ( ! isInline && ! isNoreturn ) {
     
    909930        switch ( type->kind ) {
    910931          case TypeData::Enum:
    911                 return new EnumInstType( buildQualifiers( type ), type->enumeration->name );
     932                return new EnumInstType( buildQualifiers( type ), type->enumeration.name );
    912933          case TypeData::Aggregate: {
    913934                  ReferenceToType *ret;
    914                   switch ( type->aggregate->kind ) {
     935                  switch ( type->aggregate.kind ) {
    915936                        case DeclarationNode::Struct:
    916                           ret = new StructInstType( buildQualifiers( type ), type->aggregate->name );
     937                          ret = new StructInstType( buildQualifiers( type ), type->aggregate.name );
    917938                          break;
    918939                        case DeclarationNode::Union:
    919                           ret = new UnionInstType( buildQualifiers( type ), type->aggregate->name );
     940                          ret = new UnionInstType( buildQualifiers( type ), type->aggregate.name );
    920941                          break;
    921942                        case DeclarationNode::Trait:
    922                           ret = new TraitInstType( buildQualifiers( type ), type->aggregate->name );
     943                          ret = new TraitInstType( buildQualifiers( type ), type->aggregate.name );
    923944                          break;
    924945                        default:
    925946                          assert( false );
    926947                  } // switch
    927                   buildList( type->aggregate->actuals, ret->get_parameters() );
     948                  buildList( type->aggregate.actuals, ret->get_parameters() );
    928949                  return ret;
    929950          }
    930951          case TypeData::Symbolic: {
    931                   TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic->name, false );
    932                   buildList( type->symbolic->actuals, ret->get_parameters() );
     952                  TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic.name, false );
     953                  buildList( type->symbolic.actuals, ret->get_parameters() );
     954                  return ret;
     955          }
     956          case TypeData::Attr: {
     957                  assert( type->kind == TypeData::Attr );
     958                  // assert( type->attr );
     959                  AttrType * ret;
     960                  if ( attr.expr ) {
     961                          ret = new AttrType( buildQualifiers( type ), attr.name, attr.expr->build() );
     962                  } else {
     963                          assert( attr.type );
     964                          ret = new AttrType( buildQualifiers( type ), attr.name, attr.type->buildType() );
     965                  } // if
    933966                  return ret;
    934967          }
  • src/Parser/ParseNode.h

    r0362d42 r1ced874  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 28 21:14:51 2016
    13 // Update Count     : 575
     12// Last Modified On : Mon Aug 29 21:45:43 2016
     13// Update Count     : 583
    1414//
    1515
     
    290290        // bool buildFuncSpecifier( StorageClass key ) const;
    291291
     292        struct Enumeration_t {
     293                std::string name;
     294                DeclarationNode * constants;
     295        };
     296        Enumeration_t enumeration;
     297
     298        struct Variable_t {
     299                DeclarationNode::TypeClass tyClass;
     300                std::string name;
     301                DeclarationNode * assertions;
     302        };
     303        Variable_t variable;
     304
     305        struct Attr_t {
     306                std::string name;
     307                ExpressionNode * expr;
     308                DeclarationNode * type;
     309        };
     310        Attr_t attr;
     311
     312        BuiltinType builtin;
     313
    292314        TypeData *type;
    293315        std::string name;
  • src/Parser/TypeData.cc

    r0362d42 r1ced874  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 28 18:28:58 2016
    13 // Update Count     : 223
     12// Last Modified On : Mon Aug 29 22:31:53 2016
     13// Update Count     : 277
    1414//
    1515
     
    3333                break;
    3434          case Basic:
    35                 basic = new Basic_t;
     35                // basic = new Basic_t;
    3636                break;
    3737          case Array:
    38                 array = new Array_t;
    39                 array->dimension = 0;
    40                 array->isVarLen = false;
    41                 array->isStatic = false;
     38                // array = new Array_t;
     39                array.dimension = 0;
     40                array.isVarLen = false;
     41                array.isStatic = false;
    4242                break;
    4343          case Function:
    44                 function = new Function_t;
    45                 function->params = 0;
    46                 function->idList = 0;
    47                 function->oldDeclList = 0;
    48                 function->body = 0;
    49                 function->hasBody = false;
    50                 function->newStyle = false;
     44                // function = new Function_t;
     45                function.params = 0;
     46                function.idList = 0;
     47                function.oldDeclList = 0;
     48                function.body = 0;
     49                function.hasBody = false;
     50                function.newStyle = false;
    5151                break;
    5252          case Aggregate:
    53                 aggregate = new Aggregate_t;
    54                 aggregate->params = 0;
    55                 aggregate->actuals = 0;
    56                 aggregate->fields = 0;
     53                // aggregate = new Aggregate_t;
     54                aggregate.params = 0;
     55                aggregate.actuals = 0;
     56                aggregate.fields = 0;
    5757                break;
    5858          case AggregateInst:
    59                 aggInst = new AggInst_t;
    60                 aggInst->aggregate = 0;
    61                 aggInst->params = 0;
     59                // aggInst = new AggInst_t;
     60                aggInst.aggregate = 0;
     61                aggInst.params = 0;
    6262                break;
    6363          case Enum:
    64                 enumeration = new Enumeration_t;
    65                 enumeration->constants = 0;
     64                // enumeration = new Enumeration_t;
     65                enumeration.constants = 0;
    6666                break;
    6767          case Symbolic:
    6868          case SymbolicInst:
    69                 symbolic = new Symbolic_t;
    70                 symbolic->params = 0;
    71                 symbolic->actuals = 0;
    72                 symbolic->assertions = 0;
     69                // symbolic = new Symbolic_t;
     70                symbolic.params = 0;
     71                symbolic.actuals = 0;
     72                symbolic.assertions = 0;
    7373                break;
    7474          case Variable:
    75                 variable = new Variable_t;
    76                 variable->tyClass = DeclarationNode::Type;
    77                 variable->assertions = 0;
     75                // variable = new Variable_t;
     76                // variable.tyClass = DeclarationNode::Type;
     77                // variable.assertions = 0;
    7878                break;
    7979          case Tuple:
    80                 tuple = new Tuple_t;
    81                 tuple->members = 0;
     80                // tuple = new Tuple_t;
     81                tuple = nullptr;
    8282                break;
    8383          case Typeof:
    84                 typeexpr = new Typeof_t;
    85                 typeexpr->expr = 0;
     84                // typeexpr = new Typeof_t;
     85                typeexpr = nullptr;
     86                break;
     87          case Attr:
     88                // attr = new Attr_t;
     89                // attr.expr = nullptr;
     90                // attr.type = nullptr;
    8691                break;
    8792          case Builtin:
    88                 builtin = new Builtin_t;
    89                 break;
    90           case Attr:
    91                 attr = new Attr_t;
    92                 attr->expr = 0;
    93                 attr->type = 0;
     93                // builtin = new Builtin_t;
    9494                break;
    9595        } // switch
     
    107107                break;
    108108          case Basic:
    109                 delete basic;
     109                // delete basic;
    110110                break;
    111111          case Array:
    112                 delete array->dimension;
    113                 delete array;
     112                delete array.dimension;
     113                // delete array;
    114114                break;
    115115          case Function:
    116                 delete function->params;
    117                 delete function->idList;
    118                 delete function->oldDeclList;
    119                 delete function->body;
    120                 delete function;
     116                delete function.params;
     117                delete function.idList;
     118                delete function.oldDeclList;
     119                delete function.body;
     120                // delete function;
    121121                break;
    122122          case Aggregate:
    123                 delete aggregate->params;
    124                 delete aggregate->actuals;
    125                 delete aggregate->fields;
    126                 delete aggregate;
     123                delete aggregate.params;
     124                delete aggregate.actuals;
     125                delete aggregate.fields;
     126                // delete aggregate;
    127127                break;
    128128          case AggregateInst:
    129                 delete aggInst->aggregate;
    130                 delete aggInst->params;
    131                 delete aggInst;
     129                delete aggInst.aggregate;
     130                delete aggInst.params;
     131                // delete aggInst;
    132132                break;
    133133          case Enum:
    134                 delete enumeration->constants;
    135                 delete enumeration;
     134                delete enumeration.constants;
     135                // delete enumeration;
    136136                break;
    137137          case Symbolic:
    138138          case SymbolicInst:
    139                 delete symbolic->params;
    140                 delete symbolic->actuals;
    141                 delete symbolic->assertions;
    142                 delete symbolic;
     139                delete symbolic.params;
     140                delete symbolic.actuals;
     141                delete symbolic.assertions;
     142                // delete symbolic;
    143143                break;
    144144          case Variable:
    145                 delete variable->assertions;
    146                 delete variable;
     145                // delete variable.assertions;
     146                // delete variable;
    147147                break;
    148148          case Tuple:
    149                 delete tuple->members;
     149                // delete tuple->members;
    150150                delete tuple;
    151151                break;
    152152          case Typeof:
    153                 delete typeexpr->expr;
     153                // delete typeexpr->expr;
    154154                delete typeexpr;
    155155                break;
     156          case Attr:
     157                // delete attr.expr;
     158                // delete attr.type;
     159                // delete attr;
     160                break;
    156161          case Builtin:
    157                 delete builtin;
    158                 break;
    159           case Attr:
    160                 delete attr->expr;
    161                 delete attr->type;
    162                 delete attr;
     162                // delete builtin;
    163163                break;
    164164        } // switch
     
    178178                break;
    179179          case Basic:
    180                 newtype->basic->typeSpec = basic->typeSpec;
    181                 newtype->basic->modifiers = basic->modifiers;
     180                newtype->basic.typeSpec = basic.typeSpec;
     181                newtype->basic.modifiers = basic.modifiers;
    182182                break;
    183183          case Array:
    184                 newtype->array->dimension = maybeClone( array->dimension );
    185                 newtype->array->isVarLen = array->isVarLen;
    186                 newtype->array->isStatic = array->isStatic;
     184                newtype->array.dimension = maybeClone( array.dimension );
     185                newtype->array.isVarLen = array.isVarLen;
     186                newtype->array.isStatic = array.isStatic;
    187187                break;
    188188          case Function:
    189                 newtype->function->params = maybeClone( function->params );
    190                 newtype->function->idList = maybeClone( function->idList );
    191                 newtype->function->oldDeclList = maybeClone( function->oldDeclList );
    192                 newtype->function->body = maybeClone( function->body );
    193                 newtype->function->hasBody = function->hasBody;
    194                 newtype->function->newStyle = function->newStyle;
     189                newtype->function.params = maybeClone( function.params );
     190                newtype->function.idList = maybeClone( function.idList );
     191                newtype->function.oldDeclList = maybeClone( function.oldDeclList );
     192                newtype->function.body = maybeClone( function.body );
     193                newtype->function.hasBody = function.hasBody;
     194                newtype->function.newStyle = function.newStyle;
    195195                break;
    196196          case Aggregate:
    197                 newtype->aggregate->params = maybeClone( aggregate->params );
    198                 newtype->aggregate->actuals = maybeClone( aggregate->actuals );
    199                 newtype->aggregate->fields = maybeClone( aggregate->fields );
    200                 newtype->aggregate->name = aggregate->name;
    201                 newtype->aggregate->kind = aggregate->kind;
    202                 newtype->aggregate->body = aggregate->body;
     197                newtype->aggregate.params = maybeClone( aggregate.params );
     198                newtype->aggregate.actuals = maybeClone( aggregate.actuals );
     199                newtype->aggregate.fields = maybeClone( aggregate.fields );
     200                newtype->aggregate.name = aggregate.name;
     201                newtype->aggregate.kind = aggregate.kind;
     202                newtype->aggregate.body = aggregate.body;
    203203                break;
    204204          case AggregateInst:
    205                 newtype->aggInst->aggregate = maybeClone( aggInst->aggregate );
    206                 newtype->aggInst->params = maybeClone( aggInst->params );
     205                newtype->aggInst.aggregate = maybeClone( aggInst.aggregate );
     206                newtype->aggInst.params = maybeClone( aggInst.params );
    207207                break;
    208208          case Enum:
    209                 newtype->enumeration->name = enumeration->name;
    210                 newtype->enumeration->constants = maybeClone( enumeration->constants );
     209                newtype->enumeration.name = enumeration.name;
     210                newtype->enumeration.constants = maybeClone( enumeration.constants );
    211211                break;
    212212          case Symbolic:
    213213          case SymbolicInst:
    214                 newtype->symbolic->params = maybeClone( symbolic->params );
    215                 newtype->symbolic->actuals = maybeClone( symbolic->actuals );
    216                 newtype->symbolic->assertions = maybeClone( symbolic->assertions );
    217                 newtype->symbolic->isTypedef = symbolic->isTypedef;
    218                 newtype->symbolic->name = symbolic->name;
     214                newtype->symbolic.params = maybeClone( symbolic.params );
     215                newtype->symbolic.actuals = maybeClone( symbolic.actuals );
     216                newtype->symbolic.assertions = maybeClone( symbolic.assertions );
     217                newtype->symbolic.isTypedef = symbolic.isTypedef;
     218                newtype->symbolic.name = symbolic.name;
    219219                break;
    220220          case Variable:
    221                 newtype->variable->assertions = maybeClone( variable->assertions );
    222                 newtype->variable->name = variable->name;
    223                 newtype->variable->tyClass = variable->tyClass;
     221                assert( false );
     222                // newtype->variable.assertions = maybeClone( variable.assertions );
     223                // newtype->variable.name = variable.name;
     224                // newtype->variable.tyClass = variable.tyClass;
    224225                break;
    225226          case Tuple:
    226                 newtype->tuple->members = maybeClone( tuple->members );
     227                newtype->tuple = maybeClone( tuple );
    227228                break;
    228229          case Typeof:
    229                 newtype->typeexpr->expr = maybeClone( typeexpr->expr );
     230                newtype->typeexpr = maybeClone( typeexpr );
     231                break;
     232          case Attr:
     233                assert( false );
     234                // newtype->attr.expr = maybeClone( attr.expr );
     235                // newtype->attr.type = maybeClone( attr.type );
    230236                break;
    231237          case Builtin:
    232                 newtype->builtin->type = builtin->type;
    233                 break;
    234           case Attr:
    235                 newtype->attr->expr = maybeClone( attr->expr );
    236                 newtype->attr->type = maybeClone( attr->type );
     238                assert( false );
     239                // newtype->builtin = builtin;
    237240                break;
    238241        } // switch
     
    268271                break;
    269272          case Basic:
    270                 printEnums( basic->modifiers.begin(), basic->modifiers.end(), DeclarationNode::modifierName, os );
    271                 printEnums( basic->typeSpec.begin(), basic->typeSpec.end(), DeclarationNode::basicTypeName, os );
     273                printEnums( basic.modifiers.begin(), basic.modifiers.end(), DeclarationNode::modifierName, os );
     274                printEnums( basic.typeSpec.begin(), basic.typeSpec.end(), DeclarationNode::basicTypeName, os );
    272275                break;
    273276          case Array:
    274                 if ( array->isStatic ) {
     277                if ( array.isStatic ) {
    275278                        os << "static ";
    276279                } // if
    277                 if ( array->dimension ) {
     280                if ( array.dimension ) {
    278281                        os << "array of ";
    279                         array->dimension->printOneLine( os, indent );
    280                 } else if ( array->isVarLen ) {
     282                        array.dimension->printOneLine( os, indent );
     283                } else if ( array.isVarLen ) {
    281284                        os << "variable-length array of ";
    282285                } else {
     
    289292          case Function:
    290293                os << "function" << endl;
    291                 if ( function->params ) {
     294                if ( function.params ) {
    292295                        os << string( indent + 2, ' ' ) << "with parameters " << endl;
    293                         function->params->printList( os, indent + 4 );
     296                        function.params->printList( os, indent + 4 );
    294297                } else {
    295298                        os << string( indent + 2, ' ' ) << "with no parameters " << endl;
    296299                } // if
    297                 if ( function->idList ) {
     300                if ( function.idList ) {
    298301                        os << string( indent + 2, ' ' ) << "with old-style identifier list " << endl;
    299                         function->idList->printList( os, indent + 4 );
    300                 } // if
    301                 if ( function->oldDeclList ) {
     302                        function.idList->printList( os, indent + 4 );
     303                } // if
     304                if ( function.oldDeclList ) {
    302305                        os << string( indent + 2, ' ' ) << "with old-style declaration list " << endl;
    303                         function->oldDeclList->printList( os, indent + 4 );
     306                        function.oldDeclList->printList( os, indent + 4 );
    304307                } // if
    305308                os << string( indent + 2, ' ' ) << "returning ";
     
    310313                } // if
    311314                os << endl;
    312                 if ( function->hasBody ) {
     315                if ( function.hasBody ) {
    313316                        os << string( indent + 2, ' ' ) << "with body " << endl;
    314317                } // if
    315                 if ( function->body ) {
    316                         function->body->printList( os, indent + 2 );
     318                if ( function.body ) {
     319                        function.body->printList( os, indent + 2 );
    317320                } // if
    318321                break;
    319322          case Aggregate:
    320                 os << DeclarationNode::aggregateName[ aggregate->kind ] << ' ' << aggregate->name << endl;
    321                 if ( aggregate->params ) {
     323                os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << aggregate.name << endl;
     324                if ( aggregate.params ) {
    322325                        os << string( indent + 2, ' ' ) << "with type parameters " << endl;
    323                         aggregate->params->printList( os, indent + 4 );
    324                 } // if
    325                 if ( aggregate->actuals ) {
     326                        aggregate.params->printList( os, indent + 4 );
     327                } // if
     328                if ( aggregate.actuals ) {
    326329                        os << string( indent + 2, ' ' ) << "instantiated with actual parameters " << endl;
    327                         aggregate->actuals->printList( os, indent + 4 );
    328                 } // if
    329                 if ( aggregate->fields ) {
     330                        aggregate.actuals->printList( os, indent + 4 );
     331                } // if
     332                if ( aggregate.fields ) {
    330333                        os << string( indent + 2, ' ' ) << "with members " << endl;
    331                         aggregate->fields->printList( os, indent + 4 );
    332                 } // if
    333                 if ( aggregate->body ) {
     334                        aggregate.fields->printList( os, indent + 4 );
     335                } // if
     336                if ( aggregate.body ) {
    334337                        os << string( indent + 2, ' ' ) << " with body " << endl;
    335338                } // if
    336339                break;
    337340          case AggregateInst:
    338                 if ( aggInst->aggregate ) {
     341                if ( aggInst.aggregate ) {
    339342                        os << "instance of " ;
    340                         aggInst->aggregate->print( os, indent );
     343                        aggInst.aggregate->print( os, indent );
    341344                } else {
    342345                        os << "instance of an unspecified aggregate ";
    343346                } // if
    344                 if ( aggInst->params ) {
     347                if ( aggInst.params ) {
    345348                        os << string( indent + 2, ' ' ) << "with parameters " << endl;
    346                         aggInst->params->printList( os, indent + 2 );
     349                        aggInst.params->printList( os, indent + 2 );
    347350                } // if
    348351                break;
    349352          case Enum:
    350353                os << "enumeration ";
    351                 if ( enumeration->constants ) {
     354                if ( enumeration.constants ) {
    352355                        os << "with constants" << endl;
    353                         enumeration->constants->printList( os, indent + 2 );
     356                        enumeration.constants->printList( os, indent + 2 );
    354357                } // if
    355358                break;
    356359          case SymbolicInst:
    357                 os << "instance of type " << symbolic->name;
    358                 if ( symbolic->actuals ) {
     360                os << "instance of type " << symbolic.name;
     361                if ( symbolic.actuals ) {
    359362                        os << " with parameters" << endl;
    360                         symbolic->actuals->printList( os, indent + 2 );
     363                        symbolic.actuals->printList( os, indent + 2 );
    361364                } // if
    362365                break;
    363366          case Symbolic:
    364                 if ( symbolic->isTypedef ) {
     367                if ( symbolic.isTypedef ) {
    365368                        os << "typedef definition ";
    366369                } else {
    367370                        os << "type definition ";
    368371                } // if
    369                 if ( symbolic->params ) {
     372                if ( symbolic.params ) {
    370373                        os << endl << string( indent + 2, ' ' ) << "with parameters" << endl;
    371                         symbolic->params->printList( os, indent + 2 );
    372                 } // if
    373                 if ( symbolic->assertions ) {
     374                        symbolic.params->printList( os, indent + 2 );
     375                } // if
     376                if ( symbolic.assertions ) {
    374377                        os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;
    375                         symbolic->assertions->printList( os, indent + 4 );
     378                        symbolic.assertions->printList( os, indent + 4 );
    376379                        os << string( indent + 2, ' ' );
    377380                } // if
     
    382385                break;
    383386          case Variable:
    384                 os << DeclarationNode::typeClassName[ variable->tyClass ] << " variable ";
    385                 if ( variable->assertions ) {
    386                         os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;
    387                         variable->assertions->printList( os, indent + 4 );
    388                         os << string( indent + 2, ' ' );
    389                 } // if
     387                // os << DeclarationNode::typeClassName[ variable.tyClass ] << " variable ";
     388                // if ( variable.assertions ) {
     389                //      os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;
     390                //      variable.assertions->printList( os, indent + 4 );
     391                //      os << string( indent + 2, ' ' );
     392                // } // if
    390393                break;
    391394          case Tuple:
    392395                os << "tuple ";
    393                 if ( tuple->members ) {
     396                if ( tuple ) {
    394397                        os << "with members " << endl;
    395                         tuple->members->printList( os, indent + 2 );
     398                        tuple->printList( os, indent + 2 );
    396399                } // if
    397400                break;
    398401          case Typeof:
    399402                os << "type-of expression ";
    400                 if ( typeexpr->expr ) {
    401                         typeexpr->expr->print( os, indent + 2 );
     403                if ( typeexpr ) {
     404                        typeexpr->print( os, indent + 2 );
    402405                } // if
    403406                break;
    404407          case Attr:
    405                 os << "attribute type decl " << attr->name << " applied to ";
    406                 if ( attr->expr ) {
    407                         attr->expr->print( os, indent + 2 );
    408                 } // if
    409                 if ( attr->type ) {
    410                         attr->type->print( os, indent + 2 );
    411                 } // if
     408                // os << "attribute type decl " << attr.name << " applied to ";
     409                // if ( attr.expr ) {
     410                //      attr.expr->print( os, indent + 2 );
     411                // } // if
     412                // if ( attr.type ) {
     413                //      attr.type->print( os, indent + 2 );
     414                // } // if
    412415                break;
    413416          case Builtin:
     
    479482                return new VarArgsType( buildQualifiers( td ) );
    480483          case TypeData::Attr:
     484                assert( false );
    481485                return buildAttr( td );
    482486          case TypeData::Symbolic:
     
    494498        switch ( td->kind ) {
    495499          case TypeData::Aggregate:
    496                 if ( ! toplevel && td->aggregate->fields ) {
     500                if ( ! toplevel && td->aggregate.fields ) {
    497501                        ret = td->clone();
    498502                } // if
    499503                break;
    500504          case TypeData::Enum:
    501                 if ( ! toplevel && td->enumeration->constants ) {
     505                if ( ! toplevel && td->enumeration.constants ) {
    502506                        ret = td->clone();
    503507                } // if
    504508                break;
    505509          case TypeData::AggregateInst:
    506                 if ( td->aggInst->aggregate ) {
    507                         ret = typeextractAggregate( td->aggInst->aggregate, false );
     510                if ( td->aggInst.aggregate ) {
     511                        ret = typeextractAggregate( td->aggInst.aggregate, false );
    508512                } // if
    509513                break;
     
    535539        BasicType::Kind ret;
    536540
    537         for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic->typeSpec.begin(); i != td->basic->typeSpec.end(); ++i ) {
     541        for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic.typeSpec.begin(); i != td->basic.typeSpec.end(); ++i ) {
    538542                if ( ! init ) {
    539543                        init = true;
    540544                        if ( *i == DeclarationNode::Void ) {
    541                                 if ( td->basic->typeSpec.size() != 1 || ! td->basic->modifiers.empty() ) {
     545                                if ( td->basic.typeSpec.size() != 1 || ! td->basic.modifiers.empty() ) {
    542546                                        throw SemanticError( "invalid type specifier \"void\" in type: ", td );
    543547                                } else {
     
    611615        } // for
    612616
    613         for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic->modifiers.begin(); i != td->basic->modifiers.end(); ++i ) {
     617        for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic.modifiers.begin(); i != td->basic.modifiers.end(); ++i ) {
    614618                switch ( *i ) {
    615619                  case DeclarationNode::Long:
     
    746750        ArrayType * at;
    747751        if ( td->base ) {
    748                 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array->dimension ),
    749                                                         td->array->isVarLen, td->array->isStatic );
     752                at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array.dimension ),
     753                                                        td->array.isVarLen, td->array.isStatic );
    750754        } else {
    751755                at = new ArrayType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ),
    752                                                         maybeBuild< Expression >( td->array->dimension ), td->array->isVarLen, td->array->isStatic );
     756                                                        maybeBuild< Expression >( td->array.dimension ), td->array.isVarLen, td->array.isStatic );
    753757        } // if
    754758        buildForall( td->forall, at->get_forall() );
     
    759763        assert( td->kind == TypeData::Aggregate );
    760764        AggregateDecl * at;
    761         switch ( td->aggregate->kind ) {
     765        switch ( td->aggregate.kind ) {
    762766          case DeclarationNode::Struct:
    763                 at = new StructDecl( td->aggregate->name );
    764                 buildForall( td->aggregate->params, at->get_parameters() );
     767                at = new StructDecl( td->aggregate.name );
     768                buildForall( td->aggregate.params, at->get_parameters() );
    765769                break;
    766770          case DeclarationNode::Union:
    767                 at = new UnionDecl( td->aggregate->name );
    768                 buildForall( td->aggregate->params, at->get_parameters() );
     771                at = new UnionDecl( td->aggregate.name );
     772                buildForall( td->aggregate.params, at->get_parameters() );
    769773                break;
    770774          case DeclarationNode::Trait:
    771                 at = new TraitDecl( td->aggregate->name );
    772                 buildList( td->aggregate->params, at->get_parameters() );
     775                at = new TraitDecl( td->aggregate.name );
     776                buildList( td->aggregate.params, at->get_parameters() );
    773777                break;
    774778          default:
     
    776780        } // switch
    777781
    778         buildList( td->aggregate->fields, at->get_members() );
    779         at->set_body( td->aggregate->body );
     782        buildList( td->aggregate.fields, at->get_members() );
     783        at->set_body( td->aggregate.body );
    780784
    781785        return at;
     
    786790
    787791        ReferenceToType * ret;
    788         if ( td->aggInst->aggregate->kind == TypeData::Enum ) {
    789                 ret = new EnumInstType( buildQualifiers( td ), td->aggInst->aggregate->enumeration->name );
     792        if ( td->aggInst.aggregate->kind == TypeData::Enum ) {
     793                ret = new EnumInstType( buildQualifiers( td ), td->aggInst.aggregate->enumeration.name );
    790794        } else {
    791                 assert( td->aggInst->aggregate->kind == TypeData::Aggregate );
    792                 switch ( td->aggInst->aggregate->aggregate->kind ) {
     795                assert( td->aggInst.aggregate->kind == TypeData::Aggregate );
     796                switch ( td->aggInst.aggregate->aggregate.kind ) {
    793797                  case DeclarationNode::Struct:
    794                         ret = new StructInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
     798                        ret = new StructInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
    795799                        break;
    796800                  case DeclarationNode::Union:
    797                         ret = new UnionInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
     801                        ret = new UnionInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
    798802                        break;
    799803                  case DeclarationNode::Trait:
    800                         ret = new TraitInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
     804                        ret = new TraitInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
    801805                        break;
    802806                  default:
     
    804808                } // switch
    805809        } // if
    806         buildList( td->aggInst->params, ret->get_parameters() );
     810        buildList( td->aggInst.params, ret->get_parameters() );
    807811        buildForall( td->forall, ret->get_forall() );
    808812        return ret;
     
    813817        NamedTypeDecl * ret;
    814818        assert( td->base );
    815         if ( td->symbolic->isTypedef ) {
     819        if ( td->symbolic.isTypedef ) {
    816820                ret = new TypedefDecl( name, sc, typebuild( td->base ) );
    817821        } else {
    818822                ret = new TypeDecl( name, sc, typebuild( td->base ), TypeDecl::Any );
    819823        } // if
    820         buildList( td->symbolic->params, ret->get_parameters() );
    821         buildList( td->symbolic->assertions, ret->get_assertions() );
     824        buildList( td->symbolic.params, ret->get_parameters() );
     825        buildList( td->symbolic.assertions, ret->get_assertions() );
    822826        return ret;
    823827} // buildSymbolic
    824828
    825829TypeDecl * buildVariable( const TypeData * td ) {
    826         assert( td->kind == TypeData::Variable );
    827         static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
    828 
    829         TypeDecl * ret = new TypeDecl( td->variable->name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable->tyClass ] );
    830         buildList( td->variable->assertions, ret->get_assertions() );
    831         return ret;
     830        assert( false );
     831        return nullptr;
     832        // assert( td->kind == TypeData::Variable );
     833        // static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
     834
     835        // TypeDecl * ret = new TypeDecl( td->variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable.tyClass ] );
     836        // buildList( td->variable.assertions, ret->get_assertions() );
     837        // return ret;
    832838} // buildSymbolic
    833839
    834840EnumDecl * buildEnum( const TypeData * td ) {
    835841        assert( td->kind == TypeData::Enum );
    836         EnumDecl * ret = new EnumDecl( td->enumeration->name );
    837         buildList( td->enumeration->constants, ret->get_members() );
     842        EnumDecl * ret = new EnumDecl( td->enumeration.name );
     843        buildList( td->enumeration.constants, ret->get_members() );
    838844        std::list< Declaration * >::iterator members = ret->get_members().begin();
    839         for ( const DeclarationNode * cur = td->enumeration-> constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
     845        for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
    840846                if ( cur->has_enumeratorValue() ) {
    841847                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
     
    848854TypeInstType * buildSymbolicInst( const TypeData * td ) {
    849855        assert( td->kind == TypeData::SymbolicInst );
    850         TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic->name, false );
    851         buildList( td->symbolic->actuals, ret->get_parameters() );
     856        TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic.name, false );
     857        buildList( td->symbolic.actuals, ret->get_parameters() );
    852858        buildForall( td->forall, ret->get_forall() );
    853859        return ret;
     
    857863        assert( td->kind == TypeData::Tuple );
    858864        TupleType * ret = new TupleType( buildQualifiers( td ) );
    859         buildTypeList( td->tuple->members, ret->get_types() );
     865        buildTypeList( td->tuple, ret->get_types() );
    860866        buildForall( td->forall, ret->get_forall() );
    861867        return ret;
     
    865871        assert( td->kind == TypeData::Typeof );
    866872        assert( td->typeexpr );
    867         assert( td->typeexpr->expr );
    868         return new TypeofType( buildQualifiers( td ), td->typeexpr->expr->build() );
     873        // assert( td->typeexpr->expr );
     874        return new TypeofType( buildQualifiers( td ), td->typeexpr->build() );
    869875} // buildTypeof
    870876
    871877AttrType * buildAttr( const TypeData * td ) {
    872         assert( td->kind == TypeData::Attr );
    873         assert( td->attr );
    874         AttrType * ret;
    875         if ( td->attr->expr ) {
    876                 ret = new AttrType( buildQualifiers( td ), td->attr->name, td->attr->expr->build() );
    877         } else {
    878                 assert( td->attr->type );
    879                 ret = new AttrType( buildQualifiers( td ), td->attr->name, td->attr->type->buildType() );
    880         } // if
    881         return ret;
     878        assert( false );
     879        return nullptr;
     880        // assert( td->kind == TypeData::Attr );
     881        // // assert( td->attr );
     882        // AttrType * ret;
     883        // if ( td->attr.expr ) {
     884        //      ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.expr->build() );
     885        // } else {
     886        //      assert( td->attr.type );
     887        //      ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.type->buildType() );
     888        // } // if
     889        // return ret;
    882890} // buildAttr
    883891
     
    885893        if ( td->kind == TypeData::Function ) {
    886894                FunctionDecl * decl;
    887                 if ( td->function->hasBody ) {
    888                         if ( td->function->body ) {
    889                                 Statement * stmt = td->function->body->build();
     895                if ( td->function.hasBody ) {
     896                        if ( td->function.body ) {
     897                                Statement * stmt = td->function.body->build();
    890898                                CompoundStmt * body = dynamic_cast< CompoundStmt* >( stmt );
    891899                                assert( body );
     
    898906                        decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn );
    899907                } // if
    900                 for ( DeclarationNode * cur = td->function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {
     908                for ( DeclarationNode * cur = td->function.idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {
    901909                        if ( cur->get_name() != "" ) {
    902910                                decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() );
    903911                        } // if
    904912                } // for
    905                 buildList( td->function->oldDeclList, decl->get_oldDecls() );
     913                buildList( td->function.oldDeclList, decl->get_oldDecls() );
    906914                return decl;
    907915        } else if ( td->kind == TypeData::Aggregate ) {
     
    912920                return buildSymbolic( td, name, sc );
    913921        } else if ( td->kind == TypeData::Variable ) {
     922                assert( false );
    914923                return buildVariable( td );
    915924        } else {
     
    921930FunctionType * buildFunction( const TypeData * td ) {
    922931        assert( td->kind == TypeData::Function );
    923         bool hasEllipsis = td->function->params ? td->function->params->get_hasEllipsis() : true;
    924         if ( ! td->function->params ) hasEllipsis = ! td->function->newStyle;
     932        bool hasEllipsis = td->function.params ? td->function.params->get_hasEllipsis() : true;
     933        if ( ! td->function.params ) hasEllipsis = ! td->function.newStyle;
    925934        FunctionType * ft = new FunctionType( buildQualifiers( td ), hasEllipsis );
    926         buildList( td->function->params, ft->get_parameters() );
     935        buildList( td->function.params, ft->get_parameters() );
    927936        buildForall( td->forall, ft->get_forall() );
    928937        if ( td->base ) {
    929938                switch ( td->base->kind ) {
    930939                  case TypeData::Tuple:
    931                         buildList( td->base->tuple->members, ft->get_returnVals() );
     940                        buildList( td->base->tuple, ft->get_returnVals() );
    932941                        break;
    933942                  default:
  • src/Parser/TypeData.h

    r0362d42 r1ced874  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 28 22:39:00 2016
    13 // Update Count     : 85
     12// Last Modified On : Mon Aug 29 22:31:52 2016
     13// Update Count     : 110
    1414//
    1515
     
    2424struct TypeData {
    2525        enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst,
    26                                 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr } kind;
     26                                Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr };
    2727
    2828        struct Basic_t {
     
    7373        };
    7474
    75         struct Variable_t {
    76                 DeclarationNode::TypeClass tyClass;
    77                 std::string name;
    78                 DeclarationNode * assertions;
    79         };
     75        // struct Tuple_t {
     76        //      DeclarationNode * members;
     77        // };
     78 
     79        // struct Typeof_t {
     80        //      ExpressionNode * expr;
     81        // };
    8082
    81         struct Tuple_t {
    82                 DeclarationNode * members;
    83         };
    84  
    85         struct Typeof_t {
    86                 ExpressionNode * expr;
    87         };
     83        // struct Builtin_t {
     84        //      DeclarationNode::BuiltinType type;
     85        // };
    8886
    89         struct Builtin_t {
    90                 DeclarationNode::BuiltinType type;
    91         };
    92 
    93         struct Attr_t {
    94                 std::string name;
    95                 ExpressionNode * expr;
    96                 DeclarationNode * type;
    97         };
    98 
     87        Kind kind;
    9988        TypeData * base;
    10089        typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers;
     
    10291        DeclarationNode * forall;
    10392
    104         union {
    105                 Basic_t * basic;
    106                 Aggregate_t * aggregate;
    107                 AggInst_t * aggInst;
    108                 Array_t * array;
    109                 Enumeration_t * enumeration;
    110                 Function_t * function;
    111                 Symbolic_t * symbolic;
    112                 Variable_t * variable;
    113                 Tuple_t * tuple;
    114                 Typeof_t * typeexpr;
    115                 Attr_t * attr;
    116                 Builtin_t * builtin;
    117         };
     93                Basic_t basic;
     94                Aggregate_t aggregate;
     95                AggInst_t aggInst;
     96                Array_t array;
     97                Enumeration_t enumeration;
     98                Function_t function;
     99                Symbolic_t symbolic;
     100                DeclarationNode * tuple;
     101                ExpressionNode * typeexpr;
     102                //Attr_t attr;
     103                // DeclarationNode::BuiltinType builtin;
    118104
    119105        TypeData( Kind k = Unknown );
  • src/ResolvExpr/AlternativeFinder.cc

    r0362d42 r1ced874  
    4242#include "Common/utility.h"
    4343#include "InitTweak/InitTweak.h"
     44#include "ResolveTypeof.h"
    4445
    4546extern bool resolvep;
     
    740741        void AlternativeFinder::visit( CastExpr *castExpr ) {
    741742                for ( std::list< Type* >::iterator i = castExpr->get_results().begin(); i != castExpr->get_results().end(); ++i ) {
     743                        *i = resolveTypeof( *i, indexer );
    742744                        SymTab::validateType( *i, &indexer );
    743745                        adjustExprType( *i, env, indexer );
     
    828830
    829831        void AlternativeFinder::visit( VariableExpr *variableExpr ) {
    830                 alternatives.push_back( Alternative( variableExpr->clone(), env, Cost::zero ) );
     832                // not sufficient to clone here, because variable's type may have changed
     833                // since the VariableExpr was originally created.
     834                alternatives.push_back( Alternative( new VariableExpr( variableExpr->get_var() ), env, Cost::zero ) );
    831835        }
    832836
     
    837841        void AlternativeFinder::visit( SizeofExpr *sizeofExpr ) {
    838842                if ( sizeofExpr->get_isType() ) {
     843                        // xxx - resolveTypeof?
    839844                        alternatives.push_back( Alternative( sizeofExpr->clone(), env, Cost::zero ) );
    840845                } else {
     
    856861        void AlternativeFinder::visit( AlignofExpr *alignofExpr ) {
    857862                if ( alignofExpr->get_isType() ) {
     863                        // xxx - resolveTypeof?
    858864                        alternatives.push_back( Alternative( alignofExpr->clone(), env, Cost::zero ) );
    859865                } else {
     
    889895        void AlternativeFinder::visit( UntypedOffsetofExpr *offsetofExpr ) {
    890896                AlternativeFinder funcFinder( indexer, env );
     897                // xxx - resolveTypeof?
    891898                if ( StructInstType *structInst = dynamic_cast< StructInstType* >( offsetofExpr->get_type() ) ) {
    892899                        addOffsetof( structInst, offsetofExpr->get_member() );
  • src/ResolvExpr/Resolver.cc

    r0362d42 r1ced874  
    528528
    529529        void Resolver::visit( ConstructorInit *ctorInit ) {
    530                 try {
    531                         maybeAccept( ctorInit->get_ctor(), *this );
    532                         maybeAccept( ctorInit->get_dtor(), *this );
    533                 } catch ( SemanticError ) {
    534                         // no alternatives for the constructor initializer - fallback on C-style initializer
    535                         // xxx - not sure if this makes a ton of sense - should maybe never be able to have this situation?
    536                         fallbackInit( ctorInit );
    537                         return;
    538                 }
     530                // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit
     531                maybeAccept( ctorInit->get_ctor(), *this );
     532                maybeAccept( ctorInit->get_dtor(), *this );
    539533
    540534                // found a constructor - can get rid of C-style initializer
  • src/SymTab/Indexer.cc

    r0362d42 r1ced874  
    2121#include <unordered_set>
    2222#include <utility>
     23#include <algorithm>
    2324
    2425#include "Mangler.h"
     
    3334#include "SynTree/Initializer.h"
    3435#include "SynTree/Statement.h"
     36
     37#include "InitTweak/InitTweak.h"
    3538
    3639#define debugPrint(x) if ( doDebug ) { std::cout << x; }
     
    99102
    100103                if ( --toFree->refCount == 0 ) delete toFree;
     104        }
     105
     106        void Indexer::removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const {
     107                // only need to perform this step for constructors and destructors
     108                if ( ! InitTweak::isCtorDtor( id ) ) return;
     109
     110                // helpful data structure
     111                struct ValueType {
     112                        struct DeclBall {
     113                                FunctionDecl * decl;
     114                                bool isUserDefinedFunc; // properties for this particular decl
     115                                bool isDefaultFunc;
     116                                bool isCopyFunc;
     117                        };
     118                        // properties for this type
     119                        bool userDefinedFunc = false; // any user defined function found
     120                        bool userDefinedDefaultFunc = false; // user defined default ctor found
     121                        bool userDefinedCopyFunc = false; // user defined copy ctor found
     122                        std::list< DeclBall > decls;
     123
     124                        // another FunctionDecl for the current type was found - determine
     125                        // if it has special properties and update data structure accordingly
     126                        ValueType & operator+=( FunctionDecl * function ) {
     127                                bool isUserDefinedFunc = ! LinkageSpec::isOverridable( function->get_linkage() );
     128                                bool isDefaultFunc = function->get_functionType()->get_parameters().size() == 1;
     129                                bool isCopyFunc = InitTweak::isCopyConstructor( function );
     130                                decls.push_back( DeclBall{ function, isUserDefinedFunc, isDefaultFunc, isCopyFunc } );
     131                                userDefinedFunc = userDefinedFunc || isUserDefinedFunc;
     132                                userDefinedDefaultFunc = userDefinedDefaultFunc || (isUserDefinedFunc && isDefaultFunc);
     133                                userDefinedCopyFunc = userDefinedCopyFunc || (isUserDefinedFunc && isCopyFunc);
     134                                return *this;
     135                        }
     136                }; // ValueType
     137
     138                std::list< DeclarationWithType * > copy;
     139                copy.splice( copy.end(), out );
     140
     141                // organize discovered declarations by type
     142                std::unordered_map< std::string, ValueType > funcMap;
     143                for ( DeclarationWithType * decl : copy ) {
     144                        if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ) ) {
     145                                std::list< DeclarationWithType * > params = function->get_functionType()->get_parameters();
     146                                assert( ! params.empty() );
     147                                funcMap[ Mangler::mangle( params.front()->get_type() ) ] += function;
     148                        } else {
     149                                out.push_back( decl );
     150                        }
     151                }
     152
     153                // if a type contains user defined ctor/dtors, then special rules trigger, which determine
     154                // the set of ctor/dtors that are seen by the requester. In particular, if the user defines
     155                // a default ctor, then the generated default ctor should never be seen, likewise for copy ctor
     156                // and dtor. If the user defines any ctor/dtor, then no generated field ctors should be seen.
     157                for ( std::pair< const std::string, ValueType > & pair : funcMap ) {
     158                        ValueType & val = pair.second;
     159                        for ( ValueType::DeclBall ball : val.decls ) {
     160                                if ( ! val.userDefinedFunc || ball.isUserDefinedFunc || (! val.userDefinedDefaultFunc && ball.isDefaultFunc) || (! val.userDefinedCopyFunc && ball.isCopyFunc) ) {
     161                                        // decl conforms to the rules described above, so it should be seen by the requester
     162                                        out.push_back( ball.decl );
     163                                }
     164                        }
     165                }
    101166        }
    102167
     
    461526                        searchTables = searchTables->base.tables;
    462527                }
     528
     529                // some special functions, e.g. constructors and destructors
     530                // remove autogenerated functions when they are defined so that
     531                // they can never be matched
     532                removeSpecialOverrides( id, out );
    463533        }
    464534
  • src/SymTab/Indexer.h

    r0362d42 r1ced874  
    128128                static void deleteRef( Impl *toFree );
    129129
     130                // Removes matching autogenerated constructors and destructors
     131                // so that they will not be selected
     132                // void removeSpecialOverrides( FunctionDecl *decl );
     133                void removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const;
     134
    130135                /// Ensures that tables variable is writable (i.e. allocated, uniquely owned by this Indexer, and at the current scope)
    131136                void makeWritable();
  • src/SynTree/FunctionDecl.cc

    r0362d42 r1ced874  
    2121#include "Attribute.h"
    2222#include "Common/utility.h"
     23#include "InitTweak/InitTweak.h"
    2324
    2425FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes )
  • src/main.cc

    r0362d42 r1ced874  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 20 12:52:22 2016
    13 // Update Count     : 403
     12// Last Modified On : Mon Aug 29 17:34:39 2016
     13// Update Count     : 426
    1414//
    1515
     
    7575static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
    7676
    77 void sigSegvBusHandler( int sig_num ) {
     77void backtrace( int start ) {                                                   // skip first N stack frames
    7878        enum { Frames = 50 };
    7979        void * array[Frames];
    8080        int size = backtrace( array, Frames );
    81 
    82         cerr << "*CFA runtime error* program cfa-cpp terminated with "
    83                  <<     (sig_num == SIGSEGV ? "segment fault" : "bus error")
    84                  << " backtrace:" << endl;
    85 
    8681        char ** messages = backtrace_symbols( array, size );
    8782
    88         // skip first stack frame (points here)
    89         for ( int i = 2; i < size - 2 && messages != nullptr; i += 1 ) {
     83        // skip last 2 stack frames after main
     84        for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
    9085                char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr;
    9186                for ( char *p = messages[i]; *p; ++p ) {        // find parantheses and +offset
     
    10196
    10297                // if line contains symbol, attempt to demangle
     98                int frameNo = i - start;
    10399                if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) {
    104100                        *mangled_name++ = '\0';
     
    106102                        *offset_end++ = '\0';
    107103
    108                         int status;
     104                        int status, frameNo = i - start;
    109105                        char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status );
    110106                        if ( status == 0 ) {                                            // demangling successful ?
    111                                 cerr << "(" << i - 2 << ") " << messages[i] << " : "
     107                                cerr << "(" << frameNo << ") " << messages[i] << " : "
    112108                                         << real_name << "+" << offset_begin << offset_end << endl;
    113109
    114110                        } else {                                                                        // otherwise, output mangled name
    115                                 cerr << "(" << i - 2 << ") " << messages[i] << " : "
     111                                cerr << "(" << frameNo << ") " << messages[i] << " : "
    116112                                         << mangled_name << "+" << offset_begin << offset_end << endl;
    117113                        } // if
    118114                        free( real_name );
    119115                } else {                                                                                // otherwise, print the whole line
    120                         cerr << "(" << i - 2 << ") " << messages[i] << endl;
     116                        cerr << "(" << frameNo << ") " << messages[i] << endl;
    121117                } // if
    122118        } // for
     119
    123120        free( messages );
     121} // backtrace
     122
     123void sigSegvBusHandler( int sig_num ) {
     124        cerr << "*CFA runtime error* program cfa-cpp terminated with "
     125                 <<     (sig_num == SIGSEGV ? "segment fault" : "bus error")
     126                 << " backtrace:" << endl;
     127        backtrace( 2 );                                                                         // skip first 2 stack frames
    124128        exit( EXIT_FAILURE );
    125129} // sigSegvBusHandler
     130
     131void sigAbortHandler( int sig_num ) {
     132        backtrace( 6 );                                                                         // skip first 6 stack frames
     133        signal( SIGABRT, SIG_DFL);                                                      // reset default signal handler
     134    raise( SIGABRT );                                                                   // reraise SIGABRT
     135} // sigAbortHandler
     136
    126137
    127138int main( int argc, char * argv[] ) {
     
    133144        signal( SIGSEGV, sigSegvBusHandler );
    134145        signal( SIGBUS, sigSegvBusHandler );
     146        signal( SIGABRT, sigAbortHandler );
    135147
    136148        parse_cmdline( argc, argv, filename );                          // process command-line arguments
  • src/tests/.expect/32/declarationSpecifier.txt

    r0362d42 r1ced874  
    530530    return ((int )_retVal0);
    531531}
    532 __attribute__ ((constructor(),)) static void _init_declarationSpecifier(void){
    533     ((void)___constructor__F_P13s__anonymous0_autogen___1(((struct __anonymous0 *)(&__x10__CV13s__anonymous0_1))));
    534     ((void)___constructor__F_P13s__anonymous1_autogen___1(((struct __anonymous1 *)(&__x11__CV13s__anonymous1_1))));
    535     ((void)___constructor__F_P13s__anonymous2_autogen___1(((struct __anonymous2 *)(&__x12__CV13s__anonymous2_1))));
    536     ((void)___constructor__F_P13s__anonymous3_autogen___1(((struct __anonymous3 *)(&__x13__CV13s__anonymous3_1))));
    537     ((void)___constructor__F_P13s__anonymous4_autogen___1(((struct __anonymous4 *)(&__x14__CV13s__anonymous4_1))));
    538     ((void)___constructor__F_P13s__anonymous5_autogen___1(((struct __anonymous5 *)(&__x15__CV13s__anonymous5_1))));
    539     ((void)___constructor__F_P13s__anonymous6_autogen___1(((struct __anonymous6 *)(&__x16__CV13s__anonymous6_1))));
    540     ((void)___constructor__F_P13s__anonymous7_autogen___1(((struct __anonymous7 *)(&__x17__CV13s__anonymous7_1))));
    541     ((void)___constructor__F_P13s__anonymous8_autogen___1(((struct __anonymous8 *)(&__x29__CV13s__anonymous8_1))));
    542     ((void)___constructor__F_P13s__anonymous9_autogen___1(((struct __anonymous9 *)(&__x30__CV13s__anonymous9_1))));
    543     ((void)___constructor__F_P14s__anonymous10_autogen___1(((struct __anonymous10 *)(&__x31__CV14s__anonymous10_1))));
    544     ((void)___constructor__F_P14s__anonymous11_autogen___1(((struct __anonymous11 *)(&__x32__CV14s__anonymous11_1))));
    545     ((void)___constructor__F_P14s__anonymous12_autogen___1(((struct __anonymous12 *)(&__x33__CV14s__anonymous12_1))));
    546     ((void)___constructor__F_P14s__anonymous13_autogen___1(((struct __anonymous13 *)(&__x34__CV14s__anonymous13_1))));
    547     ((void)___constructor__F_P14s__anonymous14_autogen___1(((struct __anonymous14 *)(&__x35__CV14s__anonymous14_1))));
    548     ((void)___constructor__F_P14s__anonymous15_autogen___1(((struct __anonymous15 *)(&__x36__CV14s__anonymous15_1))));
    549 }
    550 __attribute__ ((destructor(),)) static void _destroy_declarationSpecifier(void){
    551     ((void)___destructor__F_P14s__anonymous15_autogen___1(((struct __anonymous15 *)(&__x36__CV14s__anonymous15_1))));
    552     ((void)___destructor__F_P14s__anonymous14_autogen___1(((struct __anonymous14 *)(&__x35__CV14s__anonymous14_1))));
    553     ((void)___destructor__F_P14s__anonymous13_autogen___1(((struct __anonymous13 *)(&__x34__CV14s__anonymous13_1))));
    554     ((void)___destructor__F_P14s__anonymous12_autogen___1(((struct __anonymous12 *)(&__x33__CV14s__anonymous12_1))));
    555     ((void)___destructor__F_P14s__anonymous11_autogen___1(((struct __anonymous11 *)(&__x32__CV14s__anonymous11_1))));
    556     ((void)___destructor__F_P14s__anonymous10_autogen___1(((struct __anonymous10 *)(&__x31__CV14s__anonymous10_1))));
    557     ((void)___destructor__F_P13s__anonymous9_autogen___1(((struct __anonymous9 *)(&__x30__CV13s__anonymous9_1))));
    558     ((void)___destructor__F_P13s__anonymous8_autogen___1(((struct __anonymous8 *)(&__x29__CV13s__anonymous8_1))));
    559     ((void)___destructor__F_P13s__anonymous7_autogen___1(((struct __anonymous7 *)(&__x17__CV13s__anonymous7_1))));
    560     ((void)___destructor__F_P13s__anonymous6_autogen___1(((struct __anonymous6 *)(&__x16__CV13s__anonymous6_1))));
    561     ((void)___destructor__F_P13s__anonymous5_autogen___1(((struct __anonymous5 *)(&__x15__CV13s__anonymous5_1))));
    562     ((void)___destructor__F_P13s__anonymous4_autogen___1(((struct __anonymous4 *)(&__x14__CV13s__anonymous4_1))));
    563     ((void)___destructor__F_P13s__anonymous3_autogen___1(((struct __anonymous3 *)(&__x13__CV13s__anonymous3_1))));
    564     ((void)___destructor__F_P13s__anonymous2_autogen___1(((struct __anonymous2 *)(&__x12__CV13s__anonymous2_1))));
    565     ((void)___destructor__F_P13s__anonymous1_autogen___1(((struct __anonymous1 *)(&__x11__CV13s__anonymous1_1))));
    566     ((void)___destructor__F_P13s__anonymous0_autogen___1(((struct __anonymous0 *)(&__x10__CV13s__anonymous0_1))));
    567 }
  • src/tests/.expect/32/extension.txt

    r0362d42 r1ced874  
    8686        __extension__ int __c__i_2;
    8787    };
    88     int __i__i_2;
    89     ((void)((*((int *)(&__i__i_2)))=(__extension__ __a__i_1+__extension__ 3)) /* ?{} */);
     88    int __i__i_2 = ((int )(__extension__ __a__i_1+__extension__ 3));
    9089    ((void)__extension__ 3);
    9190    ((void)__extension__ __a__i_1);
  • src/tests/.expect/32/gccExtensions.txt

    r0362d42 r1ced874  
    7676        ((void)((*((int *)(&(*___dst__P2sS_2).__c__i_2)))=__c__i_2) /* ?{} */);
    7777    }
    78     int __i__i_2;
    79     ((void)((*((int *)(&__i__i_2)))=__extension__ 3) /* ?{} */);
     78    int __i__i_2 = ((int )__extension__ 3);
    8079    __extension__ int __a__i_2;
    8180    __extension__ int __b__i_2;
     
    133132    }
    134133    struct s3 __x1__3ss3_2;
    135     ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));
    136134    struct s3 __y1__3ss3_2;
    137     ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));
    138135    struct s4 {
    139136        int __i__i_2;
     
    141138    inline struct s4 ___operator_assign__F3ss4_P3ss43ss4_autogen___2(struct s4 *___dst__P3ss4_2, struct s4 ___src__3ss4_2){
    142139        ((void)((*___dst__P3ss4_2).__i__i_2=___src__3ss4_2.__i__i_2));
    143         ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));
    144         ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));
    145140        return ((struct s4 )___src__3ss4_2);
    146141    }
     
    158153    }
    159154    struct s4 __x2__3ss4_2;
    160     ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));
    161155    struct s4 __y2__3ss4_2;
    162     ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));
    163156    int __m1__A0i_2[((unsigned int )10)];
    164157    int __m2__A0A0i_2[((unsigned int )10)][((unsigned int )10)];
     
    166159    int _retVal0 = { 0 };
    167160    ((void)(_retVal0=0) /* ?{} */);
    168     ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));
    169     ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));
    170     ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));
    171     ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));
    172161    return ((int )_retVal0);
    173     ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));
    174     ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));
    175     ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));
    176     ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));
    177162}
  • src/tests/.expect/64/declarationSpecifier.txt

    r0362d42 r1ced874  
    530530    return ((int )_retVal0);
    531531}
    532 __attribute__ ((constructor(),)) static void _init_declarationSpecifier(void){
    533     ((void)___constructor__F_P13s__anonymous0_autogen___1(((struct __anonymous0 *)(&__x10__CV13s__anonymous0_1))));
    534     ((void)___constructor__F_P13s__anonymous1_autogen___1(((struct __anonymous1 *)(&__x11__CV13s__anonymous1_1))));
    535     ((void)___constructor__F_P13s__anonymous2_autogen___1(((struct __anonymous2 *)(&__x12__CV13s__anonymous2_1))));
    536     ((void)___constructor__F_P13s__anonymous3_autogen___1(((struct __anonymous3 *)(&__x13__CV13s__anonymous3_1))));
    537     ((void)___constructor__F_P13s__anonymous4_autogen___1(((struct __anonymous4 *)(&__x14__CV13s__anonymous4_1))));
    538     ((void)___constructor__F_P13s__anonymous5_autogen___1(((struct __anonymous5 *)(&__x15__CV13s__anonymous5_1))));
    539     ((void)___constructor__F_P13s__anonymous6_autogen___1(((struct __anonymous6 *)(&__x16__CV13s__anonymous6_1))));
    540     ((void)___constructor__F_P13s__anonymous7_autogen___1(((struct __anonymous7 *)(&__x17__CV13s__anonymous7_1))));
    541     ((void)___constructor__F_P13s__anonymous8_autogen___1(((struct __anonymous8 *)(&__x29__CV13s__anonymous8_1))));
    542     ((void)___constructor__F_P13s__anonymous9_autogen___1(((struct __anonymous9 *)(&__x30__CV13s__anonymous9_1))));
    543     ((void)___constructor__F_P14s__anonymous10_autogen___1(((struct __anonymous10 *)(&__x31__CV14s__anonymous10_1))));
    544     ((void)___constructor__F_P14s__anonymous11_autogen___1(((struct __anonymous11 *)(&__x32__CV14s__anonymous11_1))));
    545     ((void)___constructor__F_P14s__anonymous12_autogen___1(((struct __anonymous12 *)(&__x33__CV14s__anonymous12_1))));
    546     ((void)___constructor__F_P14s__anonymous13_autogen___1(((struct __anonymous13 *)(&__x34__CV14s__anonymous13_1))));
    547     ((void)___constructor__F_P14s__anonymous14_autogen___1(((struct __anonymous14 *)(&__x35__CV14s__anonymous14_1))));
    548     ((void)___constructor__F_P14s__anonymous15_autogen___1(((struct __anonymous15 *)(&__x36__CV14s__anonymous15_1))));
    549 }
    550 __attribute__ ((destructor(),)) static void _destroy_declarationSpecifier(void){
    551     ((void)___destructor__F_P14s__anonymous15_autogen___1(((struct __anonymous15 *)(&__x36__CV14s__anonymous15_1))));
    552     ((void)___destructor__F_P14s__anonymous14_autogen___1(((struct __anonymous14 *)(&__x35__CV14s__anonymous14_1))));
    553     ((void)___destructor__F_P14s__anonymous13_autogen___1(((struct __anonymous13 *)(&__x34__CV14s__anonymous13_1))));
    554     ((void)___destructor__F_P14s__anonymous12_autogen___1(((struct __anonymous12 *)(&__x33__CV14s__anonymous12_1))));
    555     ((void)___destructor__F_P14s__anonymous11_autogen___1(((struct __anonymous11 *)(&__x32__CV14s__anonymous11_1))));
    556     ((void)___destructor__F_P14s__anonymous10_autogen___1(((struct __anonymous10 *)(&__x31__CV14s__anonymous10_1))));
    557     ((void)___destructor__F_P13s__anonymous9_autogen___1(((struct __anonymous9 *)(&__x30__CV13s__anonymous9_1))));
    558     ((void)___destructor__F_P13s__anonymous8_autogen___1(((struct __anonymous8 *)(&__x29__CV13s__anonymous8_1))));
    559     ((void)___destructor__F_P13s__anonymous7_autogen___1(((struct __anonymous7 *)(&__x17__CV13s__anonymous7_1))));
    560     ((void)___destructor__F_P13s__anonymous6_autogen___1(((struct __anonymous6 *)(&__x16__CV13s__anonymous6_1))));
    561     ((void)___destructor__F_P13s__anonymous5_autogen___1(((struct __anonymous5 *)(&__x15__CV13s__anonymous5_1))));
    562     ((void)___destructor__F_P13s__anonymous4_autogen___1(((struct __anonymous4 *)(&__x14__CV13s__anonymous4_1))));
    563     ((void)___destructor__F_P13s__anonymous3_autogen___1(((struct __anonymous3 *)(&__x13__CV13s__anonymous3_1))));
    564     ((void)___destructor__F_P13s__anonymous2_autogen___1(((struct __anonymous2 *)(&__x12__CV13s__anonymous2_1))));
    565     ((void)___destructor__F_P13s__anonymous1_autogen___1(((struct __anonymous1 *)(&__x11__CV13s__anonymous1_1))));
    566     ((void)___destructor__F_P13s__anonymous0_autogen___1(((struct __anonymous0 *)(&__x10__CV13s__anonymous0_1))));
    567 }
  • src/tests/.expect/64/extension.txt

    r0362d42 r1ced874  
    8686        __extension__ int __c__i_2;
    8787    };
    88     int __i__i_2;
    89     ((void)((*((int *)(&__i__i_2)))=(__extension__ __a__i_1+__extension__ 3)) /* ?{} */);
     88    int __i__i_2 = ((int )(__extension__ __a__i_1+__extension__ 3));
    9089    ((void)__extension__ 3);
    9190    ((void)__extension__ __a__i_1);
  • src/tests/.expect/64/gccExtensions.txt

    r0362d42 r1ced874  
    7676        ((void)((*((int *)(&(*___dst__P2sS_2).__c__i_2)))=__c__i_2) /* ?{} */);
    7777    }
    78     int __i__i_2;
    79     ((void)((*((int *)(&__i__i_2)))=__extension__ 3) /* ?{} */);
     78    int __i__i_2 = ((int )__extension__ 3);
    8079    __extension__ int __a__i_2;
    8180    __extension__ int __b__i_2;
     
    133132    }
    134133    struct s3 __x1__3ss3_2;
    135     ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));
    136134    struct s3 __y1__3ss3_2;
    137     ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));
    138135    struct s4 {
    139136        int __i__i_2;
     
    141138    inline struct s4 ___operator_assign__F3ss4_P3ss43ss4_autogen___2(struct s4 *___dst__P3ss4_2, struct s4 ___src__3ss4_2){
    142139        ((void)((*___dst__P3ss4_2).__i__i_2=___src__3ss4_2.__i__i_2));
    143         ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));
    144         ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));
    145140        return ((struct s4 )___src__3ss4_2);
    146141    }
     
    158153    }
    159154    struct s4 __x2__3ss4_2;
    160     ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));
    161155    struct s4 __y2__3ss4_2;
    162     ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));
    163156    int __m1__A0i_2[((long unsigned int )10)];
    164157    int __m2__A0A0i_2[((long unsigned int )10)][((long unsigned int )10)];
     
    166159    int _retVal0 = { 0 };
    167160    ((void)(_retVal0=0) /* ?{} */);
    168     ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));
    169     ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));
    170     ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));
    171     ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));
    172161    return ((int )_retVal0);
    173     ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));
    174     ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));
    175     ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));
    176     ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));
    177162}
  • src/tests/Makefile.am

    r0362d42 r1ced874  
    6262        ${CC} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
    6363
    64 ctorWarnings: ctorWarnings.c
    65         ${CC} ${CFALGS} -CFA -XCFA -p ${<} -o ${@}
     64memberCtors-ERR1: memberCtors.c
     65        ${CC} ${CFALGS} -DERR1 ${<} -o ${@}
    6666
  • src/tests/Makefile.in

    r0362d42 r1ced874  
    670670        ${CC} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@}
    671671
    672 ctorWarnings: ctorWarnings.c
    673         ${CC} ${CFALGS} -CFA -XCFA -p ${<} -o ${@}
     672memberCtors-ERR1: memberCtors.c
     673        ${CC} ${CFALGS} -DERR1 ${<} -o ${@}
    674674
    675675# Tell versions [3.59,3.63) of GNU make to not export all variables.
  • src/tests/typeof.c

    r0362d42 r1ced874  
    88    typeof( int ( int, int p ) ) *v7;
    99    typeof( [int] ( int, int p ) ) *v8;
     10    (typeof(v1)) v2; // cast with typeof
    1011}
Note: See TracChangeset for help on using the changeset viewer.