Changes in / [a065f1f:ef1da0e2]


Ignore:
Files:
8 deleted
37 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    ra065f1f ref1da0e2  
    310310                        node->name,
    311311                        get<Attribute>().acceptL( node->attributes ),
    312                         false, // Temporary
    313312                        LinkageSpec::Spec( node->linkage.val ),
    314313                        get<Type>().accept1(node->base)
     
    732731        }
    733732
    734         const ast::Expr * visit( const ast::QualifiedNameExpr * node ) override final {
    735                 auto temp = new QualifiedNameExpr(
    736                                 get<Declaration>().accept1(node->type_decl),
    737                                 node->name
    738                 );
    739                 temp->var = get<DeclarationWithType>().accept1(node->var);
    740                 auto expr = visitBaseExpr( node,
    741                         temp
    742                 );
    743                 this->node = expr;
    744                 return nullptr;
    745         }
    746 
    747733        const ast::Expr * visit( const ast::AddressExpr * node ) override final {
    748734                auto expr = visitBaseExpr( node,
     
    17541740                        old->location,
    17551741                        old->name,
    1756                         old->isTyped,
    17571742                        GET_ACCEPT_V(attributes, Attribute),
    17581743                        { old->linkage.val },
     
    22812266        }
    22822267
    2283         /// xxx - type_decl should be DeclWithType in the final design
    2284         /// type_decl is set to EnumDecl as a temporary fix
    2285         virtual void visit( const QualifiedNameExpr * old ) override final {
    2286                 this->node = visitBaseExpr( old,
    2287                         new ast::QualifiedNameExpr (
    2288                                 old->location,
    2289                                 GET_ACCEPT_1(type_decl, Decl),
    2290                                 GET_ACCEPT_1(var, DeclWithType),
    2291                                 old->name
    2292                         )
    2293                 );
    2294         }
    2295 
    22962268        virtual void visit( const CastExpr * old ) override final {
    22972269                this->node = visitBaseExpr( old,
  • src/AST/Decl.hpp

    ra065f1f ref1da0e2  
    312312class EnumDecl final : public AggregateDecl {
    313313public:
    314         bool isTyped;
    315314        ptr<Type> base;
    316315
    317         EnumDecl( const CodeLocation& loc, const std::string& name, bool isTyped = false,
    318                 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall,
    319                 Type const * base = nullptr,
     316        EnumDecl( const CodeLocation& loc, const std::string& name,
     317                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall, Type const * base = nullptr,
    320318                std::unordered_map< std::string, long long > enumValues = std::unordered_map< std::string, long long >() )
    321         : AggregateDecl( loc, name, std::move(attrs), linkage ), isTyped(isTyped), base(base), enumValues(enumValues) {}
     319        : AggregateDecl( loc, name, std::move(attrs), linkage ), base(base), enumValues(enumValues) {}
    322320
    323321        /// gets the integer value for this enumerator, returning true iff value found
     
    329327        const char * typeString() const override { return aggrString( Enum ); }
    330328
     329        bool isTyped() {return base && base.get();}
    331330
    332331private:
  • src/AST/Expr.hpp

    ra065f1f ref1da0e2  
    254254};
    255255
    256 class QualifiedNameExpr final : public Expr {
    257 public:
    258         ptr<Decl> type_decl;
    259         ptr<DeclWithType> var;
    260         std::string name;
    261 
    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 ) {}
    264 
    265         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    266 private:
    267         QualifiedNameExpr * clone() const override { return new QualifiedNameExpr{ *this }; }
    268         MUTATE_FRIEND
    269 };
    270 
    271256/// A reference to a named variable.
    272257class VariableExpr final : public Expr {
  • src/AST/Fwd.hpp

    ra065f1f ref1da0e2  
    6767class UntypedExpr;
    6868class NameExpr;
    69 class QualifiedNameExpr;
    7069class AddressExpr;
    7170class LabelAddressExpr;
  • src/AST/Pass.hpp

    ra065f1f ref1da0e2  
    167167        const ast::Expr *             visit( const ast::UntypedExpr          * ) override final;
    168168        const ast::Expr *             visit( const ast::NameExpr             * ) override final;
    169         const ast::Expr *                         visit( const ast::QualifiedNameExpr    * ) override final;
    170169        const ast::Expr *             visit( const ast::AddressExpr          * ) override final;
    171170        const ast::Expr *             visit( const ast::LabelAddressExpr     * ) override final;
  • src/AST/Pass.impl.hpp

    ra065f1f ref1da0e2  
    11991199
    12001200//--------------------------------------------------------------------------
    1201 // QualifiedNameExpr
    1202 template< typename core_t >
    1203 const ast::Expr * ast::Pass< core_t >::visit( const ast::QualifiedNameExpr * node ) {
    1204         VISIT_START( node );
    1205         if ( __visit_children() ) {
    1206                 guard_symtab guard { *this };
    1207                 maybe_accept( node, &QualifiedNameExpr::var );
    1208                 maybe_accept( node, &QualifiedNameExpr::type_decl );
    1209         }
    1210         VISIT_END( Expr, node );
    1211 }
    1212 
    1213 //--------------------------------------------------------------------------
    12141201// CastExpr
    12151202template< typename core_t >
  • src/AST/Print.cpp

    ra065f1f ref1da0e2  
    899899                postprint( node );
    900900
    901                 return node;
    902         }
    903 
    904         virtual const ast::Expr * visit( const ast::QualifiedNameExpr * node ) override final {
    905                 os << "QualifiedNameExpr: " << std::endl;
    906                 os << ++indent << "Type: ";
    907                 safe_print( node->type_decl );
    908                 os << std::endl;
    909                 os <<  indent << "Name: " << node->name  << std::endl;
    910                 --indent;
    911                 postprint( node );
    912901                return node;
    913902        }
  • src/AST/Visitor.hpp

    ra065f1f ref1da0e2  
    5959    virtual const ast::Expr *             visit( const ast::UntypedExpr          * ) = 0;
    6060    virtual const ast::Expr *             visit( const ast::NameExpr             * ) = 0;
    61     virtual const ast::Expr *             visit( const ast::QualifiedNameExpr    * ) = 0;
    6261    virtual const ast::Expr *             visit( const ast::AddressExpr          * ) = 0;
    6362    virtual const ast::Expr *             visit( const ast::LabelAddressExpr     * ) = 0;
  • src/CodeGen/CodeGenerator.cc

    ra065f1f ref1da0e2  
    277277                std::list< Declaration* > &memb = enumDecl->get_members();
    278278                if (enumDecl->base && ! memb.empty()) {
    279                         unsigned long long last_val = -1; // if the first enum value has no explicit initializer,
    280                         // as other
     279                        unsigned long long last_val = -1;
    281280                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    282281                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
     
    696695                        output << opInfo->symbol;
    697696                } else {
     697                        // if (dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())
     698                        // && dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base) {
     699                        //      output << '(' <<genType(dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base, "", options) << ')';
     700                        // }
    698701                        output << mangleName( variableExpr->get_var() );
    699702                } // if
     
    914917        }
    915918
    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);
    920         }
    921919
    922920        // *** Statements
  • src/CodeGen/CodeGenerator.h

    ra065f1f ref1da0e2  
    103103                void postvisit( DefaultArgExpr * );
    104104                void postvisit( GenericExpr * );
    105                 void postvisit( QualifiedNameExpr *);
    106105
    107106                //*** Statements
  • src/Common/CodeLocationTools.cpp

    ra065f1f ref1da0e2  
    137137    macro(UntypedExpr, Expr) \
    138138    macro(NameExpr, Expr) \
    139         macro(QualifiedNameExpr, Expr) \
    140139    macro(AddressExpr, Expr) \
    141140    macro(LabelAddressExpr, Expr) \
  • src/Common/PassVisitor.h

    ra065f1f ref1da0e2  
    133133        virtual void visit( NameExpr * nameExpr ) override final;
    134134        virtual void visit( const NameExpr * nameExpr ) override final;
    135         virtual void visit ( QualifiedNameExpr * qualifiedNameExpr ) override final;
    136         virtual void visit ( const QualifiedNameExpr * qualifiedNameExpr ) override final;
    137135        virtual void visit( CastExpr * castExpr ) override final;
    138136        virtual void visit( const CastExpr * castExpr ) override final;
     
    327325        virtual Expression * mutate( TupleExpr * tupleExpr ) override final;
    328326        virtual Expression * mutate( TupleIndexExpr * tupleExpr ) override final;
    329         virtual Expression * mutate( TupleAssignExpr * assignExpr ) override final; 
     327        virtual Expression * mutate( TupleAssignExpr * assignExpr ) override final;
    330328        virtual Expression * mutate( StmtExpr *  stmtExpr ) override final;
    331329        virtual Expression * mutate( UniqueExpr *  uniqueExpr ) override final;
     
    335333        virtual Expression * mutate( DefaultArgExpr * argExpr ) override final;
    336334        virtual Expression * mutate( GenericExpr * genExpr ) override final;
    337         virtual Expression * mutate( QualifiedNameExpr * qualifiedNameExpr ) override final;
    338335
    339336        virtual Type * mutate( VoidType * basicType ) override final;
  • src/Common/PassVisitor.impl.h

    ra065f1f ref1da0e2  
    19271927
    19281928//--------------------------------------------------------------------------
    1929 // QualifiedNameExpr
    1930 template< typename pass_type >
    1931 void PassVisitor< pass_type >::visit( QualifiedNameExpr * node ) {
    1932         VISIT_START( node );
    1933 
    1934         indexerScopedAccept( node->result, *this );
    1935         maybeAccept_impl( node->type_decl, *this );
    1936         maybeAccept_impl( node->var, *this );
    1937 
    1938         VISIT_END( node );
    1939 }
    1940 
    1941 template< typename pass_type >
    1942 void PassVisitor< pass_type >::visit( const QualifiedNameExpr * node ) {
    1943         VISIT_START( node );
    1944 
    1945         indexerScopedAccept( node->result, *this );
    1946         maybeAccept_impl( node->type_decl, *this );
    1947         maybeAccept_impl( node->var, *this );
    1948 
    1949         VISIT_END( node );
    1950 }
    1951 
    1952 template< typename pass_type >
    1953 Expression * PassVisitor< pass_type >::mutate( QualifiedNameExpr * node ) {
    1954         MUTATE_START( node );
    1955 
    1956     indexerScopedMutate( node->env   , *this );
    1957     indexerScopedMutate( node->result, *this );
    1958         maybeMutate_impl( node->type_decl, *this );
    1959         maybeAccept_impl( node->var, *this );
    1960 
    1961         MUTATE_END( Expression, node );
    1962 }
    1963 
    1964 //--------------------------------------------------------------------------
    19651929// CastExpr
    19661930template< typename pass_type >
  • src/Parser/DeclarationNode.cc

    ra065f1f ref1da0e2  
    254254} // DeclarationNode::newAggregate
    255255
    256 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base) {
     256DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, DeclarationNode * base) {
    257257        DeclarationNode * newnode = new DeclarationNode;
    258258        newnode->type = new TypeData( TypeData::Enum );
     
    261261        newnode->type->enumeration.body = body;
    262262        newnode->type->enumeration.anon = name == nullptr;
    263         newnode->type->enumeration.typed = typed;
    264263        if ( base && base->type)  {
    265264                newnode->type->base = base->type;
    266265        } // if
    267266
     267        // Check: if base has TypeData
    268268        return newnode;
    269269} // DeclarationNode::newEnum
     
    285285
    286286DeclarationNode * DeclarationNode::newEnumValueGeneric( const string * name, InitializerNode * init ) {
    287         if ( init ) {
    288                 if ( init->get_expression() ) {
     287        if ( init ) { // list init {} or a singleInit
     288                if ( init->get_expression() ) { // singleInit
    289289                        return newEnumConstant( name, init->get_expression() );
    290                 } else {
     290                } else { // TODO: listInit
    291291                        DeclarationNode * newnode = newName( name );
    292292                        newnode->initializer = init;
     
    294294                } // if
    295295        } else {
    296                 return newName( name );
     296                return newName( name ); // Not explicitly inited enum value;
    297297        } // if
    298298} // DeclarationNode::newEnumValueGeneric
  • src/Parser/ExpressionNode.cc

    ra065f1f ref1da0e2  
    509509} // build_varref
    510510
    511 QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name ) {
    512         Declaration * newDecl = maybeBuild< Declaration >(decl_node);
    513         if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) {
    514                 const Type * t = newDeclWithType->get_type();
    515                 if ( t ) {
    516                         if ( const TypeInstType * typeInst = dynamic_cast<const TypeInstType *>( t ) ) {
    517                                 newDecl= new EnumDecl( typeInst->name );
    518                         }
    519                 }
    520         }
    521         auto ret =  new QualifiedNameExpr( newDecl, name->name );
    522         if ( auto e = dynamic_cast<EnumDecl*>(newDecl) ) {
    523                 auto enumInst = new EnumInstType( Type::Qualifiers(), e );
    524                 auto obj = new ObjectDecl( name->name, Type::StorageClasses(), LinkageSpec::Cforall, nullptr, enumInst, nullptr );
    525                 ret->set_var( obj );
    526         }
    527         return ret;
    528 }
    529 
    530 QualifiedNameExpr * build_qualified_expr( const EnumDecl * decl_node, const NameExpr * name ) {
    531         EnumDecl * newDecl = const_cast< EnumDecl * >( decl_node );
    532         return new QualifiedNameExpr( newDecl, name->name );
    533 }
    534 
    535511DimensionExpr * build_dimensionref( const string * name ) {
    536512        DimensionExpr * expr = new DimensionExpr( *name );
  • src/Parser/ParseNode.h

    ra065f1f ref1da0e2  
    183183
    184184NameExpr * build_varref( const std::string * name );
    185 QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name );
    186 QualifiedNameExpr * build_qualified_expr( const EnumDecl * decl, const NameExpr * name );
    187185DimensionExpr * build_dimensionref( const std::string * name );
    188186
     
    237235        static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
    238236        static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    239         static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base = nullptr );
     237        static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, DeclarationNode * base = nullptr );
    240238        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
    241239        static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init );
  • src/Parser/TypeData.cc

    ra065f1f ref1da0e2  
    546546                return buildAggInst( td );
    547547          case TypeData::EnumConstant:
     548                // the name gets filled in later -- by SymTab::Validate
    548549                return new EnumInstType( buildQualifiers( td ), "" );
    549550          case TypeData::SymbolicInst:
     
    920921        assert( td->kind == TypeData::Enum );
    921922        Type * baseType = td->base ? typebuild(td->base) : nullptr;
    922         EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, td->enumeration.typed, linkage, baseType );
     923        EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage, baseType );
    923924        buildList( td->enumeration.constants, ret->get_members() );
    924925        list< Declaration * >::iterator members = ret->get_members().begin();
    925926        for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
    926                 if ( ret->isTyped && !ret->base && cur->has_enumeratorValue() ) {
    927                         SemanticError( td->location, "Enumerator of enum(void) cannot have an explicit initializer value." );
    928                 } else if ( cur->has_enumeratorValue() ) {
     927                if ( cur->has_enumeratorValue() ) {
    929928                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
    930929                        member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) );
    931930                } else if ( !cur->initializer ) {
    932931                        if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) {
    933                                 SemanticError( td->location, "Enumerators of an non-integer typed enum must be explicitly initialized." );
     932                                SemanticError( td->location, "A non whole number enum value decl must be explicitly initialized." );
    934933                        }
    935934                }
  • src/Parser/TypeData.h

    ra065f1f ref1da0e2  
    5959                bool body;
    6060                bool anon;
    61                 bool typed;
    6261        };
    6362
  • src/Parser/parser.yy

    ra065f1f ref1da0e2  
    637637                { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); }
    638638        | type_name '.' identifier                                                      // CFA, nested type
    639                 { $$ = new ExpressionNode( build_qualified_expr( $1, build_varref( $3 ) ) ); }
     639                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    640640        | type_name '.' '[' field_name_list ']'                         // CFA, nested type / tuple field selector
    641641                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     
    25382538enum_type:
    25392539        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    2540                 { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); }
     2540                { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
    25412541        | ENUM attribute_list_opt identifier
    25422542                { typedefTable.makeTypedef( *$3 ); }
    25432543          '{' enumerator_list comma_opt '}'
    2544                 { $$ = DeclarationNode::newEnum( $3, $6, true, false )->addQualifiers( $2 ); }
     2544                { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
    25452545        | ENUM attribute_list_opt typedef_name                          // unqualified type name
    25462546          '{' enumerator_list comma_opt '}'
    2547                 { $$ = DeclarationNode::newEnum( $3->name, $5, true, false )->addQualifiers( $2 ); }
     2547                { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }
     2548        | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'
     2549                { SemanticError( yylloc, "Unvalued enumerated type is currently unimplemented." ); $$ = nullptr; }
    25482550        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    25492551                {
     
    25512553                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    25522554
    2553                         $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 );
    2554                 }
    2555         | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    2556                 {
    2557                         $$ = DeclarationNode::newEnum( nullptr, $6, true, true )->addQualifiers( $4 );
     2555                        $$ = DeclarationNode::newEnum( nullptr, $7, true, $3 )->addQualifiers( $5 );
    25582556                }
    25592557        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
     
    25642562          '{' enumerator_list comma_opt '}'
    25652563                {
    2566                         $$ = DeclarationNode::newEnum( $6, $10, true, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
    2567                 }
    2568         | ENUM '(' ')' attribute_list_opt identifier attribute_list_opt
    2569           '{' enumerator_list comma_opt '}'
    2570                 {
    2571                         $$ = DeclarationNode::newEnum( $5, $8, true, true, nullptr )->addQualifiers( $4 )->addQualifiers( $6 );
    2572                 }       
     2564                        $$ = DeclarationNode::newEnum( $6, $10, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
     2565                }
    25732566        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
    25742567                {
    2575                         $$ = DeclarationNode::newEnum( $6->name, $9, true, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
    2576                 }
    2577         | ENUM '(' ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
    2578                 {
    2579                         $$ = DeclarationNode::newEnum( $5->name, $8, true, true, nullptr )->addQualifiers( $4 )->addQualifiers( $6 );
     2568                        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." ); }
     2569                        typedefTable.makeTypedef( *$6->name );
     2570                        $$ = DeclarationNode::newEnum( $6->name, $9, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 );
    25802571                }
    25812572        | enum_type_nobody
     
    25842575enum_type_nobody:                                                                               // enum - {...}
    25852576        ENUM attribute_list_opt identifier
    2586                 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false, false )->addQualifiers( $2 ); }
    2587         | ENUM attribute_list_opt type_name     
    2588                 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false, false )->addQualifiers( $2 ); }
     2577                { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); }
     2578        | ENUM attribute_list_opt type_name                                     // qualified type name
     2579                { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); }
    25892580        ;
    25902581
  • src/ResolvExpr/CandidateFinder.cpp

    ra065f1f ref1da0e2  
    864864                }
    865865
    866                 void postvisit( const ast::QualifiedNameExpr * qualifiedNameExpr ) {
    867                         auto mangleName = Mangle::mangle(qualifiedNameExpr->var);
    868                         addCandidate( qualifiedNameExpr, tenv );
    869                 }
    870 
    871866                void postvisit( const ast::UntypedExpr * untypedExpr ) {
    872867                        std::vector< CandidateFinder > argCandidates =
     
    902897                                                }
    903898
    904                                                 if (argType.as<ast::PointerType>()) funcFinder.otypeKeys.insert(Mangle::Encoding::pointer);                                             
    905                                                 // else if (const ast::EnumInstType * enumInst = argType.as<ast::EnumInstType>()) {
    906                                                 //      const ast::EnumDecl * enumDecl = enumInst->base; // Here
    907                                                 //      if ( const ast::Type* enumType = enumDecl->base ) {
    908                                                 //              // instance of enum (T) is a instance of type (T)
    909                                                 //              funcFinder.otypeKeys.insert(Mangle::mangle(enumType, Mangle::NoGenericParams | Mangle::Type));
    910                                                 //      } else {
    911                                                 //              // instance of an untyped enum is techically int
    912                                                 //              funcFinder.otypeKeys.insert(Mangle::mangle(enumDecl, Mangle::NoGenericParams | Mangle::Type));
    913                                                 //      }
    914                                                 // }
     899                                                if (argType.as<ast::PointerType>()) funcFinder.otypeKeys.insert(Mangle::Encoding::pointer);
     900                                                else if (const ast::EnumInstType * enumInst = argType.as<ast::EnumInstType>()) {
     901                                                        const ast::EnumDecl * enumDecl = enumInst->base;
     902                                                        if ( const ast::Type* enumType = enumDecl->base ) {
     903                                                                // instance of enum (T) is a instance of type (T)
     904                                                                funcFinder.otypeKeys.insert(Mangle::mangle(enumType, Mangle::NoGenericParams | Mangle::Type));
     905                                                        } else {
     906                                                                // instance of an untyped enum is techically int
     907                                                                funcFinder.otypeKeys.insert(Mangle::mangle(enumDecl, Mangle::NoGenericParams | Mangle::Type));
     908                                                        }
     909                                                }
    915910                                                else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type));
    916911                                        }
  • src/ResolvExpr/ConversionCost.cc

    ra065f1f ref1da0e2  
    340340                } else if ( const EnumInstType * enumInst = dynamic_cast< const EnumInstType * >( dest ) ) {
    341341                        const EnumDecl * base_enum = enumInst->baseEnum;
    342                         if ( const Type * base = base_enum->base ) {
     342                        if ( const Type * base = base_enum->base ) { // if the base enum has a base (if it is typed)
    343343                                if ( const BasicType * enumBaseAstBasic = dynamic_cast< const BasicType *> (base) ) {
    344344                                        conversionCostFromBasicToBasic(basicType, enumBaseAstBasic);
     
    634634        } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    635635                const ast::EnumDecl * enumDecl = enumInst->base.get();
    636                 if ( enumDecl->isTyped && !enumDecl->base.get() ) {
    637                         cost = Cost::infinity;
    638                 } else if ( const ast::Type * enumType = enumDecl->base.get() ) {
     636                if ( const ast::Type * enumType = enumDecl->base.get() ) {
    639637                        if ( const ast::BasicType * enumTypeAsBasic = dynamic_cast<const ast::BasicType *>(enumType) ) {
    640638                                conversionCostFromBasicToBasic( basicType, enumTypeAsBasic );
     
    718716        const ast::EnumDecl * baseEnum = enumInstType->base;
    719717        if ( const ast::Type * baseType = baseEnum->base ) {
    720                 costCalc( baseType, dst, srcIsLvalue, symtab, env );
     718                cost = costCalc( baseType, dst, srcIsLvalue, symtab, env );
    721719        } else {
    722720                (void)enumInstType;
  • src/ResolvExpr/Resolver.cc

    ra065f1f ref1da0e2  
    14781478                        // enum type is still incomplete at this point. Use `int` instead.
    14791479
    1480                         if ( auto enumBase = dynamic_cast< const ast::EnumInstType * >
    1481                                 ( objectDecl->get_type() )->base->base ) {
     1480                        if (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base) {
    14821481                                objectDecl = fixObjectType( objectDecl, context );
     1482                                const ast::Type * enumBase =  (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base.get());
    14831483                                currentObject = ast::CurrentObject{
    14841484                                        objectDecl->location,
     
    14931493                }
    14941494                else {
    1495                         if ( !objectDecl->isTypeFixed ) {
     1495                        if (!objectDecl->isTypeFixed) {
    14961496                                auto newDecl = fixObjectType(objectDecl, context);
    14971497                                auto mutDecl = mutate(newDecl);
  • src/ResolvExpr/Unify.cc

    ra065f1f ref1da0e2  
    165165                ast::Type * newFirst  = shallowCopy( first  );
    166166                ast::Type * newSecond = shallowCopy( second );
    167                 if ( auto temp = dynamic_cast<const ast::EnumInstType *>(first) ) {
    168                         if ( !dynamic_cast< const ast::EnumInstType * >( second ) ) {
    169                                 const ast::EnumDecl * baseEnum = dynamic_cast<const ast::EnumDecl *>(temp->base.get());
    170                                 if ( auto t = baseEnum->base.get() ) {
    171                                         newFirst = ast::shallowCopy( t );
    172                                 }
    173                         }
    174                 } else if ( auto temp = dynamic_cast<const ast::EnumInstType *>(second) ) {
    175                         const ast::EnumDecl * baseEnum = dynamic_cast<const ast::EnumDecl *>(temp->base.get());
    176                         if ( auto t = baseEnum->base.get() ) {
    177                                 newSecond = ast::shallowCopy( t );
    178                         }
    179                 }
    180 
    181167                newFirst ->qualifiers = {};
    182168                newSecond->qualifiers = {};
     
    989975                                if ( isTuple && isTuple2 ) {
    990976                                        ++it; ++jt;  // skip ttype parameters before break
    991                                 } else if ( isTuple ) { 
     977                                } else if ( isTuple ) {
    992978                                        // bundle remaining params into tuple
    993979                                        pty2 = tupleFromExprs( param2, jt, params2.end(), pty->qualifiers );
  • src/SymTab/Mangler.cc

    ra065f1f ref1da0e2  
    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

    ra065f1f ref1da0e2  
    857857                } else if ( UnionInstType * aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
    858858                        declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) );
    859                 } else if ( EnumInstType * enumInst = dynamic_cast< EnumInstType * >( designatorType ) ) {
     859                } else if ( EnumInstType * enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
    860860                        // declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) );
    861                         if ( enumInst->baseEnum ) {
    862                                 const EnumDecl * enumDecl = enumInst->baseEnum;
    863                                 declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, enumDecl->isTyped, tyDecl->linkage, enumDecl->base ) );
     861                        if (enumDecl->baseEnum) {
     862                                declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) );
    864863                        } else {
    865                                 declsToAddBefore.push_back( new EnumDecl( enumInst->name, noAttributes, tyDecl->linkage ) );
     864                                declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) );
    866865                        }
    867866                } // if
  • src/SymTab/ValidateType.cc

    ra065f1f ref1da0e2  
    8282        void postvisit( QualifiedType * qualType );
    8383
    84         void postvisit( QualifiedNameExpr * qualExpr );
    85 
    8684        void postvisit( EnumDecl * enumDecl );
    8785        void postvisit( StructDecl * structDecl );
     
    159157        // linking only makes sense for the 'oldest ancestor' of the qualified type
    160158        qualType->parent->accept( * visitor );
    161 }
    162 
    163 void LinkReferenceToTypes_old::postvisit( QualifiedNameExpr * qualExpr ) {
    164         const EnumDecl * st = local_indexer->lookupEnum( qualExpr->type_decl->name );
    165         qualExpr->type_decl = const_cast<EnumDecl *>(st);
    166159}
    167160
  • src/SynTree/Declaration.h

    ra065f1f ref1da0e2  
    145145        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    146146
     147        // TODO: Move to the right place
    147148        void checkAssignedValue() const;
    148149};
     
    337338        typedef AggregateDecl Parent;
    338339  public:
    339         bool isTyped;
    340         Type * base;
    341 
    342340        EnumDecl( const std::string & name,
    343341         const std::list< Attribute * > & attributes = std::list< class Attribute * >(),
    344           bool isTyped = false, LinkageSpec::Spec linkage = LinkageSpec::Cforall,
    345           Type * baseType = nullptr )
    346           : Parent( name, attributes, linkage ),isTyped(isTyped), base( baseType ) {}
    347         EnumDecl( const EnumDecl & other )
    348           : Parent( other ), isTyped( other.isTyped), base( other.base ) {}
     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 ) {}
     345
    349346        bool valueOf( Declaration * enumerator, long long int & value );
     347
    350348        virtual EnumDecl * clone() const override { return new EnumDecl( *this ); }
    351349        virtual void accept( Visitor & v ) override { v.visit( this ); }
    352350        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    353351        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    354 
    355         std::unordered_map< std::string, long long int > enumValues; // This attribute is unused
     352        Type * base;
     353        std::unordered_map< std::string, long long int > enumValues;
    356354        virtual void print( std::ostream & os, Indenter indent = {} ) const override final;
    357355  private:
  • src/SynTree/Expression.h

    ra065f1f ref1da0e2  
    163163};
    164164
    165 // [Qualifier].name; Qualifier is the type_name from the parser
    166 class QualifiedNameExpr : public Expression {
    167   public:
    168         Declaration * type_decl;
    169         std::string name;
    170         DeclarationWithType * var;
    171 
    172         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; }
    176 
    177         virtual ~QualifiedNameExpr() {
    178                 delete var;
    179                 delete type_decl;
    180         }
    181 
    182         virtual QualifiedNameExpr * clone() const override {
    183                 return new QualifiedNameExpr( * this );
    184         }
    185         virtual void accept( Visitor & v ) override { v.visit(this); }
    186         virtual void accept( Visitor & v ) const override { v.visit(this); }
    187         virtual Expression * acceptMutator( Mutator & m ) override {
    188                 return m.mutate( this );
    189         }
    190        
    191         virtual void print( std::ostream & os, Indenter indent = {} ) const override {
    192                 type_decl->print( os, indent );
    193                 os << name << std::endl;
    194         }
    195 };
    196 
    197165/// VariableExpr represents an expression that simply refers to the value of a named variable.
    198166/// Does not take ownership of var.
  • src/SynTree/Mutator.h

    ra065f1f ref1da0e2  
    9898        virtual Expression * mutate( DefaultArgExpr * argExpr ) = 0;
    9999        virtual Expression * mutate( GenericExpr * genExpr ) = 0;
    100         virtual Expression * mutate( QualifiedNameExpr * qualifiedNameExpr ) = 0;
    101100
    102101        virtual Type * mutate( VoidType * basicType ) = 0;
  • src/SynTree/SynTree.h

    ra065f1f ref1da0e2  
    103103class DefaultArgExpr;
    104104class GenericExpr;
    105 class QualifiedNameExpr;
    106105
    107106class Type;
  • src/SynTree/Type.h

    ra065f1f ref1da0e2  
    345345        Type * parent;
    346346        Type * child;
     347
    347348        QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child );
    348349        QualifiedType( const QualifiedType & tq );
  • src/SynTree/Visitor.h

    ra065f1f ref1da0e2  
    101101        virtual void visit( NameExpr * node ) { visit( const_cast<const NameExpr *>(node) ); }
    102102        virtual void visit( const NameExpr * nameExpr ) = 0;
    103         virtual void visit( QualifiedNameExpr * node ) { visit( const_cast<const QualifiedNameExpr*>(node) );}
    104         virtual void visit( const QualifiedNameExpr* qualifiednameExpr ) = 0;
    105103        virtual void visit( CastExpr * node ) { visit( const_cast<const CastExpr *>(node) ); }
    106104        virtual void visit( const CastExpr * castExpr ) = 0;
  • src/Validate/Autogen.cpp

    ra065f1f ref1da0e2  
    235235        // Must visit children (enum constants) to add them to the symbol table.
    236236        if ( !enumDecl->body ) return;
    237 
    238         // if ( auto enumBaseType = enumDecl->base ) {
    239         //      if ( auto enumBaseTypeAsStructInst = dynamic_cast<const ast::StructInstType *>(enumBaseType.get()) ) {
    240         //              const ast::StructDecl * structDecl = enumBaseTypeAsStructInst->base.get();
    241         //              this->previsit( structDecl );
    242         //      }
    243         // }
    244237
    245238        ast::EnumInstType enumInst( enumDecl->name );
  • src/Validate/FixQualifiedTypes.cpp

    ra065f1f ref1da0e2  
    1919#include "AST/TranslationUnit.hpp"
    2020#include "Validate/NoIdSymbolTable.hpp"
    21 #include "SymTab/Mangler.h"            // for Mangler
    22 #include "AST/LinkageSpec.hpp"                     // for Linkage
    2321
    2422namespace Validate {
     
    9189                }
    9290        }
    93 
    94         ast::Expr const * postvisit( ast::QualifiedNameExpr const * t) {
    95                 assert( location );
    96                 if ( t->type_decl ) {
    97                 auto enumName = t->type_decl->name;
    98                 const ast::EnumDecl * enumDecl = symtab.lookupEnum( enumName );
    99                         for ( ast::ptr<ast::Decl> const & member : enumDecl->members ) {
    100                                 if ( auto memberAsObj = member.as<ast::ObjectDecl>() ) {
    101                                         if ( memberAsObj->name == t->name ) {
    102                                                 return new ast::VariableExpr( t->location, memberAsObj );
    103                                         }
    104                                 } else {
    105                                         assertf( false, "unhandled qualified child type");
    106                                 }
    107                         }
    108 
    109 
    110                 auto var = new ast::ObjectDecl( t->var->location, t->name,
    111                          new ast::EnumInstType(enumDecl, ast::CV::Const), nullptr, {}, ast::Linkage::Cforall );
    112                         var->scopeLevel = 1; // 1 for now; should copy the scopeLevel of the enumValue
    113                         var->mangleName = Mangle::mangle( var );
    114                         return new ast::VariableExpr( t->location, var );
    115                 // return ret;
    116         }
    117 
    118                 return t;
    119         }
    120 
    12191};
    12292
  • src/Validate/LinkReferenceToTypes.cpp

    ra065f1f ref1da0e2  
    4646        void postvisit( ast::UnionDecl const * decl );
    4747        ast::TraitDecl const * postvisit( ast::TraitDecl const * decl );
    48         ast::QualifiedNameExpr const * previsit( ast::QualifiedNameExpr const * decl);
    4948
    5049private:
     
    293292}
    294293
    295 ast::QualifiedNameExpr const * LinkTypesCore::previsit( ast::QualifiedNameExpr const * decl ) {
    296         // Try to lookup type
    297         if ( auto objDecl = decl->type_decl.as<ast::ObjectDecl>() ) {
    298                 if ( auto inst = objDecl->type.as<ast::TypeInstType>()) {
    299                         if ( auto enumDecl = symtab.lookupEnum ( inst->name ) ) {
    300                                 auto mut = ast::mutate( decl );
    301                                 mut->type_decl = enumDecl;
    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                 }
    309         } else if ( auto enumDecl = decl->type_decl.as<ast::EnumDecl>() ) {
    310                 auto mut = ast::mutate( decl );
    311                 auto enumInst = new ast::EnumInstType( enumDecl );
    312                 enumInst->name = decl->name;
    313                 // Adding result; addCandidate() use result
    314                 mut->result = enumInst;
    315                 decl = mut;
    316         }
    317         // ast::EnumDecl const * decl = symtab.lookupEnum( type->name );
    318         // // It's not a semantic error if the enum is not found, just an implicit forward declaration.
    319         // if ( decl ) {
    320         //      // Just linking in the node.
    321         //      auto mut = ast::mutate( type );
    322         //      mut->base = const_cast<ast::EnumDecl *>( decl );
    323         //      type = mut;
    324         // }
    325         return decl;
    326 }
    327 
    328294} // namespace
    329295
  • src/Validate/ReplaceTypedef.cpp

    ra065f1f ref1da0e2  
    183183        } else if ( auto enumType = dynamic_cast<ast::EnumInstType const *>( designatorType ) ) {
    184184                declsToAddBefore.push_back( new ast::EnumDecl(
    185                         decl->location, enumType->name, false, {}, decl->linkage,
     185                        decl->location, enumType->name, {}, decl->linkage,
    186186                        ( (enumType->base) ? enumType->base->base : nullptr )
    187187                        ) );
  • tests/enum_tests/structEnum.cfa

    ra065f1f ref1da0e2  
    22
    33struct Point {
    4      int x;
    5      char y;
     4    int x;
     5    char y;
    66};
    77
    88enum(Point) PointEnum {
    9      first={
    10          100,
    11          'c'
    12      },
    13      second={
    14          200,
    15          'a'
    16      }
     9    first={
     10        100,
     11        'c'
     12    },
     13    second={
     14        200,
     15        'a'
     16    }
    1717};
    18 
    19 PointEnum foo(PointEnum in) {
    20      return in;
    21 }
    2218
    2319// The only valid usage
    2420struct Point apple = first;
    2521// Failed due to Qualified name is currently unimplemented.
     22// struct Point banana = PointEnum.first;
    2623
    2724int main() {
    28      PointEnum vals = second;
    29      PointEnum val2;
    30      // The failing line: assignment
    31      // val2 = vals;
    32 
    33      printf("%d %c\n", apple.x, apple.y);
    34      // Failed; enumInstType is now not a real type and not instantiated.
    35      // Not sure if we want that
    36      // printf("%d %c\n", second.x, second.y);
    37      return 0;
     25    printf("%d %c\n", apple.x, apple.y);
     26    // Failed; enumInstType is now not a real type and not instantiated.
     27    // Not sure if we want that
     28    // printf("%d %c\n", second.x, second.y);
     29    return 0;
    3830}
Note: See TracChangeset for help on using the changeset viewer.