Changes in / [6256891:92538ab]


Ignore:
Files:
2 added
22 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r6256891 r92538ab  
    273273                decl->parent = get<AggregateDecl>().accept1( node->parent );
    274274                declPostamble( decl, node );
    275                 return nullptr;
     275                return nullptr; // ??
    276276        }
    277277
     
    307307                        node->name,
    308308                        get<Attribute>().acceptL( node->attributes ),
    309                         LinkageSpec::Spec( node->linkage.val )
    310                 );
    311                 return aggregatePostamble( decl, node );
     309                        LinkageSpec::Spec( node->linkage.val ),
     310                        get<Type>().accept1(node->base)
     311                );
     312                return aggregatePostamble( decl, node ); // Node info, including members, processed in aggregatePostamble
    312313        }
    313314
     
    14701471                return strict_dynamic_cast< ast::Decl * >( node );
    14711472        }
    1472 
     1473       
    14731474        ConverterOldToNew() = default;
    14741475        ConverterOldToNew(const ConverterOldToNew &) = delete;
     
    14981499                getAccept1< ast::type, decltype( old->child ) >( old->child )
    14991500
     1501
    15001502        template<typename NewT, typename OldC>
    15011503        std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) {
     
    15121514#       define GET_ACCEPT_V(child, type) \
    15131515                getAcceptV< ast::type, decltype( old->child ) >( old->child )
     1516
     1517#       define GET_ACCEPT_E(child, type) \
     1518                getAccept1< ast::type, decltype( old->base ) >( old->base )
    15141519
    15151520        template<typename NewT, typename OldC>
     
    17131718        }
    17141719
     1720        // Convert SynTree::EnumDecl to AST::EnumDecl
    17151721        virtual void visit( const EnumDecl * old ) override final {
    17161722                if ( inCache( old ) ) return;
     
    17191725                        old->name,
    17201726                        GET_ACCEPT_V(attributes, Attribute),
    1721                         { old->linkage.val }
     1727                        { old->linkage.val },
     1728                        GET_ACCEPT_1(base, Type),
     1729                        old->enumValues
    17221730                );
    17231731                cache.emplace( old, decl );
     
    17291737                decl->uniqueId   = old->uniqueId;
    17301738                decl->storage    = { old->storageClasses.val };
    1731 
    17321739                this->node = decl;
    17331740        }
     
    27672774        }
    27682775
    2769         virtual void visit( const EnumInstType * old ) override final {
    2770                 ast::EnumInstType * ty;
     2776        virtual void visit( const EnumInstType * old ) override final { // Here is visiting the EnumInst Decl not the usage.
     2777                ast::EnumInstType * ty; 
    27712778                if ( old->baseEnum ) {
    2772                         ty = new ast::EnumInstType{
     2779                        ty = new ast::EnumInstType{ // Probably here: missing the specification of the base
    27732780                                GET_ACCEPT_1( baseEnum, EnumDecl ),
    27742781                                cv( old ),
  • src/AST/Decl.cpp

    r6256891 r92538ab  
    136136
    137137        auto it = enumValues.find( enumerator->name );
     138       
    138139        if ( it != enumValues.end() ) {
    139                 value = it->second;
     140                       
     141                // Handle typed enum by casting the value in (C++) compiler
     142                // if ( base ) { // A typed enum
     143                //      if ( const BasicType * bt = dynamic_cast<const BasicType *>(base) ) {
     144                //              switch( bt->kind ) {
     145                //                      case BasicType::Kind::Bool:     value = (bool) it->second; break;
     146                //                      case BasicType::Kind::Char: value = (char) it->second; break;
     147                //                      case BasicType::Kind::SignedChar: value = (signed char) it->second; break;
     148                //                      case BasicType::Kind::UnsignedChar: value = (unsigned char) it->second; break;
     149                //                      case BasicType::Kind::ShortSignedInt: value = (short signed int) it->second; break;
     150                //                      case BasicType::Kind::SignedInt: value = (signed int) it->second; break;
     151                //                      case BasicType::Kind::UnsignedInt: value = (unsigned int) it->second; break;
     152                //                      case BasicType::Kind::LongSignedInt: value = (long signed int) it->second; break;
     153                //                      case BasicType::Kind::LongUnsignedInt: value = (long unsigned int) it->second; break;
     154                //                      case BasicType::Kind::LongLongSignedInt: value = (long long signed int) it->second; break;
     155                //                      case BasicType::Kind::LongLongUnsignedInt: value = (long long unsigned int) it->second; break;
     156                //                      // TODO: value should be able to handle long long unsigned int
     157
     158                //                      default:
     159                //                      value = it->second;
     160                //              }
     161                //      }
     162                // } else {
     163                        value = it->second;
     164                //}
     165
    140166                return true;
    141167        }
  • src/AST/Decl.hpp

    r6256891 r92538ab  
    302302class EnumDecl final : public AggregateDecl {
    303303public:
     304        ptr<Type> base;
     305
    304306        EnumDecl( const CodeLocation& loc, const std::string& name,
    305                 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall )
    306         : AggregateDecl( loc, name, std::move(attrs), linkage ), enumValues() {}
     307                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall, Type * base = nullptr,
     308                 std::unordered_map< std::string, long long > enumValues = std::unordered_map< std::string, long long >() )
     309        : AggregateDecl( loc, name, std::move(attrs), linkage ), base(base), enumValues(enumValues) {}
    307310
    308311        /// gets the integer value for this enumerator, returning true iff value found
     312        // Maybe it is not used in producing the enum value
    309313        bool valueOf( const Decl * enumerator, long long& value ) const;
    310314
     
    312316
    313317        const char * typeString() const override { return aggrString( Enum ); }
     318
     319        bool isTyped() {return base && base.get();}
    314320
    315321private:
  • src/AST/Print.cpp

    r6256891 r92538ab  
    210210                }
    211211
     212                auto ptrToEnum = dynamic_cast<const ast::EnumDecl *>(node);
     213                if ( ! short_mode && ptrToEnum && ptrToEnum->base ) {
     214                        os << endl << indent << ".. with (enum) base" << endl;
     215                        ++indent;
     216                        ptrToEnum->base->accept( *this );
     217                        --indent; 
     218                }
     219
    212220                os << endl;
    213221        }
  • src/CodeGen/CodeGenerator.cc

    r6256891 r92538ab  
    274274        void CodeGenerator::postvisit( EnumDecl * enumDecl ) {
    275275                extension( enumDecl );
    276                 output << "enum ";
    277                 genAttributes( enumDecl->get_attributes() );
    278 
    279                 output << enumDecl->get_name();
    280 
    281276                std::list< Declaration* > &memb = enumDecl->get_members();
    282 
    283                 if ( ! memb.empty() ) {
    284                         output << " {" << endl;
    285 
    286                         ++indent;
     277                if (enumDecl->base && ! memb.empty() &&
     278                (dynamic_cast<BasicType *>(enumDecl->base)
     279                 && !(dynamic_cast<BasicType *>(enumDecl->base)->kind == BasicType::Kind::SignedInt))) {
     280                        ObjectDecl * last = nullptr;
    287281                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    288282                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
    289283                                assert( obj );
    290                                 output << indent << mangleName( obj );
     284                                output << "static const ";
     285                                output << genType(enumDecl->base, "", options) << " ";
     286                                output << mangleName( obj ) << " ";
     287                                output << " = ";
     288                                output << "(" << genType(enumDecl->base, "", options) << ")";;
    291289                                if ( obj->get_init() ) {
    292                                         output << " = ";
    293290                                        obj->get_init()->accept( *visitor );
    294                                 } // if
    295                                 output << "," << endl;
     291                                } else {
     292                                        if (last == nullptr) {
     293                                                output << 0;
     294                                        } else {
     295                                                output << mangleName(last) << " + 1";
     296                                        }
     297                                } // if—
     298                                output << ";" << endl;
     299                                last = obj;
    296300                        } // for
    297 
     301                } else {
     302                        output << "enum ";
     303                        genAttributes( enumDecl->get_attributes() );
     304
     305                        output << enumDecl->get_name();
     306
     307                        if ( ! memb.empty() ) {
     308                                output << " {" << endl;
     309
     310                                ++indent;
     311                                for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
     312                                        ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
     313                                        assert( obj );
     314                                        output << indent << mangleName( obj );
     315                                        if ( obj->get_init() ) {
     316                                                output << " = ";
     317                                                obj->get_init()->accept( *visitor );
     318                                        } // if
     319                                        output << "," << endl;
     320                                } // for
    298321                        --indent;
    299 
    300322                        output << indent << "}";
     323                        } // if
    301324                } // if
    302325        }
     
    347370                                des->accept( *visitor );
    348371                        } else {
    349                                 // otherwise, it has to be a ConstantExpr or CastExpr, initializing array eleemnt
     372                                // otherwise, it has to be a ConstantExpr or CastExpr, initializing array element
    350373                                output << "[";
    351374                                des->accept( *visitor );
     
    661684                        output << opInfo->symbol;
    662685                } else {
     686                        // if (dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())
     687                        // && dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base) {
     688                        //      output << '(' <<genType(dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base, "", options) << ')';
     689                        // }
    663690                        output << mangleName( variableExpr->get_var() );
    664691                } // if
  • src/CodeGen/GenType.cc

    r6256891 r92538ab  
    253253
    254254        void GenType::postvisit( EnumInstType * enumInst ) {
    255                 typeString = enumInst->name + " " + typeString;
    256                 if ( options.genC ) typeString = "enum " + typeString;
     255                if ( enumInst->baseEnum->base
     256                && dynamic_cast<BasicType *>(enumInst->baseEnum->base)
     257                && dynamic_cast<BasicType *>(enumInst->baseEnum->base)->kind != BasicType::Kind::SignedInt) {
     258                        typeString = genType(enumInst->baseEnum->base, "", options) + typeString;
     259                } else {
     260                        typeString = enumInst->name + " " + typeString;
     261                        if ( options.genC ) {
     262                                typeString = "enum " + typeString;
     263                        }
     264                }
    257265                handleQualifiers( enumInst );
    258266        }
  • src/Common/Eval.cc

    r6256891 r92538ab  
    112112        }
    113113
    114         void postvisit( const ast::VariableExpr * expr ) {
     114        void postvisit( const ast::VariableExpr * expr ) { // No hit
    115115                if ( const ast::EnumInstType * inst = dynamic_cast<const ast::EnumInstType *>(expr->result.get()) ) {
    116116                        if ( const ast::EnumDecl * decl = inst->base ) {
  • src/Common/PassVisitor.impl.h

    r6256891 r92538ab  
    754754
    755755        // unlike structs, traits, and unions, enums inject their members into the global scope
     756        // if ( node->base ) maybeAccept_impl( node->base, *this ); // Need this? Maybe not?
    756757        maybeAccept_impl( node->parameters, *this );
    757758        maybeAccept_impl( node->members   , *this );
  • src/Parser/DeclarationNode.cc

    r6256891 r92538ab  
    7878        delete variable.initializer;
    7979
    80         delete type;
     80//      delete type;
    8181        delete bitfieldWidth;
    8282
     
    253253} // DeclarationNode::newAggregate
    254254
    255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body ) {
     255DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed) {
    256256        DeclarationNode * newnode = new DeclarationNode;
    257257        newnode->type = new TypeData( TypeData::Enum );
     
    263263} // DeclarationNode::newEnum
    264264
     265
     266
    265267DeclarationNode * DeclarationNode::newName( const string * name ) {
    266268        DeclarationNode * newnode = new DeclarationNode;
     
    270272} // DeclarationNode::newName
    271273
    272 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) {
     274DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) { // Marker
    273275        DeclarationNode * newnode = newName( name );
    274276        newnode->enumeratorValue.reset( constant );
     
    665667}
    666668
     669DeclarationNode * DeclarationNode::addEnumBase( DeclarationNode * o ) {
     670        if ( o && o -> type)  {
     671                type->base= o->type;
     672        }
     673        delete o;
     674        return this;
     675}
     676
    667677DeclarationNode * DeclarationNode::addTypedef() {
    668678        TypeData * newtype = new TypeData( TypeData::Symbolic );
  • src/Parser/ParseNode.h

    r6256891 r92538ab  
    235235        static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
    236236        static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    237         static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body );
     237        static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed );
    238238        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    239239        static DeclarationNode * newName( const std::string * );
     
    265265        DeclarationNode * addType( DeclarationNode * );
    266266        DeclarationNode * addTypedef();
     267        DeclarationNode * addEnumBase( DeclarationNode * );
    267268        DeclarationNode * addAssertions( DeclarationNode * );
    268269        DeclarationNode * addName( std::string * );
  • src/Parser/StatementNode.cc

    r6256891 r92538ab  
    366366} // maybe_build_compound
    367367
     368// Question
    368369Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) {
    369370        list< Expression * > out, in;
  • src/Parser/TypeData.cc

    r6256891 r92538ab  
    918918EnumDecl * buildEnum( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) {
    919919        assert( td->kind == TypeData::Enum );
    920         EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage );
     920        Type * baseType = td->base ? typebuild(td->base) : nullptr;
     921        EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage, baseType );
    921922        buildList( td->enumeration.constants, ret->get_members() );
    922923        list< Declaration * >::iterator members = ret->get_members().begin();
    923         for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
     924        for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
    924925                if ( cur->has_enumeratorValue() ) {
    925926                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
    926927                        member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) );
     928                } else {
     929                        if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) {
     930                                SemanticError( td->location, "A non whole number enum value decl must be explicitly initialized." );
     931                        }
    927932                } // if
    928933        } // for
    929         ret->set_body( td->enumeration.body );
     934        ret->set_body( td->enumeration.body ); // Boolean; if it has body
    930935        return ret;
    931936} // buildEnum
  • src/Parser/TypeData.h

    r6256891 r92538ab  
    132132                                                 Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() );
    133133FunctionType * buildFunction( const TypeData * );
     134Declaration * addEnumBase( Declaration *, const TypeData * );
    134135void buildKRFunction( const TypeData::Function_t & function );
    135136
  • src/Parser/parser.yy

    r6256891 r92538ab  
    23032303        ;
    23042304
    2305 enum_type:                                                                                              // enum
     2305enum_type: // static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed );                                                                                         // enum
    23062306        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    2307                 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
     2307                { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); }
    23082308        | ENUM attribute_list_opt identifier
    23092309                { typedefTable.makeTypedef( *$3 ); }
    23102310          '{' enumerator_list comma_opt '}'
    2311                 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
     2311                { $$ = DeclarationNode::newEnum( $3, $6, true, false )->addQualifiers( $2 ); }
    23122312        | ENUM attribute_list_opt typedef_name                          // unqualified type name
    23132313          '{' enumerator_list comma_opt '}'
    2314                 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }
     2314                { $$ = DeclarationNode::newEnum( $3->name, $5, true, false )->addQualifiers( $2 ); }
    23152315        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    23162316                {
    2317                         if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    2318                         SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
    2319                 }
    2320         | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
     2317                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 )
     2318                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     2319                        // SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
     2320
     2321                        $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 )  -> addEnumBase( $3 );
     2322                        // $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 );
     2323                }
     2324        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier
    23212325                {
    23222326                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     
    23252329          '{' enumerator_list comma_opt '}'
    23262330                {
    2327                         SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
     2331                        $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
     2332                        // $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
    23282333                }
    23292334        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
     
    23312336                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    23322337                        typedefTable.makeTypedef( *$6->name );
    2333                         SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
     2338                        $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
     2339                        // $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
    23342340                }
    23352341        | enum_type_nobody
     
    23382344enum_type_nobody:                                                                               // enum - {...}
    23392345        ENUM attribute_list_opt identifier
    2340                 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); }
     2346                { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false, false )->addQualifiers( $2 ); }
    23412347        | ENUM attribute_list_opt type_name                                     // qualified type name
    2342                 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); }
     2348                { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false, false )->addQualifiers( $2 ); }
    23432349        ;
    23442350
  • src/ResolvExpr/ConversionCost.cc

    r6256891 r92538ab  
    333333                } else if ( dynamic_cast< const EnumInstType * >( dest ) ) {
    334334                        // xxx - not positive this is correct, but appears to allow casting int => enum
    335                         cost = Cost::unsafe;
     335                        // TODO
     336                        EnumDecl * decl = dynamic_cast< const EnumInstType * >( dest )->baseEnum;
     337                        if ( decl->base ) {
     338                                cost = Cost::infinity;
     339                        } else {
     340                                cost = Cost::unsafe;
     341                        } // if
    336342                } // if
    337343                // no cases for zero_t/one_t because it should not be possible to convert int, etc. to zero_t/one_t.
     
    610616        } else if ( dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    611617                // xxx - not positive this is correct, but appears to allow casting int => enum
    612                 cost = Cost::unsafe;
     618                const ast::EnumDecl * decl = (dynamic_cast< const ast::EnumInstType * >( dst ))->base.get();
     619                if ( decl->base ) {
     620                        cost = Cost::infinity;
     621                } else {
     622                        cost = Cost::unsafe;
     623                } // if
    613624        }
    614625}
  • src/ResolvExpr/Resolver.cc

    r6256891 r92538ab  
    14761476                        // enumerator initializers should not use the enum type to initialize, since the
    14771477                        // enum type is still incomplete at this point. Use `int` instead.
    1478                         objectDecl = fixObjectType(objectDecl, context);
    1479                         currentObject = ast::CurrentObject{
    1480                                 objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
     1478
     1479                        if (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base) { // const ast::PointerType &
     1480                                const ast::Type * enumBase =  (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base.get());
     1481                                const ast::PointerType * enumBaseAsPtr = dynamic_cast<const ast::PointerType *>(enumBase);
     1482
     1483                                if ( enumBaseAsPtr ) {
     1484                                        const ast::Type * pointerBase = enumBaseAsPtr->base.get();
     1485                                        if ( dynamic_cast<const ast::BasicType *>(pointerBase) ) {
     1486                                                objectDecl = fixObjectType(objectDecl, symtab);
     1487                                                if (dynamic_cast<const ast::BasicType *>(pointerBase)->kind == ast::BasicType::Char)
     1488                                                currentObject = ast::CurrentObject{
     1489                                                        objectDecl->location,  new ast::PointerType{
     1490                                                                new ast::BasicType{ ast::BasicType::Char }
     1491                                                        } };
     1492                                        } else {
     1493                                                objectDecl = fixObjectType(objectDecl, symtab);
     1494                                                currentObject = ast::CurrentObject{objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
     1495                                        }
     1496                                }
     1497                        } else {
     1498                                objectDecl = fixObjectType(objectDecl, symtab);
     1499                                currentObject = ast::CurrentObject{
     1500                                        objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
     1501                        }
     1502
    14811503                }
    14821504                else {
  • src/SymTab/Validate.cc

    r6256891 r92538ab  
    974974                                        // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information.
    975975                                        SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init );
    976                                         ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
     976                                        if ( !enumDecl->base || dynamic_cast<BasicType *>(enumDecl->base))
     977                                                ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
     978                                        else {
     979                                                if (dynamic_cast<PointerType *>(enumDecl->base)) {
     980                                                        auto typePtr = dynamic_cast<PointerType *>(enumDecl->base);
     981                                                        ResolvExpr::findSingleExpression( init->value,
     982                                                         new PointerType( Type::Qualifiers(), typePtr->base ), indexer );
     983                                                } else {
     984                                                        ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
     985                                                }
     986                                        }
     987                                       
    977988                                }
    978989                        }
     990
    979991                } // if
    980992        }
     
    12401252                        declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) );
    12411253                } else if ( EnumInstType * enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
    1242                         declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) );
     1254                        // declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) );
     1255                        if (enumDecl->baseEnum) {
     1256                                declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) );
     1257                        } else {
     1258                                declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) );
     1259                        }
    12431260                } // if
    12441261                return tyDecl->clone();
  • src/SynTree/AggregateDecl.cc

    r6256891 r92538ab  
    5959        } // if
    6060        os << " with body " << has_body();
    61 
    6261        if ( ! parameters.empty() ) {
    6362                os << endl << indent << "... with parameters" << endl;
     
    106105const char * EnumDecl::typeString() const { return aggrString( Enum ); }
    107106
     107void EnumDecl::print( std::ostream & os, Indenter indent ) const {
     108        AggregateDecl::print(os, indent);
     109        os << " with base? " << (base? "True" : "False") << std::endl;
     110        if ( base ) {
     111                os << "Base Type of Enum:" << std::endl;
     112                base->print(os, indent);
     113        }
     114        os <<  std::endl << "End of EnumDecl::print" << std::endl;
     115}
     116
    108117const char * TraitDecl::typeString() const { return aggrString( Trait ); }
    109118
  • src/SynTree/BasicType.cc

    r6256891 r92538ab  
    2929}
    3030
     31bool BasicType::isWholeNumber() const {
     32        return kind == Bool ||
     33                kind ==Char ||
     34                kind == SignedChar ||
     35                kind == UnsignedChar ||
     36                kind == ShortSignedInt ||
     37                kind == ShortUnsignedInt ||
     38                kind == SignedInt ||
     39                kind == UnsignedInt ||
     40                kind == LongSignedInt ||
     41                kind == LongUnsignedInt ||
     42                kind == LongLongSignedInt ||
     43                kind ==LongLongUnsignedInt ||
     44                kind == SignedInt128 ||
     45                kind == UnsignedInt128;
     46}
     47
    3148bool BasicType::isInteger() const {
    3249        return kind <= UnsignedInt128;
  • src/SynTree/Declaration.h

    r6256891 r92538ab  
    144144        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    145145        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
     146
     147        // TODO: Move to the right place
     148        void checkAssignedValue() const;
    146149};
    147150
     
    287290        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
    288291
    289         virtual void print( std::ostream & os, Indenter indent = {} ) const override final;
     292        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    290293        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    291294  protected:
     
    335338        typedef AggregateDecl Parent;
    336339  public:
    337         EnumDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}
    338         EnumDecl( const EnumDecl & other ) : Parent( other ) {}
     340        EnumDecl( const std::string & name,
     341         const std::list< Attribute * > & attributes = std::list< class Attribute * >(),
     342          LinkageSpec::Spec linkage = LinkageSpec::Cforall,
     343          Type * baseType = nullptr ) : Parent( name, attributes, linkage ) , base( baseType ){}
     344        EnumDecl( const EnumDecl & other ) : Parent( other ), base( other.base ) {}
    339345
    340346        bool valueOf( Declaration * enumerator, long long int & value );
     
    344350        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    345351        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    346   private:
     352        Type * base;
    347353        std::unordered_map< std::string, long long int > enumValues;
     354        virtual void print( std::ostream & os, Indenter indent = {} ) const override final;
     355  private:
     356        // std::unordered_map< std::string, long long int > enumValues;
    348357        virtual const char * typeString() const override;
    349358};
  • src/SynTree/Type.h

    r6256891 r92538ab  
    268268        virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); }
    269269        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    270 
     270        bool isWholeNumber() const;
    271271        bool isInteger() const;
    272272};
  • src/SynTree/Visitor.h

    r6256891 r92538ab  
    3535        virtual void visit( UnionDecl * node ) { visit( const_cast<const UnionDecl *>(node) ); }
    3636        virtual void visit( const UnionDecl * aggregateDecl ) = 0;
    37         virtual void visit( EnumDecl * node ) { visit( const_cast<const EnumDecl *>(node) ); }
     37        virtual void visit( EnumDecl * node ) { visit( const_cast<const EnumDecl *>(node) ); } // Marker 1
    3838        virtual void visit( const EnumDecl * aggregateDecl ) = 0;
    3939        virtual void visit( TraitDecl * node ) { visit( const_cast<const TraitDecl *>(node) ); }
     
    190190        virtual void visit( UnionInstType * node ) { visit( const_cast<const UnionInstType *>(node) ); }
    191191        virtual void visit( const UnionInstType * aggregateUseType ) = 0;
    192         virtual void visit( EnumInstType * node ) { visit( const_cast<const EnumInstType *>(node) ); }
     192        virtual void visit( EnumInstType * node ) { visit( const_cast<const EnumInstType *>(node) ); } // Marker 2
    193193        virtual void visit( const EnumInstType * aggregateUseType ) = 0;
    194194        virtual void visit( TraitInstType * node ) { visit( const_cast<const TraitInstType *>(node) ); }
Note: See TracChangeset for help on using the changeset viewer.