Changes in / [24ceace:4b4f95f]


Ignore:
Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r24ceace r4b4f95f  
    17301730        }
    17311731
    1732 
     1732        // Convert SynTree::EnumDecl to AST::EnumDecl
    17331733        virtual void visit( const EnumDecl * old ) override final {
    17341734                if ( inCache( old ) ) return;
  • src/Parser/DeclarationNode.cc

    r24ceace r4b4f95f  
    253253} // DeclarationNode::newAggregate
    254254
    255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, DeclarationNode * base) {
     255DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body) {
    256256        DeclarationNode * newnode = new DeclarationNode;
    257257        newnode->type = new TypeData( TypeData::Enum );
     
    260260        newnode->type->enumeration.body = body;
    261261        newnode->type->enumeration.anon = name == nullptr;
    262         if ( base && base->type)  {
    263                 newnode->type->base = base->type;       
    264         } // if
    265 
    266         // Check: if base has TypeData
    267262        return newnode;
    268263} // DeclarationNode::newEnum
     
    295290                return newName( name ); // Not explicitly inited enum value;
    296291        } // if
    297 } // DeclarationNode::newEnumValueGeneric
     292} // DeclarationNode::newEnumGeneric
    298293
    299294DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) {
  • src/Parser/ParseNode.h

    r24ceace r4b4f95f  
    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, DeclarationNode * base = nullptr );
     237        static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body );
    238238        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    239239        static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init );
  • src/Parser/TypeData.cc

    r24ceace r4b4f95f  
    388388                if ( enumeration.body ) {
    389389                        os << string( indent + 2, ' ' ) << " with body" << endl;
    390                 } // if
    391                 if ( base ) {
    392                         os << "for ";
    393                         base->print( os, indent + 2 );
    394390                } // if
    395391                break;
     
    930926                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
    931927                        member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) );
    932                 } else if ( !cur->initializer ) {
     928                } else {
    933929                        if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) {
    934930                                SemanticError( td->location, "A non whole number enum value decl must be explicitly initialized." );
    935931                        }
    936                 }
    937                 // else cur is a List Initializer and has been set as init in buildList()
    938                 // if
     932                } // if
    939933        } // for
    940         ret->set_body( td->enumeration.body );
     934        ret->set_body( td->enumeration.body ); // Boolean; if it has body
    941935        return ret;
    942936} // buildEnum
  • src/Parser/parser.yy

    r24ceace r4b4f95f  
    23032303        ;
    23042304
    2305 enum_type:
     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 '}'
    23072307                { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
     
    23182318                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    23192319
    2320                         $$ = DeclarationNode::newEnum( nullptr, $7, true, $3 ) ->addQualifiers( $5 );
    2321                 }
    2322         | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
     2320                        $$ = DeclarationNode::newEnum( nullptr, $7, true ) ->addQualifiers( $5 )  -> addEnumBase( $3 );
     2321                }
     2322        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier
    23232323                {
    23242324                        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." ); }
     
    23272327          '{' enumerator_list comma_opt '}'
    23282328                {
    2329                         $$ = DeclarationNode::newEnum( $6, $10, true, $3 ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
     2329                        $$ = DeclarationNode::newEnum( $6, $10, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
    23302330                }
    23312331        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
     
    23332333                        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." ); }
    23342334                        typedefTable.makeTypedef( *$6->name );
    2335                         $$ = DeclarationNode::newEnum( $6->name, $9, true, $3 ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
     2335                        $$ = DeclarationNode::newEnum( $6->name, $9, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
    23362336                }
    23372337        | enum_type_nobody
  • src/ResolvExpr/Resolver.cc

    r24ceace r4b4f95f  
    427427                        // enumerator initializers should not use the enum type to initialize, since
    428428                        // the enum type is still incomplete at this point. Use signed int instead.
    429                         // TODO: BasicType::SignedInt may not longer be true
    430429                        currentObject = CurrentObject( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
    431430                }
     
    14781477                        // enum type is still incomplete at this point. Use `int` instead.
    14791478
    1480                         if (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base) {
     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, context);
     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, context);
     1494                                //              currentObject = ast::CurrentObject{objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
     1495                                //      }
     1496                                // }
    14811497                                objectDecl = fixObjectType( objectDecl, context );
    14821498                                const ast::Type * enumBase =  (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base.get());
  • src/SymTab/Validate.cc

    r24ceace r4b4f95f  
    765765                } // if
    766766        }
     767
    767768        void LinkReferenceToTypes_old::postvisit( StructInstType * structInst ) {
    768769                const StructDecl * st = local_indexer->lookupStruct( structInst->name );
     
    890891        void LinkReferenceToTypes_old::postvisit( EnumDecl * enumDecl ) {
    891892                // visit enum members first so that the types of self-referencing members are updated properly
    892                 // Replace the enum base; right now it works only for StructEnum
    893                 if ( enumDecl->base && dynamic_cast<TypeInstType*>(enumDecl->base) ) {
    894                         std::string baseName = static_cast<TypeInstType*>(enumDecl->base)->name;
    895                         const StructDecl * st = local_indexer->lookupStruct( baseName );
    896                         if ( st ) {
    897                                 enumDecl->base = new StructInstType(Type::Qualifiers(),const_cast<StructDecl *>(st)); // Just linking in the node
    898                         }
    899                 }
    900893                if ( enumDecl->body ) {
    901894                        ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->name );
Note: See TracChangeset for help on using the changeset viewer.