Changeset d191e24 for src


Ignore:
Timestamp:
Oct 19, 2022, 5:29:12 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
bc899d6
Parents:
82ff4ed1 (diff), 058ece2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r82ff4ed1 rd191e24  
    310310                        node->name,
    311311                        get<Attribute>().acceptL( node->attributes ),
    312                         false, // Temporary
     312                        node->isTyped,
    313313                        LinkageSpec::Spec( node->linkage.val ),
    314314                        get<Type>().accept1(node->base)
    315315                );
    316                 return aggregatePostamble( decl, node ); // Node info, including members, processed in aggregatePostamble
     316                return aggregatePostamble( decl, node );
    317317        }
    318318
     
    737737                                node->name
    738738                );
    739                 temp->var = get<DeclarationWithType>().accept1(node->var);
    740739                auto expr = visitBaseExpr( node,
    741740                        temp
     
    16151614                        { old->get_funcSpec().val }
    16161615                );
     1616                decl->enumInLine = old->enumInLine;
    16171617                cache.emplace(old, decl);
    16181618                assert(cache.find( old ) != cache.end());
     
    22812281        }
    22822282
    2283         /// xxx - type_decl should be DeclWithType in the final design
    2284         /// type_decl is set to EnumDecl as a temporary fix
    22852283        virtual void visit( const QualifiedNameExpr * old ) override final {
    22862284                this->node = visitBaseExpr( old,
     
    22882286                                old->location,
    22892287                                GET_ACCEPT_1(type_decl, Decl),
    2290                                 GET_ACCEPT_1(var, DeclWithType),
    22912288                                old->name
    22922289                        )
  • src/AST/Decl.hpp

    r82ff4ed1 rd191e24  
    105105        ptr<Init> init;
    106106        ptr<Expr> bitfieldWidth;
     107        bool enumInLine = false; // enum inline is not a real object declaration.
     108        // It is a place holder for a set of enum value (ObjectDecl)
     109        bool importValue = false; // if the value copied from somewhere else
    107110
    108111        ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type,
     
    312315class EnumDecl final : public AggregateDecl {
    313316public:
    314         bool isTyped;
    315         ptr<Type> base;
     317        bool isTyped; // isTyped indicated if the enum has a declaration like:
     318        // enum (type_optional) Name {...}
     319        ptr<Type> base; // if isTyped == true && base.get() == nullptr, it is a "void" type enum
    316320
    317321        EnumDecl( const CodeLocation& loc, const std::string& name, bool isTyped = false,
  • src/AST/Expr.hpp

    r82ff4ed1 rd191e24  
    257257public:
    258258        ptr<Decl> type_decl;
    259         ptr<DeclWithType> var;
    260259        std::string name;
    261260
    262         QualifiedNameExpr( const CodeLocation & loc, const Decl * d, const DeclWithType * r, const std::string & n )
    263         : Expr( loc ), type_decl( d ), var(r), name( n ) {}
     261        QualifiedNameExpr( const CodeLocation & loc, const Decl * d, const std::string & n )
     262        : Expr( loc ), type_decl( d ), name( n ) {}
    264263
    265264        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/Pass.impl.hpp

    r82ff4ed1 rd191e24  
    12051205        if ( __visit_children() ) {
    12061206                guard_symtab guard { *this };
    1207                 maybe_accept( node, &QualifiedNameExpr::var );
    12081207                maybe_accept( node, &QualifiedNameExpr::type_decl );
    12091208        }
  • src/CodeGen/CodeGenerator.cc

    r82ff4ed1 rd191e24  
    912912                }
    913913                output << ")";
    914         }
    915 
    916         // QualifiedNameExpr should not reach to CodeGen.
    917         // FixQualifiedName Convert QualifiedNameExpr to VariableExpr
    918         void CodeGenerator::postvisit( QualifiedNameExpr * expr ) {
    919                 output << "/* label */" << mangleName(expr->var);
    920914        }
    921915
  • src/CodeGen/CodeGenerator.h

    r82ff4ed1 rd191e24  
    103103                void postvisit( DefaultArgExpr * );
    104104                void postvisit( GenericExpr * );
    105                 void postvisit( QualifiedNameExpr *);
    106105
    107106                //*** Statements
  • src/Common/PassVisitor.impl.h

    r82ff4ed1 rd191e24  
    19341934        indexerScopedAccept( node->result, *this );
    19351935        maybeAccept_impl( node->type_decl, *this );
    1936         maybeAccept_impl( node->var, *this );
    19371936
    19381937        VISIT_END( node );
     
    19451944        indexerScopedAccept( node->result, *this );
    19461945        maybeAccept_impl( node->type_decl, *this );
    1947         maybeAccept_impl( node->var, *this );
    19481946
    19491947        VISIT_END( node );
     
    19571955    indexerScopedMutate( node->result, *this );
    19581956        maybeMutate_impl( node->type_decl, *this );
    1959         maybeAccept_impl( node->var, *this );
    19601957
    19611958        MUTATE_END( Expression, node );
  • src/Parser/DeclarationNode.cc

    r82ff4ed1 rd191e24  
    297297        } // if
    298298} // DeclarationNode::newEnumValueGeneric
     299
     300DeclarationNode * DeclarationNode::newEnumInLine( const string name ) {
     301        DeclarationNode * newnode = newName( new std::string(name) );
     302        newnode->enumInLine = true;
     303        return newnode;
     304}
    299305
    300306DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) {
  • src/Parser/ExpressionNode.cc

    r82ff4ed1 rd191e24  
    523523                auto enumInst = new EnumInstType( Type::Qualifiers(), e );
    524524                auto obj = new ObjectDecl( name->name, Type::StorageClasses(), LinkageSpec::Cforall, nullptr, enumInst, nullptr );
    525                 ret->set_var( obj );
    526525        }
    527526        return ret;
  • src/Parser/ParseNode.h

    r82ff4ed1 rd191e24  
    240240        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    241241        static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init );
     242        static DeclarationNode * newEnumInLine( const std::string name );
    242243        static DeclarationNode * newName( const std::string * );
    243244        static DeclarationNode * newFromTypeGen( const std::string *, ExpressionNode * params );
     
    339340
    340341        bool inLine = false;
     342        bool enumInLine = false;
    341343        Type::FuncSpecifiers funcSpecs;
    342344        Type::StorageClasses storageClasses;
  • src/Parser/TypeData.cc

    r82ff4ed1 rd191e24  
    924924        list< Declaration * >::iterator members = ret->get_members().begin();
    925925        for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
     926                if ( cur->enumInLine ) {
     927                        // Tell the compiler this is a inline value placeholder
     928                        ObjectDecl * member = dynamic_cast< ObjectDecl* >(* members);
     929                        member->enumInLine = true;
     930                }
    926931                if ( ret->isTyped && !ret->base && cur->has_enumeratorValue() ) {
    927932                        SemanticError( td->location, "Enumerator of enum(void) cannot have an explicit initializer value." );
  • src/Parser/parser.yy

    r82ff4ed1 rd191e24  
    26052605                { $$ = DeclarationNode::newEnumValueGeneric( $1, $2 ); }
    26062606        | INLINE type_name
    2607                 { $$ = DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ); }
     2607                { $$ = DeclarationNode::newEnumInLine( *$2->type->symbolic.name ); }
    26082608        | enumerator_list ',' identifier_or_type_name enumerator_value_opt
    26092609                { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( $3, $4 ) ); }
  • src/ResolvExpr/CandidateFinder.cpp

    r82ff4ed1 rd191e24  
    862862                                }
    863863                        }
    864                 }
    865 
    866                 void postvisit( const ast::QualifiedNameExpr * qualifiedNameExpr ) {
    867                         auto mangleName = Mangle::mangle(qualifiedNameExpr->var);
    868                         addCandidate( qualifiedNameExpr, tenv );
    869864                }
    870865
  • src/SymTab/Mangler.cc

    r82ff4ed1 rd191e24  
    6565                                void postvisit( const QualifiedType * qualType );
    6666
    67                                 void postvisit( const QualifiedNameExpr * qualNameExpr );
    68 
    6967                                std::string get_mangleName() { return mangleName; }
    7068                          private:
     
    307305                                        mangleName += Encoding::qualifiedTypeEnd;
    308306                                }
    309                         }
    310 
    311                         void Mangler_old::postvisit( const QualifiedNameExpr * qual ) {
    312                                 maybeAccept( qual->var, *visitor );
    313307                        }
    314308
     
    423417                        void postvisit( const ast::OneType * oneType );
    424418                        void postvisit( const ast::QualifiedType * qualType );
    425                         void postvisit( const ast::QualifiedNameExpr * qualNameExpr );
    426419
    427420                        std::string get_mangleName() { return mangleName; }
     
    652645                                mangleName += Encoding::qualifiedTypeEnd;
    653646                        }
    654                 }
    655                 void Mangler_new::postvisit( const ast::QualifiedNameExpr * qual ) {
    656                         maybeAccept( qual->var.get(), *visitor );
    657647                }
    658648
  • src/SymTab/Validate.cc

    r82ff4ed1 rd191e24  
    858858                        declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) );
    859859                } else if ( EnumInstType * enumInst = dynamic_cast< EnumInstType * >( designatorType ) ) {
    860                         // declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) );
    861860                        if ( enumInst->baseEnum ) {
    862861                                const EnumDecl * enumDecl = enumInst->baseEnum;
  • src/SymTab/ValidateType.cc

    r82ff4ed1 rd191e24  
    8181        void previsit( QualifiedType * qualType );
    8282        void postvisit( QualifiedType * qualType );
    83 
    8483        void postvisit( QualifiedNameExpr * qualExpr );
    85 
     84       
    8685        void postvisit( EnumDecl * enumDecl );
    8786        void postvisit( StructDecl * structDecl );
  • src/SynTree/AddressExpr.cc

    r82ff4ed1 rd191e24  
    5050                                set_result( addrType( refType->base ) );
    5151                        } else {
     52                                if(!arg->result->location.isSet()) arg->result->location = arg->location;
    5253                                SemanticError( arg->result, "Attempt to take address of non-lvalue expression: " );
    5354                        } // if
  • src/SynTree/Declaration.h

    r82ff4ed1 rd191e24  
    121121        Initializer * init;
    122122        Expression * bitfieldWidth;
     123        bool enumInLine = false;
    123124
    124125        ObjectDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression * bitfieldWidth, Type * type, Initializer * init,
  • src/SynTree/Expression.h

    r82ff4ed1 rd191e24  
    168168        Declaration * type_decl;
    169169        std::string name;
    170         DeclarationWithType * var;
    171170
    172171        QualifiedNameExpr( Declaration * decl, std::string name): Expression(), type_decl(decl), name(name) {}
    173         QualifiedNameExpr( const QualifiedNameExpr & other): Expression(other), type_decl(other.type_decl), name(other.name), var(other.var) {}
    174         DeclarationWithType * get_var() const { return var; }
    175         void set_var( DeclarationWithType * newValue ) { var = newValue; }
     172        QualifiedNameExpr( const QualifiedNameExpr & other): Expression(other), type_decl(other.type_decl), name(other.name) {}
    176173
    177174        virtual ~QualifiedNameExpr() {
    178                 delete var;
    179175                delete type_decl;
    180176        }
  • src/Validate/FixQualifiedTypes.cpp

    r82ff4ed1 rd191e24  
    102102                        }
    103103
    104 
    105                 auto var = new ast::ObjectDecl( t->var->location, t->name,
    106                          new ast::EnumInstType(enumDecl, ast::CV::Const), nullptr, {}, ast::Linkage::Cforall );
    107                         var->scopeLevel = 1; // 1 for now; should copy the scopeLevel of the enumValue
     104                auto var = new ast::ObjectDecl( t->location, t->name,
     105                        new ast::EnumInstType(enumDecl, ast::CV::Const), nullptr, {}, ast::Linkage::Cforall );
    108106                        var->mangleName = Mangle::mangle( var );
    109107                        return new ast::VariableExpr( t->location, var );
    110                 // return ret;
    111108        }
    112109
  • src/Validate/LinkReferenceToTypes.cpp

    r82ff4ed1 rd191e24  
    4444        void postvisit( ast::UnionDecl const * decl );
    4545        ast::TraitDecl const * postvisit( ast::TraitDecl const * decl );
    46         ast::QualifiedNameExpr const * previsit( ast::QualifiedNameExpr const * decl);
    4746
    4847private:
     
    203202        }
    204203
     204        // The following section
     205        auto mut = ast::mutate( decl );
     206        std::vector<ast::ptr<ast::Decl>> buffer;
     207        for ( auto it = decl->members.begin(); it != decl->members.end(); ++it) {
     208                auto member = (*it).as<ast::ObjectDecl>();
     209                if ( member->enumInLine ) {
     210                        auto targetEnum = symtab.lookupEnum( member->name );
     211                        if ( targetEnum ) {                     
     212                                for ( auto singleMamber : targetEnum->members ) {
     213                                        auto tm = singleMamber.as<ast::ObjectDecl>();
     214                                        auto t = new ast::ObjectDecl(
     215                                                member->location, // use the "inline" location
     216                                                tm->name,
     217                                                new ast::EnumInstType( decl, ast::CV::Const ),
     218                                                // Construct a new EnumInstType as the type
     219                                                tm->init,
     220                                                tm->storage,
     221                                                tm->linkage,
     222                                                tm->bitfieldWidth,
     223                                                {}, // enum member doesn't have attribute
     224                                                tm->funcSpec
     225                                        );
     226                                        t->importValue = true;
     227                                        buffer.push_back(t);
     228                                }
     229                        }
     230                } else {
     231                        auto search_it = std::find_if( buffer.begin(), buffer.end(), [member](ast::ptr<ast::Decl> cur) {
     232                                auto curAsObjDecl = cur.as<ast::ObjectDecl>();
     233                                return (curAsObjDecl->importValue) && (curAsObjDecl->name == member->name);
     234                        });
     235                        if ( search_it != buffer.end() ) {
     236                                buffer.erase( search_it ); // Found an import enum value that has the same name
     237                                // override the imported value
     238                        }
     239                        buffer.push_back( *it );
     240                }
     241        }
     242        mut->members = buffer;
     243        decl = mut;
     244
    205245        ForwardEnumsType::iterator fwds = forwardEnums.find( decl->name );
    206246        if ( fwds != forwardEnums.end() ) {
     
    284324}
    285325
    286 ast::QualifiedNameExpr const * LinkTypesCore::previsit( ast::QualifiedNameExpr const * decl ) {
    287         // Try to lookup type
    288         if ( auto objDecl = decl->type_decl.as<ast::ObjectDecl>() ) {
    289                 if ( auto inst = objDecl->type.as<ast::TypeInstType>()) {
    290                         if ( auto enumDecl = symtab.lookupEnum ( inst->name ) ) {
    291                                 auto mut = ast::mutate( decl );
    292                                 mut->type_decl = enumDecl;
    293                                 auto enumInst = new ast::EnumInstType( enumDecl );
    294                                 enumInst->name = decl->name;
    295                                 // Adding result; addCandidate() use result
    296                                 mut->result = enumInst;
    297                                 decl = mut;
    298                         }
    299                 }
    300         } else if ( auto enumDecl = decl->type_decl.as<ast::EnumDecl>() ) {
    301                 auto mut = ast::mutate( decl );
    302                 auto enumInst = new ast::EnumInstType( enumDecl );
    303                 enumInst->name = decl->name;
    304                 // Adding result; addCandidate() use result
    305                 mut->result = enumInst;
    306                 decl = mut;
    307         }
    308         // ast::EnumDecl const * decl = symtab.lookupEnum( type->name );
    309         // // It's not a semantic error if the enum is not found, just an implicit forward declaration.
    310         // if ( decl ) {
    311         //      // Just linking in the node.
    312         //      auto mut = ast::mutate( type );
    313         //      mut->base = const_cast<ast::EnumDecl *>( decl );
    314         //      type = mut;
    315         // }
    316         return decl;
    317 }
    318 
    319326} // namespace
    320327
Note: See TracChangeset for help on using the changeset viewer.