Changeset f135b50 for src/Parser


Ignore:
Timestamp:
Feb 28, 2022, 3:41:44 AM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
786c438
Parents:
a8ef59e
Message:

The compiler is now trying to pass the value of enum const to code gen; but it won't work cause we must be able to evaluate the const_expr in compiler time. It is not currently passed as a Expression but won't be able to evaluate at compile time

Location:
src/Parser
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    ra8ef59e rf135b50  
    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, bool ) {
     255DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed) {
    256256        DeclarationNode * newnode = new DeclarationNode;
    257257        newnode->type = new TypeData( TypeData::Enum );
     
    272272} // DeclarationNode::newName
    273273
    274 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) {
     274DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) { // Marker
    275275        DeclarationNode * newnode = newName( name );
    276276        newnode->enumeratorValue.reset( constant );
     
    667667}
    668668
     669DeclarationNode * DeclarationNode::addEnumBase( DeclarationNode * o ) {
     670        if ( o && o -> type)  {
     671                type->base= o->type;
     672        }
     673        delete o;
     674        return this;
     675}
     676
    669677DeclarationNode * DeclarationNode::addTypedef() {
    670678        TypeData * newtype = new TypeData( TypeData::Symbolic );
  • src/Parser/ParseNode.h

    ra8ef59e rf135b50  
    265265        DeclarationNode * addType( DeclarationNode * );
    266266        DeclarationNode * addTypedef();
     267        DeclarationNode * addEnumBase( DeclarationNode * );
    267268        DeclarationNode * addAssertions( DeclarationNode * );
    268269        DeclarationNode * addName( std::string * );
  • src/Parser/StatementNode.cc

    ra8ef59e rf135b50  
    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

    ra8ef59e rf135b50  
    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 );
    921         buildList( td->enumeration.constants, ret->get_members() );
     920        Type* baseType = td->base ? typebuild(td->base) : nullptr;
     921        EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage, baseType );
     922        buildList( td->enumeration.constants, ret->get_members() ); // enumConstant is both a node and a list
    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);
     
    927928                } // if
    928929        } // for
    929         ret->set_body( td->enumeration.body );
     930        ret->set_body( td->enumeration.body ); // Boolean; if it has body
    930931        return ret;
    931932} // buildEnum
  • src/Parser/TypeData.h

    ra8ef59e rf135b50  
    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

    ra8ef59e rf135b50  
    22922292                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    22932293                        // SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
    2294                         $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 );
     2294
     2295                        $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 )  -> addEnumBase( $3 );
     2296                        // $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 );
    22952297                }
    22962298        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier
     
    23012303          '{' enumerator_list comma_opt '}'
    23022304                {
    2303                         $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
     2305                        $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
     2306                        // $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
    23042307                }
    23052308        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
     
    23072310                        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." ); }
    23082311                        typedefTable.makeTypedef( *$6->name );
    2309                         $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
     2312                        $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
     2313                        // $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
    23102314                }
    23112315        | enum_type_nobody
Note: See TracChangeset for help on using the changeset viewer.