Changes in / [5e644d3e:1e8b02f5]


Ignore:
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r5e644d3e r1e8b02f5  
    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 : Thu Aug 25 20:42:25 2016
     13// Update Count     : 232
    1414//
    1515
     
    375375}
    376376
    377 void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) {
     377void DeclarationNode::checkQualifiers( TypeData *src, TypeData *dst ) {
    378378        TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers;
    379379
     
    801801DeclarationNode *DeclarationNode::extractAggregate() const {
    802802        if ( type ) {
    803                 TypeData *ret = typeextractAggregate( type );
     803                TypeData *ret = type->extractAggregate();
    804804                if ( ret ) {
    805805                        DeclarationNode *newnode = new DeclarationNode;
     
    896896        if ( ! error.empty() ) throw SemanticError( error, this );
    897897        if ( type ) {
    898                 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     898                return type->buildDecl( name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
    899899        } // if
    900900        if ( ! isInline && ! isNoreturn ) {
     
    909909        switch ( type->kind ) {
    910910          case TypeData::Enum:
    911                 return new EnumInstType( buildQualifiers( type ), type->enumeration->name );
     911                return new EnumInstType( type->buildQualifiers(), type->enumeration->name );
    912912          case TypeData::Aggregate: {
    913913                  ReferenceToType *ret;
    914914                  switch ( type->aggregate->kind ) {
    915915                        case DeclarationNode::Struct:
    916                           ret = new StructInstType( buildQualifiers( type ), type->aggregate->name );
     916                          ret = new StructInstType( type->buildQualifiers(), type->aggregate->name );
    917917                          break;
    918918                        case DeclarationNode::Union:
    919                           ret = new UnionInstType( buildQualifiers( type ), type->aggregate->name );
     919                          ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name );
    920920                          break;
    921921                        case DeclarationNode::Trait:
    922                           ret = new TraitInstType( buildQualifiers( type ), type->aggregate->name );
     922                          ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name );
    923923                          break;
    924924                        default:
     
    929929          }
    930930          case TypeData::Symbolic: {
    931                   TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic->name, false );
     931                  TypeInstType *ret = new TypeInstType( type->buildQualifiers(), type->symbolic->name, false );
    932932                  buildList( type->symbolic->actuals, ret->get_parameters() );
    933933                  return ret;
    934934          }
    935935          default:
    936                 return typebuild( type );
     936                return type->build();
    937937        } // switch
    938938}
  • src/Parser/ParseNode.h

    r5e644d3e r1e8b02f5  
    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 : Thu Aug 25 22:46:24 2016
     13// Update Count     : 564
    1414//
    1515
     
    243243
    244244        DeclarationNode *addQualifiers( DeclarationNode *);
    245         void checkQualifiers( const TypeData *, const TypeData * );
     245        void checkQualifiers( TypeData *, TypeData * );
    246246        DeclarationNode *copyStorageClasses( DeclarationNode *);
    247247        DeclarationNode *addType( DeclarationNode *);
     
    308308
    309309Type *buildType( TypeData *type );
    310 //Type::Qualifiers buildQualifiers( const TypeData::Qualifiers & qualifiers );
    311310
    312311static inline Type * maybeMoveBuildType( const DeclarationNode *orig ) {
  • src/Parser/TypeData.cc

    r5e644d3e r1e8b02f5  
    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 : Wed Aug 24 13:46:55 2016
     13// Update Count     : 69
    1414//
    1515
     
    9494                break;
    9595        } // switch
    96 } // TypeData::TypeData
     96}
    9797
    9898TypeData::~TypeData() {
     
    163163                break;
    164164        } // switch
    165 } // TypeData::~TypeData
    166 
    167 TypeData * TypeData::clone() const {
    168         TypeData * newtype = new TypeData( kind );
     165}
     166
     167TypeData *TypeData::clone() const {
     168        TypeData *newtype = new TypeData( kind );
    169169        newtype->qualifiers = qualifiers;
    170170        newtype->base = maybeClone( base );
     
    238238        } // switch
    239239        return newtype;
    240 } // TypeData::clone
     240}
    241241
    242242void TypeData::print( std::ostream &os, int indent ) const {
     
    418418                assert( false );
    419419        } // switch
    420 } // TypeData::print
    421 
    422 void buildForall( const DeclarationNode * firstNode, std::list< TypeDecl* > &outputList ) {
     420}
     421
     422TypeData *TypeData::extractAggregate( bool toplevel ) const {
     423        TypeData *ret = 0;
     424
     425        switch ( kind ) {
     426          case Aggregate:
     427                if ( ! toplevel && aggregate->fields ) {
     428                        ret = clone();
     429//                      ret->qualifiers.reset();
     430                } // if
     431                break;
     432          case Enum:
     433                if ( ! toplevel && enumeration->constants ) {
     434                        ret = clone();
     435//                      ret->qualifiers.reset();
     436                } // if
     437                break;
     438          case AggregateInst:
     439                if ( aggInst->aggregate ) {
     440                        ret = aggInst->aggregate->extractAggregate( false );
     441                } // if
     442                break;
     443          default:
     444                if ( base ) {
     445                        ret = base->extractAggregate( false );
     446                } // if
     447        } // switch
     448        return ret;
     449}
     450
     451void buildForall( const DeclarationNode *firstNode, std::list< TypeDecl* > &outputList ) {
    423452        buildList( firstNode, outputList );
    424453        for ( std::list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) {
     
    426455                        // add assertion parameters to `type' tyvars in reverse order
    427456                        // add dtor:  void ^?{}(T *)
    428                         FunctionType * dtorType = new FunctionType( Type::Qualifiers(), false );
     457                        FunctionType *dtorType = new FunctionType( Type::Qualifiers(), false );
    429458                        dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );
    430459                        (*i)->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, dtorType, 0, false, false ) );
    431460
    432461                        // add copy ctor:  void ?{}(T *, T)
    433                         FunctionType * copyCtorType = new FunctionType( Type::Qualifiers(), false );
     462                        FunctionType *copyCtorType = new FunctionType( Type::Qualifiers(), false );
    434463                        copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );
    435464                        copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
     
    437466
    438467                        // add default ctor:  void ?{}(T *)
    439                         FunctionType * ctorType = new FunctionType( Type::Qualifiers(), false );
     468                        FunctionType *ctorType = new FunctionType( Type::Qualifiers(), false );
    440469                        ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );
    441470                        (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, ctorType, 0, false, false ) );
    442471
    443472                        // add assignment operator:  T * ?=?(T *, T)
    444                         FunctionType * assignType = new FunctionType( Type::Qualifiers(), false );
     473                        FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
    445474                        assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );
    446475                        assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
     
    451480}
    452481
    453 Type * typebuild( const TypeData * td ) {
    454         assert( td );
    455         switch ( td->kind ) {
    456           case TypeData::Unknown:
     482Declaration *TypeData::buildDecl( std::string name, DeclarationNode::StorageClass sc, Expression *bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, Initializer *init ) const {
     483        if ( kind == TypeData::Function ) {
     484                FunctionDecl *decl;
     485                if ( function->hasBody ) {
     486                        if ( function->body ) {
     487                                Statement *stmt = function->body->build();
     488                                CompoundStmt *body = dynamic_cast< CompoundStmt* >( stmt );
     489                                assert( body );
     490                                decl = new FunctionDecl( name, sc, linkage, buildFunction(), body, isInline, isNoreturn );
     491                        } else {
     492                                // std::list< Label > ls;
     493                                decl = new FunctionDecl( name, sc, linkage, buildFunction(), new CompoundStmt( std::list< Label >() ), isInline, isNoreturn );
     494                        } // if
     495                } else {
     496                        decl = new FunctionDecl( name, sc, linkage, buildFunction(), 0, isInline, isNoreturn );
     497                } // if
     498                for ( DeclarationNode *cur = function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {
     499                        if ( cur->get_name() != "" ) {
     500                                decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() );
     501                        } // if
     502                } // for
     503                buildList( function->oldDeclList, decl->get_oldDecls() );
     504                return decl;
     505        } else if ( kind == TypeData::Aggregate ) {
     506                return buildAggregate();
     507        } else if ( kind == TypeData::Enum ) {
     508                return buildEnum();
     509        } else if ( kind == TypeData::Symbolic ) {
     510                return buildSymbolic( name, sc );
     511        } else if ( kind == TypeData::Variable ) {
     512                return buildVariable();
     513        } else {
     514                return new ObjectDecl( name, sc, linkage, bitfieldWidth, build(), init, std::list< Attribute * >(),  isInline, isNoreturn );
     515        } // if
     516        return 0;
     517}
     518
     519Type *TypeData::build() const {
     520        switch ( kind ) {
     521          case Unknown:
    457522                // fill in implicit int
    458                 return new BasicType( buildQualifiers( td ), BasicType::SignedInt );
    459           case TypeData::Basic:
    460                 return buildBasicType( td );
    461           case TypeData::Pointer:
    462                 return buildPointer( td );
    463           case TypeData::Array:
    464                 return buildArray( td );
    465           case TypeData::Function:
    466                 return buildFunction( td );
    467           case TypeData::AggregateInst:
    468                 return buildAggInst( td );
    469           case TypeData::EnumConstant:
     523                return new BasicType( buildQualifiers(), BasicType::SignedInt );
     524          case Basic:
     525                return buildBasicType();
     526          case Pointer:
     527                return buildPointer();
     528          case Array:
     529                return buildArray();
     530          case Function:
     531                return buildFunction();
     532          case AggregateInst:
     533                return buildAggInst();
     534          case EnumConstant:
    470535                // the name gets filled in later -- by SymTab::Validate
    471                 return new EnumInstType( buildQualifiers( td ), "" );
    472           case TypeData::SymbolicInst:
    473                 return buildSymbolicInst( td );;
    474           case TypeData::Tuple:
    475                 return buildTuple( td );
    476           case TypeData::Typeof:
    477                 return buildTypeof( td );
    478           case TypeData::Builtin:
    479                 return new VarArgsType( buildQualifiers( td ) );
    480           case TypeData::Attr:
    481                 return buildAttr( td );
    482           case TypeData::Symbolic:
    483           case TypeData::Enum:
    484           case TypeData::Aggregate:
    485           case TypeData::Variable:
     536                return new EnumInstType( buildQualifiers(), "" );
     537          case SymbolicInst:
     538                return buildSymbolicInst();;
     539          case Tuple:
     540                return buildTuple();
     541          case Typeof:
     542                return buildTypeof();
     543          case Builtin:
     544                return new VarArgsType( buildQualifiers() );
     545          case Attr:
     546                return buildAttr();
     547          case Symbolic:
     548          case Enum:
     549          case Aggregate:
     550          case Variable:
    486551                assert( false );
    487552        } // switch
    488553        return 0;
    489 } // typebuild
    490 
    491 TypeData * typeextractAggregate( const TypeData * td, bool toplevel ) {
    492         TypeData * ret = 0;
    493 
    494         switch ( td->kind ) {
    495           case TypeData::Aggregate:
    496                 if ( ! toplevel && td->aggregate->fields ) {
    497                         ret = td->clone();
    498                 } // if
    499                 break;
    500           case TypeData::Enum:
    501                 if ( ! toplevel && td->enumeration->constants ) {
    502                         ret = td->clone();
    503                 } // if
    504                 break;
    505           case TypeData::AggregateInst:
    506                 if ( td->aggInst->aggregate ) {
    507                         ret = typeextractAggregate( td->aggInst->aggregate, false );
    508                 } // if
    509                 break;
    510           default:
    511                 if ( td->base ) {
    512                         ret = typeextractAggregate( td->base, false );
    513                 } // if
    514         } // switch
    515         return ret;
    516 } // typeextractAggregate
    517 
    518 Type::Qualifiers buildQualifiers( const TypeData * td ) {
     554}
     555
     556Type::Qualifiers TypeData::buildQualifiers() const {
    519557        Type::Qualifiers q;
    520         q.isConst = td->qualifiers[ DeclarationNode::Const ];
    521         q.isVolatile = td->qualifiers[ DeclarationNode::Volatile ];
    522         q.isRestrict = td->qualifiers[ DeclarationNode::Restrict ];
    523         q.isLvalue = td->qualifiers[ DeclarationNode::Lvalue ];
    524         q.isAtomic = td->qualifiers[ DeclarationNode::Atomic ];;
     558        q.isConst = qualifiers[ DeclarationNode::Const ];
     559        q.isVolatile = qualifiers[ DeclarationNode::Volatile ];
     560        q.isRestrict = qualifiers[ DeclarationNode::Restrict ];
     561        q.isLvalue = qualifiers[ DeclarationNode::Lvalue ];
     562        q.isAtomic = qualifiers[ DeclarationNode::Atomic ];;
    525563        return q;
    526 } // buildQualifiers
    527 
    528 Type * buildBasicType( const TypeData * td ) {
     564}
     565
     566Type *TypeData::buildBasicType() const {
    529567        static const BasicType::Kind kindMap[] = { BasicType::Char, BasicType::SignedInt, BasicType::Float, BasicType::Double,
    530568                                                                                           BasicType::Char /* void */, BasicType::Bool, BasicType::DoubleComplex,
     
    535573        BasicType::Kind ret;
    536574
    537         for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic->typeSpec.begin(); i != td->basic->typeSpec.end(); ++i ) {
     575        for ( std::list< DeclarationNode::BasicType >::const_iterator i = basic->typeSpec.begin(); i != basic->typeSpec.end(); ++i ) {
    538576                if ( ! init ) {
    539577                        init = true;
    540578                        if ( *i == DeclarationNode::Void ) {
    541                                 if ( td->basic->typeSpec.size() != 1 || ! td->basic->modifiers.empty() ) {
    542                                         throw SemanticError( "invalid type specifier \"void\" in type: ", td );
     579                                if ( basic->typeSpec.size() != 1 || ! basic->modifiers.empty() ) {
     580                                        throw SemanticError( "invalid type specifier \"void\" in type: ", this );
    543581                                } else {
    544                                         return new VoidType( buildQualifiers( td ) );
     582                                        return new VoidType( buildQualifiers() );
    545583                                } // if
    546584                        } else {
     
    551589                          case DeclarationNode::Float:
    552590                                if ( sawDouble ) {
    553                                         throw SemanticError( "invalid type specifier \"float\" in type: ", td );
     591                                        throw SemanticError( "invalid type specifier \"float\" in type: ", this );
    554592                                } else {
    555593                                        switch ( ret ) {
     
    561599                                                break;
    562600                                          default:
    563                                                 throw SemanticError( "invalid type specifier \"float\" in type: ", td );
     601                                                throw SemanticError( "invalid type specifier \"float\" in type: ", this );
    564602                                        } // switch
    565603                                } // if
     
    567605                          case DeclarationNode::Double:
    568606                                if ( sawDouble ) {
    569                                         throw SemanticError( "duplicate type specifier \"double\" in type: ", td );
     607                                        throw SemanticError( "duplicate type specifier \"double\" in type: ", this );
    570608                                } else {
    571609                                        switch ( ret ) {
     
    574612                                                break;
    575613                                          default:
    576                                                 throw SemanticError( "invalid type specifier \"double\" in type: ", td );
     614                                                throw SemanticError( "invalid type specifier \"double\" in type: ", this );
    577615                                        } // switch
    578616                                } // if
     
    587625                                        break;
    588626                                  default:
    589                                         throw SemanticError( "invalid type specifier \"_Complex\" in type: ", td );
     627                                        throw SemanticError( "invalid type specifier \"_Complex\" in type: ", this );
    590628                                } // switch
    591629                                break;
     
    599637                                        break;
    600638                                  default:
    601                                         throw SemanticError( "invalid type specifier \"_Imaginary\" in type: ", td );
     639                                        throw SemanticError( "invalid type specifier \"_Imaginary\" in type: ", this );
    602640                                } // switch
    603641                                break;
    604642                          default:
    605                                 throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type: ", td );
     643                                throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type: ", this );
    606644                        } // switch
    607645                } // if
     
    611649        } // for
    612650
    613         for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic->modifiers.begin(); i != td->basic->modifiers.end(); ++i ) {
     651        for ( std::list< DeclarationNode::Modifier >::const_iterator i = basic->modifiers.begin(); i != basic->modifiers.end(); ++i ) {
    614652                switch ( *i ) {
    615653                  case DeclarationNode::Long:
     
    641679                                        break;
    642680                                  default:
    643                                         throw SemanticError( "invalid type modifier \"long\" in type: ", td );
     681                                        throw SemanticError( "invalid type modifier \"long\" in type: ", this );
    644682                                } // switch
    645683                        } // if
     
    658696                                        break;
    659697                                  default:
    660                                         throw SemanticError( "invalid type modifier \"short\" in type: ", td );
     698                                        throw SemanticError( "invalid type modifier \"short\" in type: ", this );
    661699                                } // switch
    662700                        } // if
     
    667705                                ret = BasicType::SignedInt;
    668706                        } else if ( sawSigned ) {
    669                                 throw SemanticError( "duplicate type modifer \"signed\" in type: ", td );
     707                                throw SemanticError( "duplicate type modifer \"signed\" in type: ", this );
    670708                        } else {
    671709                                switch ( ret ) {
     
    683721                                        break;
    684722                                  default:
    685                                         throw SemanticError( "invalid type modifer \"signed\" in type: ", td );
     723                                        throw SemanticError( "invalid type modifer \"signed\" in type: ", this );
    686724                                } // switch
    687725                        } // if
     
    692730                                ret = BasicType::UnsignedInt;
    693731                        } else if ( sawSigned ) {
    694                                 throw SemanticError( "invalid type modifer \"unsigned\" in type: ", td );
     732                                throw SemanticError( "invalid type modifer \"unsigned\" in type: ", this );
    695733                        } else {
    696734                                switch ( ret ) {
     
    711749                                        break;
    712750                                  default:
    713                                         throw SemanticError( "invalid type modifer \"unsigned\" in type: ", td );
     751                                        throw SemanticError( "invalid type modifer \"unsigned\" in type: ", this );
    714752                                } // switch
    715753                        } // if
     
    722760        } // for
    723761
    724         BasicType * bt;
     762        BasicType *bt;
    725763        if ( ! init ) {
    726                 bt = new BasicType( buildQualifiers( td ), BasicType::SignedInt );
     764                bt = new BasicType( buildQualifiers(), BasicType::SignedInt );
    727765        } else {
    728                 bt = new BasicType( buildQualifiers( td ), ret );
     766                bt = new BasicType( buildQualifiers(), ret );
    729767        } // if
    730         buildForall( td->forall, bt->get_forall() );
     768        buildForall( forall, bt->get_forall() );
    731769        return bt;
    732 } // buildBasicType
    733 
    734 PointerType * buildPointer( const TypeData * td ) {
    735         PointerType * pt;
    736         if ( td->base ) {
    737                 pt = new PointerType( buildQualifiers( td ), typebuild( td->base ) );
     770}
     771
     772
     773PointerType *TypeData::buildPointer() const {
     774        PointerType *pt;
     775        if ( base ) {
     776                pt = new PointerType( buildQualifiers(), base->build() );
    738777        } else {
    739                 pt = new PointerType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
     778                pt = new PointerType( buildQualifiers(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
    740779        } // if
    741         buildForall( td->forall, pt->get_forall() );
     780        buildForall( forall, pt->get_forall() );
    742781        return pt;
    743 } // buildPointer
    744 
    745 ArrayType * buildArray( const TypeData * td ) {
    746         ArrayType * at;
    747         if ( td->base ) {
    748                 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array->dimension ),
    749                                                         td->array->isVarLen, td->array->isStatic );
     782}
     783
     784ArrayType *TypeData::buildArray() const {
     785        ArrayType *at;
     786        if ( base ) {
     787                at = new ArrayType( buildQualifiers(), base->build(), maybeBuild< Expression >( array->dimension ),
     788                                                        array->isVarLen, array->isStatic );
    750789        } else {
    751                 at = new ArrayType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ),
    752                                                         maybeBuild< Expression >( td->array->dimension ), td->array->isVarLen, td->array->isStatic );
     790                at = new ArrayType( buildQualifiers(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ),
     791                                                        maybeBuild< Expression >( array->dimension ), array->isVarLen, array->isStatic );
    753792        } // if
    754         buildForall( td->forall, at->get_forall() );
     793        buildForall( forall, at->get_forall() );
    755794        return at;
    756 } // buildPointer
    757 
    758 AggregateDecl * buildAggregate( const TypeData * td ) {
    759         assert( td->kind == TypeData::Aggregate );
    760         AggregateDecl * at;
    761         switch ( td->aggregate->kind ) {
     795}
     796
     797FunctionType *TypeData::buildFunction() const {
     798        assert( kind == Function );
     799        bool hasEllipsis = function->params ? function->params->get_hasEllipsis() : true;
     800        if ( ! function->params ) hasEllipsis = ! function->newStyle;
     801        FunctionType *ft = new FunctionType( buildQualifiers(), hasEllipsis );
     802        buildList( function->params, ft->get_parameters() );
     803        buildForall( forall, ft->get_forall() );
     804        if ( base ) {
     805                switch ( base->kind ) {
     806                  case Tuple:
     807                        buildList( base->tuple->members, ft->get_returnVals() );
     808                        break;
     809                  default:
     810                        ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( base->buildDecl( "", DeclarationNode::NoStorageClass, 0, false, false, LinkageSpec::Cforall ) ) );
     811                } // switch
     812        } else {
     813                ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 ) );
     814        } // if
     815        return ft;
     816}
     817
     818AggregateDecl *TypeData::buildAggregate() const {
     819        assert( kind == Aggregate );
     820        AggregateDecl *at;
     821        switch ( aggregate->kind ) {
    762822          case DeclarationNode::Struct:
    763                 at = new StructDecl( td->aggregate->name );
    764                 buildForall( td->aggregate->params, at->get_parameters() );
     823                at = new StructDecl( aggregate->name );
     824                buildForall( aggregate->params, at->get_parameters() );
    765825                break;
    766826          case DeclarationNode::Union:
    767                 at = new UnionDecl( td->aggregate->name );
    768                 buildForall( td->aggregate->params, at->get_parameters() );
     827                at = new UnionDecl( aggregate->name );
     828                buildForall( aggregate->params, at->get_parameters() );
    769829                break;
    770830          case DeclarationNode::Trait:
    771                 at = new TraitDecl( td->aggregate->name );
    772                 buildList( td->aggregate->params, at->get_parameters() );
     831                at = new TraitDecl( aggregate->name );
     832                buildList( aggregate->params, at->get_parameters() );
    773833                break;
    774834          default:
     
    776836        } // switch
    777837
    778         buildList( td->aggregate->fields, at->get_members() );
    779         at->set_body( td->aggregate->body );
     838        buildList( aggregate->fields, at->get_members() );
     839        at->set_body( aggregate->body );
    780840
    781841        return at;
    782 } // buildAggregate
    783 
    784 ReferenceToType * buildAggInst( const TypeData * td ) {
    785         assert( td->kind == TypeData::AggregateInst );
    786 
    787         ReferenceToType * ret;
    788         if ( td->aggInst->aggregate->kind == TypeData::Enum ) {
    789                 ret = new EnumInstType( buildQualifiers( td ), td->aggInst->aggregate->enumeration->name );
     842}
     843
     844ReferenceToType *TypeData::buildAggInst() const {
     845        assert( kind == AggregateInst );
     846
     847        ReferenceToType *ret;
     848        if ( aggInst->aggregate->kind == Enum ) {
     849                ret = new EnumInstType( buildQualifiers(), aggInst->aggregate->enumeration->name );
    790850        } else {
    791                 assert( td->aggInst->aggregate->kind == TypeData::Aggregate );
    792                 switch ( td->aggInst->aggregate->aggregate->kind ) {
     851                assert( aggInst->aggregate->kind == Aggregate );
     852                switch ( aggInst->aggregate->aggregate->kind ) {
    793853                  case DeclarationNode::Struct:
    794                         ret = new StructInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
     854                        ret = new StructInstType( buildQualifiers(), aggInst->aggregate->aggregate->name );
    795855                        break;
    796856                  case DeclarationNode::Union:
    797                         ret = new UnionInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
     857                        ret = new UnionInstType( buildQualifiers(), aggInst->aggregate->aggregate->name );
    798858                        break;
    799859                  case DeclarationNode::Trait:
    800                         ret = new TraitInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
     860                        ret = new TraitInstType( buildQualifiers(), aggInst->aggregate->aggregate->name );
    801861                        break;
    802862                  default:
     
    804864                } // switch
    805865        } // if
    806         buildList( td->aggInst->params, ret->get_parameters() );
    807         buildForall( td->forall, ret->get_forall() );
     866        buildList( aggInst->params, ret->get_parameters() );
     867        buildForall( forall, ret->get_forall() );
    808868        return ret;
    809 } // buildAggInst
    810 
    811 NamedTypeDecl * buildSymbolic( const TypeData * td, const std::string & name, DeclarationNode::StorageClass sc ) {
    812         assert( td->kind == TypeData::Symbolic );
    813         NamedTypeDecl * ret;
    814         assert( td->base );
    815         if ( td->symbolic->isTypedef ) {
    816                 ret = new TypedefDecl( name, sc, typebuild( td->base ) );
     869}
     870
     871NamedTypeDecl *TypeData::buildSymbolic( const std::string &name, DeclarationNode::StorageClass sc ) const {
     872        assert( kind == Symbolic );
     873        NamedTypeDecl *ret;
     874        if ( symbolic->isTypedef ) {
     875                ret = new TypedefDecl( name, sc, maybeBuild< Type >( base ) );
    817876        } else {
    818                 ret = new TypeDecl( name, sc, typebuild( td->base ), TypeDecl::Any );
     877                ret = new TypeDecl( name, sc, maybeBuild< Type >( base ), TypeDecl::Any );
    819878        } // if
    820         buildList( td->symbolic->params, ret->get_parameters() );
    821         buildList( td->symbolic->assertions, ret->get_assertions() );
     879        buildList( symbolic->params, ret->get_parameters() );
     880        buildList( symbolic->assertions, ret->get_assertions() );
    822881        return ret;
    823 } // buildSymbolic
    824 
    825 TypeDecl * buildVariable( const TypeData * td ) {
    826         assert( td->kind == TypeData::Variable );
     882}
     883
     884TypeDecl *TypeData::buildVariable() const {
     885        assert( kind == Variable );
    827886        static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
    828887
    829         TypeDecl * ret = new TypeDecl( td->variable->name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable->tyClass ] );
    830         buildList( td->variable->assertions, ret->get_assertions() );
     888        TypeDecl *ret = new TypeDecl( variable->name, DeclarationNode::NoStorageClass, 0, kindMap[ variable->tyClass ] );
     889        buildList( variable->assertions, ret->get_assertions() );
    831890        return ret;
    832 } // buildSymbolic
    833 
    834 EnumDecl * buildEnum( const TypeData * td ) {
    835         assert( td->kind == TypeData::Enum );
    836         EnumDecl * ret = new EnumDecl( td->enumeration->name );
    837         buildList( td->enumeration->constants, ret->get_members() );
     891}
     892
     893EnumDecl *TypeData::buildEnum() const {
     894        assert( kind == Enum );
     895        EnumDecl *ret = new EnumDecl( enumeration->name );
     896        buildList( enumeration->constants, ret->get_members() );
    838897        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 ) {
     898        for ( const DeclarationNode *cur = enumeration->constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
    840899                if ( cur->has_enumeratorValue() ) {
    841                         ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
     900                        ObjectDecl *member = dynamic_cast< ObjectDecl * >(*members);
    842901                        member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), std::list< Expression * >() ) );
    843902                } // if
    844903        } // for
    845904        return ret;
    846 } // buildEnum
    847 
    848 TypeInstType * buildSymbolicInst( const TypeData * td ) {
    849         assert( td->kind == TypeData::SymbolicInst );
    850         TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic->name, false );
    851         buildList( td->symbolic->actuals, ret->get_parameters() );
    852         buildForall( td->forall, ret->get_forall() );
     905}
     906
     907TypeInstType *TypeData::buildSymbolicInst() const {
     908        assert( kind == SymbolicInst );
     909        TypeInstType *ret = new TypeInstType( buildQualifiers(), symbolic->name, false );
     910        buildList( symbolic->actuals, ret->get_parameters() );
     911        buildForall( forall, ret->get_forall() );
    853912        return ret;
    854 } // buildSymbolicInst
    855 
    856 TupleType * buildTuple( const TypeData * td ) {
    857         assert( td->kind == TypeData::Tuple );
    858         TupleType * ret = new TupleType( buildQualifiers( td ) );
    859         buildTypeList( td->tuple->members, ret->get_types() );
    860         buildForall( td->forall, ret->get_forall() );
     913}
     914
     915TupleType *TypeData::buildTuple() const {
     916        assert( kind == Tuple );
     917        TupleType *ret = new TupleType( buildQualifiers() );
     918        buildTypeList( tuple->members, ret->get_types() );
     919        buildForall( forall, ret->get_forall() );
    861920        return ret;
    862 } // buildTuple
    863 
    864 TypeofType * buildTypeof( const TypeData * td ) {
    865         assert( td->kind == TypeData::Typeof );
    866         assert( td->typeexpr );
    867         assert( td->typeexpr->expr );
    868         return new TypeofType( buildQualifiers( td ), td->typeexpr->expr->build() );
    869 } // buildTypeof
    870 
    871 AttrType * 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() );
     921}
     922
     923TypeofType *TypeData::buildTypeof() const {
     924        assert( kind == Typeof );
     925        assert( typeexpr );
     926        assert( typeexpr->expr );
     927        TypeofType *ret = new TypeofType( buildQualifiers(), typeexpr->expr->build() );
     928        return ret;
     929}
     930
     931AttrType *TypeData::buildAttr() const {
     932        assert( kind == Attr );
     933        assert( attr );
     934        AttrType *ret;
     935        if ( attr->expr ) {
     936                ret = new AttrType( buildQualifiers(), attr->name, attr->expr->build() );
    877937        } else {
    878                 assert( td->attr->type );
    879                 ret = new AttrType( buildQualifiers( td ), td->attr->name, td->attr->type->buildType() );
     938                assert( attr->type );
     939                ret = new AttrType( buildQualifiers(), attr->name, attr->type->buildType() );
    880940        } // if
    881941        return ret;
    882 } // buildAttr
    883 
    884 Declaration * buildDecl( const TypeData * td, std::string name, DeclarationNode::StorageClass sc, Expression * bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, Initializer * init ) {
    885         if ( td->kind == TypeData::Function ) {
    886                 FunctionDecl * decl;
    887                 if ( td->function->hasBody ) {
    888                         if ( td->function->body ) {
    889                                 Statement * stmt = td->function->body->build();
    890                                 CompoundStmt * body = dynamic_cast< CompoundStmt* >( stmt );
    891                                 assert( body );
    892                                 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), body, isInline, isNoreturn );
    893                         } else {
    894                                 // std::list< Label > ls;
    895                                 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), new CompoundStmt( std::list< Label >() ), isInline, isNoreturn );
    896                         } // if
    897                 } else {
    898                         decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn );
    899                 } // if
    900                 for ( DeclarationNode * cur = td->function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {
    901                         if ( cur->get_name() != "" ) {
    902                                 decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() );
    903                         } // if
    904                 } // for
    905                 buildList( td->function->oldDeclList, decl->get_oldDecls() );
    906                 return decl;
    907         } else if ( td->kind == TypeData::Aggregate ) {
    908                 return buildAggregate( td );
    909         } else if ( td->kind == TypeData::Enum ) {
    910                 return buildEnum( td );
    911         } else if ( td->kind == TypeData::Symbolic ) {
    912                 return buildSymbolic( td, name, sc );
    913         } else if ( td->kind == TypeData::Variable ) {
    914                 return buildVariable( td );
    915         } else {
    916                 return new ObjectDecl( name, sc, linkage, bitfieldWidth, typebuild( td ), init, std::list< Attribute * >(), isInline, isNoreturn );
    917         } // if
    918         return 0;
    919 } // buildDecl
    920 
    921 FunctionType * buildFunction( const TypeData * td ) {
    922         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;
    925         FunctionType * ft = new FunctionType( buildQualifiers( td ), hasEllipsis );
    926         buildList( td->function->params, ft->get_parameters() );
    927         buildForall( td->forall, ft->get_forall() );
    928         if ( td->base ) {
    929                 switch ( td->base->kind ) {
    930                   case TypeData::Tuple:
    931                         buildList( td->base->tuple->members, ft->get_returnVals() );
    932                         break;
    933                   default:
    934                         ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( buildDecl( td->base,  "", DeclarationNode::NoStorageClass, 0, false, false, LinkageSpec::Cforall ) ) );
    935                 } // switch
    936         } else {
    937                 ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 ) );
    938         } // if
    939         return ft;
    940 } // buildFunction
     942}
    941943
    942944// Local Variables: //
  • src/Parser/TypeData.h

    r5e644d3e r1e8b02f5  
    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 : Thu Aug 25 17:34:06 2016
     13// Update Count     : 26
    1414//
    1515
     
    2525        enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst,
    2626                                Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr } kind;
     27
     28        TypeData( Kind k = Unknown );
     29        ~TypeData();
     30        void print( std::ostream &, int indent = 0 ) const;
     31        TypeData * clone() const;
     32
     33        Type * build() const;
     34        FunctionType * buildFunction() const;
     35
     36        TypeData * base;
     37        typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers;
     38        Qualifiers qualifiers;
     39        DeclarationNode * forall;
    2740
    2841        struct Basic_t {
     
    97110        };
    98111
    99         TypeData * base;
    100         typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers;
    101         Qualifiers qualifiers;
    102         DeclarationNode * forall;
    103 
    104112        union {
    105113                Basic_t * basic;
     
    117125        };
    118126
    119         TypeData( Kind k = Unknown );
    120         ~TypeData();
    121         void print( std::ostream &, int indent = 0 ) const;
    122         TypeData * clone() const;
     127        TypeData * extractAggregate( bool toplevel = true ) const;
     128        // helper function for DeclNodeImpl::build
     129        Declaration * buildDecl( std::string name, DeclarationNode::StorageClass sc, Expression * bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, Initializer * init = 0 ) const;
     130        // helper functions for build()
     131        Type::Qualifiers buildQualifiers() const;
     132        Type * buildBasicType() const;
     133        PointerType * buildPointer() const;
     134        ArrayType * buildArray() const;
     135        AggregateDecl * buildAggregate() const;
     136        ReferenceToType * buildAggInst() const;
     137        NamedTypeDecl * buildSymbolic( const std::string &name, DeclarationNode::StorageClass sc ) const;
     138        TypeDecl* buildVariable() const;
     139        EnumDecl* buildEnum() const;
     140        TypeInstType * buildSymbolicInst() const;
     141        TupleType * buildTuple() const;
     142        TypeofType * buildTypeof() const;
     143        AttrType * buildAttr() const;
    123144};
    124 
    125 Type * typebuild( const TypeData * );
    126 TypeData * typeextractAggregate( const TypeData * td, bool toplevel = true );
    127 Type::Qualifiers buildQualifiers( const TypeData * td );
    128 Type * buildBasicType( const TypeData * );
    129 PointerType * buildPointer( const TypeData * );
    130 ArrayType * buildArray( const TypeData * );
    131 AggregateDecl * buildAggregate( const TypeData * );
    132 ReferenceToType * buildAggInst( const TypeData * );
    133 NamedTypeDecl * buildSymbolic( const TypeData *, const std::string &name, DeclarationNode::StorageClass sc );
    134 TypeDecl * buildVariable( const TypeData * );
    135 EnumDecl * buildEnum( const TypeData * );
    136 TypeInstType * buildSymbolicInst( const TypeData * );
    137 TupleType * buildTuple( const TypeData * );
    138 TypeofType * buildTypeof( const TypeData * );
    139 AttrType * buildAttr( const TypeData * );
    140 Declaration * buildDecl( const TypeData *, std::string, DeclarationNode::StorageClass, Expression *, bool isInline, bool isNoreturn, LinkageSpec::Spec, Initializer * init = 0 );
    141 FunctionType * buildFunction( const TypeData * );
    142145
    143146#endif // TYPEDATA_H
  • src/Parser/parser.yy

    r5e644d3e r1e8b02f5  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug 26 16:45:44 2016
    13 // Update Count     : 1964
     12// Last Modified On : Thu Aug 25 21:24:19 2016
     13// Update Count     : 1963
    1414//
    1515
     
    619619        | ERassign                                                                      { $$ = OperKinds::ERAssn; }
    620620        | ORassign                                                                      { $$ = OperKinds::OrAssn; }
    621         ;
     621;
    622622
    623623tuple:                                                                                                  // CFA, tuple
  • src/libcfa/Makefile.am

    r5e644d3e r1e8b02f5  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Fri Aug 26 12:03:37 2016
    14 ## Update Count     : 199
     13## Last Modified On : Thu Aug 11 15:36:32 2016
     14## Update Count     : 198
    1515###############################################################################
    1616
     
    5656CC = ${abs_top_srcdir}/src/driver/cfa
    5757
    58 headers = limits stdlib math iostream fstream iterator rational containers/vector
     58headers = limits stdlib math iostream fstream iterator rational # containers/vector
    5959libobjs = ${headers:=.o}
    6060
  • src/libcfa/Makefile.in

    r5e644d3e r1e8b02f5  
    8989libcfa_a_AR = $(AR) $(ARFLAGS)
    9090libcfa_a_LIBADD =
    91 am__dirstamp = $(am__leading_dot)dirstamp
    9291am__objects_1 = limits.$(OBJEXT) stdlib.$(OBJEXT) math.$(OBJEXT) \
    9392        iostream.$(OBJEXT) fstream.$(OBJEXT) iterator.$(OBJEXT) \
    94         rational.$(OBJEXT) containers/vector.$(OBJEXT)
     93        rational.$(OBJEXT)
    9594am_libcfa_a_OBJECTS = libcfa-prelude.$(OBJEXT) $(am__objects_1)
    9695libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS)
     
    234233cfalib_DATA = builtins.cf extras.cf prelude.cf
    235234MAINTAINERCLEANFILES = builtins.cf extras.cf ${addprefix ${libdir}/,${cfalib_DATA}} ${addprefix ${libdir}/,${lib_LIBRARIES}}
    236 headers = limits stdlib math iostream fstream iterator rational containers/vector
     235headers = limits stdlib math iostream fstream iterator rational # containers/vector
    237236libobjs = ${headers:=.o}
    238237libcfa_a_SOURCES = libcfa-prelude.c ${headers:=.c}
     
    304303clean-libLIBRARIES:
    305304        -test -z "$(lib_LIBRARIES)" || rm -f $(lib_LIBRARIES)
    306 containers/$(am__dirstamp):
    307         @$(MKDIR_P) containers
    308         @: > containers/$(am__dirstamp)
    309 containers/$(DEPDIR)/$(am__dirstamp):
    310         @$(MKDIR_P) containers/$(DEPDIR)
    311         @: > containers/$(DEPDIR)/$(am__dirstamp)
    312 containers/vector.$(OBJEXT): containers/$(am__dirstamp) \
    313         containers/$(DEPDIR)/$(am__dirstamp)
    314305libcfa.a: $(libcfa_a_OBJECTS) $(libcfa_a_DEPENDENCIES) $(EXTRA_libcfa_a_DEPENDENCIES)
    315306        $(AM_V_at)-rm -f libcfa.a
     
    319310mostlyclean-compile:
    320311        -rm -f *.$(OBJEXT)
    321         -rm -f containers/vector.$(OBJEXT)
    322312
    323313distclean-compile:
     
    332322@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rational.Po@am__quote@
    333323@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdlib.Po@am__quote@
    334 @AMDEP_TRUE@@am__include@ @am__quote@containers/$(DEPDIR)/vector.Po@am__quote@
    335324
    336325.c.o:
     
    505494        -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
    506495        -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
    507         -rm -f containers/$(DEPDIR)/$(am__dirstamp)
    508         -rm -f containers/$(am__dirstamp)
    509496
    510497maintainer-clean-generic:
     
    517504
    518505distclean: distclean-am
    519         -rm -rf ./$(DEPDIR) containers/$(DEPDIR)
     506        -rm -rf ./$(DEPDIR)
    520507        -rm -f Makefile
    521508distclean-am: clean-am distclean-compile distclean-generic \
     
    563550
    564551maintainer-clean: maintainer-clean-am
    565         -rm -rf ./$(DEPDIR) containers/$(DEPDIR)
     552        -rm -rf ./$(DEPDIR)
    566553        -rm -f Makefile
    567554maintainer-clean-am: distclean-am maintainer-clean-generic \
Note: See TracChangeset for help on using the changeset viewer.