Changes in / [a065f1f:ef1da0e2]
- Files:
-
- 8 deleted
- 37 edited
-
src/AST/Convert.cpp (modified) (4 diffs)
-
src/AST/Decl.hpp (modified) (2 diffs)
-
src/AST/Expr.hpp (modified) (1 diff)
-
src/AST/Fwd.hpp (modified) (1 diff)
-
src/AST/Pass.hpp (modified) (1 diff)
-
src/AST/Pass.impl.hpp (modified) (1 diff)
-
src/AST/Print.cpp (modified) (1 diff)
-
src/AST/Visitor.hpp (modified) (1 diff)
-
src/CodeGen/CodeGenerator.cc (modified) (3 diffs)
-
src/CodeGen/CodeGenerator.h (modified) (1 diff)
-
src/Common/CodeLocationTools.cpp (modified) (1 diff)
-
src/Common/PassVisitor.h (modified) (3 diffs)
-
src/Common/PassVisitor.impl.h (modified) (1 diff)
-
src/Parser/DeclarationNode.cc (modified) (4 diffs)
-
src/Parser/ExpressionNode.cc (modified) (1 diff)
-
src/Parser/ParseNode.h (modified) (2 diffs)
-
src/Parser/TypeData.cc (modified) (2 diffs)
-
src/Parser/TypeData.h (modified) (1 diff)
-
src/Parser/parser.yy (modified) (5 diffs)
-
src/ResolvExpr/CandidateFinder.cpp (modified) (2 diffs)
-
src/ResolvExpr/ConversionCost.cc (modified) (3 diffs)
-
src/ResolvExpr/Resolver.cc (modified) (2 diffs)
-
src/ResolvExpr/Unify.cc (modified) (2 diffs)
-
src/SymTab/Mangler.cc (modified) (4 diffs)
-
src/SymTab/Validate.cc (modified) (1 diff)
-
src/SymTab/ValidateType.cc (modified) (2 diffs)
-
src/SynTree/Declaration.h (modified) (2 diffs)
-
src/SynTree/Expression.h (modified) (1 diff)
-
src/SynTree/Mutator.h (modified) (1 diff)
-
src/SynTree/SynTree.h (modified) (1 diff)
-
src/SynTree/Type.h (modified) (1 diff)
-
src/SynTree/Visitor.h (modified) (1 diff)
-
src/Validate/Autogen.cpp (modified) (1 diff)
-
src/Validate/FixQualifiedTypes.cpp (modified) (2 diffs)
-
src/Validate/LinkReferenceToTypes.cpp (modified) (2 diffs)
-
src/Validate/ReplaceTypedef.cpp (modified) (1 diff)
-
tests/enum_tests/.expect/funcEnum.txt (deleted)
-
tests/enum_tests/.expect/pointerEnum.cfa (deleted)
-
tests/enum_tests/.expect/qualifiedEnum.cfa (deleted)
-
tests/enum_tests/.expect/voidEnum.txt (deleted)
-
tests/enum_tests/funcEnum.cfa (deleted)
-
tests/enum_tests/pointerEnum.cfa (deleted)
-
tests/enum_tests/qualifiedEnum.cfa (deleted)
-
tests/enum_tests/structEnum.cfa (modified) (1 diff)
-
tests/enum_tests/voidEnum.cfa (deleted)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
ra065f1f ref1da0e2 310 310 node->name, 311 311 get<Attribute>().acceptL( node->attributes ), 312 false, // Temporary313 312 LinkageSpec::Spec( node->linkage.val ), 314 313 get<Type>().accept1(node->base) … … 732 731 } 733 732 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->name738 );739 temp->var = get<DeclarationWithType>().accept1(node->var);740 auto expr = visitBaseExpr( node,741 temp742 );743 this->node = expr;744 return nullptr;745 }746 747 733 const ast::Expr * visit( const ast::AddressExpr * node ) override final { 748 734 auto expr = visitBaseExpr( node, … … 1754 1740 old->location, 1755 1741 old->name, 1756 old->isTyped,1757 1742 GET_ACCEPT_V(attributes, Attribute), 1758 1743 { old->linkage.val }, … … 2281 2266 } 2282 2267 2283 /// xxx - type_decl should be DeclWithType in the final design2284 /// type_decl is set to EnumDecl as a temporary fix2285 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->name2292 )2293 );2294 }2295 2296 2268 virtual void visit( const CastExpr * old ) override final { 2297 2269 this->node = visitBaseExpr( old, -
src/AST/Decl.hpp
ra065f1f ref1da0e2 312 312 class EnumDecl final : public AggregateDecl { 313 313 public: 314 bool isTyped;315 314 ptr<Type> base; 316 315 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, 320 318 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) {} 322 320 323 321 /// gets the integer value for this enumerator, returning true iff value found … … 329 327 const char * typeString() const override { return aggrString( Enum ); } 330 328 329 bool isTyped() {return base && base.get();} 331 330 332 331 private: -
src/AST/Expr.hpp
ra065f1f ref1da0e2 254 254 }; 255 255 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_FRIEND269 };270 271 256 /// A reference to a named variable. 272 257 class VariableExpr final : public Expr { -
src/AST/Fwd.hpp
ra065f1f ref1da0e2 67 67 class UntypedExpr; 68 68 class NameExpr; 69 class QualifiedNameExpr;70 69 class AddressExpr; 71 70 class LabelAddressExpr; -
src/AST/Pass.hpp
ra065f1f ref1da0e2 167 167 const ast::Expr * visit( const ast::UntypedExpr * ) override final; 168 168 const ast::Expr * visit( const ast::NameExpr * ) override final; 169 const ast::Expr * visit( const ast::QualifiedNameExpr * ) override final;170 169 const ast::Expr * visit( const ast::AddressExpr * ) override final; 171 170 const ast::Expr * visit( const ast::LabelAddressExpr * ) override final; -
src/AST/Pass.impl.hpp
ra065f1f ref1da0e2 1199 1199 1200 1200 //-------------------------------------------------------------------------- 1201 // QualifiedNameExpr1202 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 //--------------------------------------------------------------------------1214 1201 // CastExpr 1215 1202 template< typename core_t > -
src/AST/Print.cpp
ra065f1f ref1da0e2 899 899 postprint( node ); 900 900 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 );912 901 return node; 913 902 } -
src/AST/Visitor.hpp
ra065f1f ref1da0e2 59 59 virtual const ast::Expr * visit( const ast::UntypedExpr * ) = 0; 60 60 virtual const ast::Expr * visit( const ast::NameExpr * ) = 0; 61 virtual const ast::Expr * visit( const ast::QualifiedNameExpr * ) = 0;62 61 virtual const ast::Expr * visit( const ast::AddressExpr * ) = 0; 63 62 virtual const ast::Expr * visit( const ast::LabelAddressExpr * ) = 0; -
src/CodeGen/CodeGenerator.cc
ra065f1f ref1da0e2 277 277 std::list< Declaration* > &memb = enumDecl->get_members(); 278 278 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; 281 280 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 282 281 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); … … 696 695 output << opInfo->symbol; 697 696 } 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 // } 698 701 output << mangleName( variableExpr->get_var() ); 699 702 } // if … … 914 917 } 915 918 916 // QualifiedNameExpr should not reach to CodeGen.917 // FixQualifiedName Convert QualifiedNameExpr to VariableExpr918 void CodeGenerator::postvisit( QualifiedNameExpr * expr ) {919 output << "/* label */" << mangleName(expr->var);920 }921 919 922 920 // *** Statements -
src/CodeGen/CodeGenerator.h
ra065f1f ref1da0e2 103 103 void postvisit( DefaultArgExpr * ); 104 104 void postvisit( GenericExpr * ); 105 void postvisit( QualifiedNameExpr *);106 105 107 106 //*** Statements -
src/Common/CodeLocationTools.cpp
ra065f1f ref1da0e2 137 137 macro(UntypedExpr, Expr) \ 138 138 macro(NameExpr, Expr) \ 139 macro(QualifiedNameExpr, Expr) \140 139 macro(AddressExpr, Expr) \ 141 140 macro(LabelAddressExpr, Expr) \ -
src/Common/PassVisitor.h
ra065f1f ref1da0e2 133 133 virtual void visit( NameExpr * nameExpr ) override final; 134 134 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;137 135 virtual void visit( CastExpr * castExpr ) override final; 138 136 virtual void visit( const CastExpr * castExpr ) override final; … … 327 325 virtual Expression * mutate( TupleExpr * tupleExpr ) override final; 328 326 virtual Expression * mutate( TupleIndexExpr * tupleExpr ) override final; 329 virtual Expression * mutate( TupleAssignExpr * assignExpr ) override final; 327 virtual Expression * mutate( TupleAssignExpr * assignExpr ) override final; 330 328 virtual Expression * mutate( StmtExpr * stmtExpr ) override final; 331 329 virtual Expression * mutate( UniqueExpr * uniqueExpr ) override final; … … 335 333 virtual Expression * mutate( DefaultArgExpr * argExpr ) override final; 336 334 virtual Expression * mutate( GenericExpr * genExpr ) override final; 337 virtual Expression * mutate( QualifiedNameExpr * qualifiedNameExpr ) override final;338 335 339 336 virtual Type * mutate( VoidType * basicType ) override final; -
src/Common/PassVisitor.impl.h
ra065f1f ref1da0e2 1927 1927 1928 1928 //-------------------------------------------------------------------------- 1929 // QualifiedNameExpr1930 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 //--------------------------------------------------------------------------1965 1929 // CastExpr 1966 1930 template< typename pass_type > -
src/Parser/DeclarationNode.cc
ra065f1f ref1da0e2 254 254 } // DeclarationNode::newAggregate 255 255 256 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed,DeclarationNode * base) {256 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, DeclarationNode * base) { 257 257 DeclarationNode * newnode = new DeclarationNode; 258 258 newnode->type = new TypeData( TypeData::Enum ); … … 261 261 newnode->type->enumeration.body = body; 262 262 newnode->type->enumeration.anon = name == nullptr; 263 newnode->type->enumeration.typed = typed;264 263 if ( base && base->type) { 265 264 newnode->type->base = base->type; 266 265 } // if 267 266 267 // Check: if base has TypeData 268 268 return newnode; 269 269 } // DeclarationNode::newEnum … … 285 285 286 286 DeclarationNode * 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 289 289 return newEnumConstant( name, init->get_expression() ); 290 } else { 290 } else { // TODO: listInit 291 291 DeclarationNode * newnode = newName( name ); 292 292 newnode->initializer = init; … … 294 294 } // if 295 295 } else { 296 return newName( name ); 296 return newName( name ); // Not explicitly inited enum value; 297 297 } // if 298 298 } // DeclarationNode::newEnumValueGeneric -
src/Parser/ExpressionNode.cc
ra065f1f ref1da0e2 509 509 } // build_varref 510 510 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 535 511 DimensionExpr * build_dimensionref( const string * name ) { 536 512 DimensionExpr * expr = new DimensionExpr( *name ); -
src/Parser/ParseNode.h
ra065f1f ref1da0e2 183 183 184 184 NameExpr * 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 );187 185 DimensionExpr * build_dimensionref( const std::string * name ); 188 186 … … 237 235 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ); 238 236 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 ); 240 238 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 241 239 static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init ); -
src/Parser/TypeData.cc
ra065f1f ref1da0e2 546 546 return buildAggInst( td ); 547 547 case TypeData::EnumConstant: 548 // the name gets filled in later -- by SymTab::Validate 548 549 return new EnumInstType( buildQualifiers( td ), "" ); 549 550 case TypeData::SymbolicInst: … … 920 921 assert( td->kind == TypeData::Enum ); 921 922 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 ); 923 924 buildList( td->enumeration.constants, ret->get_members() ); 924 925 list< Declaration * >::iterator members = ret->get_members().begin(); 925 926 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() ) { 929 928 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 930 929 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) ); 931 930 } else if ( !cur->initializer ) { 932 931 if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) { 933 SemanticError( td->location, " Enumerators of an non-integer typed enummust be explicitly initialized." );932 SemanticError( td->location, "A non whole number enum value decl must be explicitly initialized." ); 934 933 } 935 934 } -
src/Parser/TypeData.h
ra065f1f ref1da0e2 59 59 bool body; 60 60 bool anon; 61 bool typed;62 61 }; 63 62 -
src/Parser/parser.yy
ra065f1f ref1da0e2 637 637 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); } 638 638 | 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; } 640 640 | type_name '.' '[' field_name_list ']' // CFA, nested type / tuple field selector 641 641 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 2538 2538 enum_type: 2539 2539 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 ); } 2541 2541 | ENUM attribute_list_opt identifier 2542 2542 { typedefTable.makeTypedef( *$3 ); } 2543 2543 '{' enumerator_list comma_opt '}' 2544 { $$ = DeclarationNode::newEnum( $3, $6, true , false)->addQualifiers( $2 ); }2544 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); } 2545 2545 | ENUM attribute_list_opt typedef_name // unqualified type name 2546 2546 '{' 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; } 2548 2550 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2549 2551 { … … 2551 2553 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2552 2554 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 ); 2558 2556 } 2559 2557 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt … … 2564 2562 '{' enumerator_list comma_opt '}' 2565 2563 { 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 } 2573 2566 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' 2574 2567 { 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 ); 2580 2571 } 2581 2572 | enum_type_nobody … … 2584 2575 enum_type_nobody: // enum - {...} 2585 2576 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 ); } 2589 2580 ; 2590 2581 -
src/ResolvExpr/CandidateFinder.cpp
ra065f1f ref1da0e2 864 864 } 865 865 866 void postvisit( const ast::QualifiedNameExpr * qualifiedNameExpr ) {867 auto mangleName = Mangle::mangle(qualifiedNameExpr->var);868 addCandidate( qualifiedNameExpr, tenv );869 }870 871 866 void postvisit( const ast::UntypedExpr * untypedExpr ) { 872 867 std::vector< CandidateFinder > argCandidates = … … 902 897 } 903 898 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; // Here907 //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 int912 //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 } 915 910 else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type)); 916 911 } -
src/ResolvExpr/ConversionCost.cc
ra065f1f ref1da0e2 340 340 } else if ( const EnumInstType * enumInst = dynamic_cast< const EnumInstType * >( dest ) ) { 341 341 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) 343 343 if ( const BasicType * enumBaseAstBasic = dynamic_cast< const BasicType *> (base) ) { 344 344 conversionCostFromBasicToBasic(basicType, enumBaseAstBasic); … … 634 634 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 635 635 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() ) { 639 637 if ( const ast::BasicType * enumTypeAsBasic = dynamic_cast<const ast::BasicType *>(enumType) ) { 640 638 conversionCostFromBasicToBasic( basicType, enumTypeAsBasic ); … … 718 716 const ast::EnumDecl * baseEnum = enumInstType->base; 719 717 if ( const ast::Type * baseType = baseEnum->base ) { 720 cost Calc( baseType, dst, srcIsLvalue, symtab, env );718 cost = costCalc( baseType, dst, srcIsLvalue, symtab, env ); 721 719 } else { 722 720 (void)enumInstType; -
src/ResolvExpr/Resolver.cc
ra065f1f ref1da0e2 1478 1478 // enum type is still incomplete at this point. Use `int` instead. 1479 1479 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) { 1482 1481 objectDecl = fixObjectType( objectDecl, context ); 1482 const ast::Type * enumBase = (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base.get()); 1483 1483 currentObject = ast::CurrentObject{ 1484 1484 objectDecl->location, … … 1493 1493 } 1494 1494 else { 1495 if ( !objectDecl->isTypeFixed) {1495 if (!objectDecl->isTypeFixed) { 1496 1496 auto newDecl = fixObjectType(objectDecl, context); 1497 1497 auto mutDecl = mutate(newDecl); -
src/ResolvExpr/Unify.cc
ra065f1f ref1da0e2 165 165 ast::Type * newFirst = shallowCopy( first ); 166 166 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 181 167 newFirst ->qualifiers = {}; 182 168 newSecond->qualifiers = {}; … … 989 975 if ( isTuple && isTuple2 ) { 990 976 ++it; ++jt; // skip ttype parameters before break 991 } else if ( isTuple ) { 977 } else if ( isTuple ) { 992 978 // bundle remaining params into tuple 993 979 pty2 = tupleFromExprs( param2, jt, params2.end(), pty->qualifiers ); -
src/SymTab/Mangler.cc
ra065f1f ref1da0e2 65 65 void postvisit( const QualifiedType * qualType ); 66 66 67 void postvisit( const QualifiedNameExpr * qualNameExpr );68 69 67 std::string get_mangleName() { return mangleName; } 70 68 private: … … 307 305 mangleName += Encoding::qualifiedTypeEnd; 308 306 } 309 }310 311 void Mangler_old::postvisit( const QualifiedNameExpr * qual ) {312 maybeAccept( qual->var, *visitor );313 307 } 314 308 … … 423 417 void postvisit( const ast::OneType * oneType ); 424 418 void postvisit( const ast::QualifiedType * qualType ); 425 void postvisit( const ast::QualifiedNameExpr * qualNameExpr );426 419 427 420 std::string get_mangleName() { return mangleName; } … … 652 645 mangleName += Encoding::qualifiedTypeEnd; 653 646 } 654 }655 void Mangler_new::postvisit( const ast::QualifiedNameExpr * qual ) {656 maybeAccept( qual->var.get(), *visitor );657 647 } 658 648 -
src/SymTab/Validate.cc
ra065f1f ref1da0e2 857 857 } else if ( UnionInstType * aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) { 858 858 declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) ); 859 } else if ( EnumInstType * enum Inst= dynamic_cast< EnumInstType * >( designatorType ) ) {859 } else if ( EnumInstType * enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) { 860 860 // 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 ) ); 864 863 } else { 865 declsToAddBefore.push_back( new EnumDecl( enum Inst->name, noAttributes, tyDecl->linkage ) );864 declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) ); 866 865 } 867 866 } // if -
src/SymTab/ValidateType.cc
ra065f1f ref1da0e2 82 82 void postvisit( QualifiedType * qualType ); 83 83 84 void postvisit( QualifiedNameExpr * qualExpr );85 86 84 void postvisit( EnumDecl * enumDecl ); 87 85 void postvisit( StructDecl * structDecl ); … … 159 157 // linking only makes sense for the 'oldest ancestor' of the qualified type 160 158 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);166 159 } 167 160 -
src/SynTree/Declaration.h
ra065f1f ref1da0e2 145 145 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; 146 146 147 // TODO: Move to the right place 147 148 void checkAssignedValue() const; 148 149 }; … … 337 338 typedef AggregateDecl Parent; 338 339 public: 339 bool isTyped;340 Type * base;341 342 340 EnumDecl( const std::string & name, 343 341 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 349 346 bool valueOf( Declaration * enumerator, long long int & value ); 347 350 348 virtual EnumDecl * clone() const override { return new EnumDecl( *this ); } 351 349 virtual void accept( Visitor & v ) override { v.visit( this ); } 352 350 virtual void accept( Visitor & v ) const override { v.visit( this ); } 353 351 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 354 355 std::unordered_map< std::string, long long int > enumValues; // This attribute is unused352 Type * base; 353 std::unordered_map< std::string, long long int > enumValues; 356 354 virtual void print( std::ostream & os, Indenter indent = {} ) const override final; 357 355 private: -
src/SynTree/Expression.h
ra065f1f ref1da0e2 163 163 }; 164 164 165 // [Qualifier].name; Qualifier is the type_name from the parser166 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 197 165 /// VariableExpr represents an expression that simply refers to the value of a named variable. 198 166 /// Does not take ownership of var. -
src/SynTree/Mutator.h
ra065f1f ref1da0e2 98 98 virtual Expression * mutate( DefaultArgExpr * argExpr ) = 0; 99 99 virtual Expression * mutate( GenericExpr * genExpr ) = 0; 100 virtual Expression * mutate( QualifiedNameExpr * qualifiedNameExpr ) = 0;101 100 102 101 virtual Type * mutate( VoidType * basicType ) = 0; -
src/SynTree/SynTree.h
ra065f1f ref1da0e2 103 103 class DefaultArgExpr; 104 104 class GenericExpr; 105 class QualifiedNameExpr;106 105 107 106 class Type; -
src/SynTree/Type.h
ra065f1f ref1da0e2 345 345 Type * parent; 346 346 Type * child; 347 347 348 QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ); 348 349 QualifiedType( const QualifiedType & tq ); -
src/SynTree/Visitor.h
ra065f1f ref1da0e2 101 101 virtual void visit( NameExpr * node ) { visit( const_cast<const NameExpr *>(node) ); } 102 102 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;105 103 virtual void visit( CastExpr * node ) { visit( const_cast<const CastExpr *>(node) ); } 106 104 virtual void visit( const CastExpr * castExpr ) = 0; -
src/Validate/Autogen.cpp
ra065f1f ref1da0e2 235 235 // Must visit children (enum constants) to add them to the symbol table. 236 236 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 // }244 237 245 238 ast::EnumInstType enumInst( enumDecl->name ); -
src/Validate/FixQualifiedTypes.cpp
ra065f1f ref1da0e2 19 19 #include "AST/TranslationUnit.hpp" 20 20 #include "Validate/NoIdSymbolTable.hpp" 21 #include "SymTab/Mangler.h" // for Mangler22 #include "AST/LinkageSpec.hpp" // for Linkage23 21 24 22 namespace Validate { … … 91 89 } 92 90 } 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 enumValue113 var->mangleName = Mangle::mangle( var );114 return new ast::VariableExpr( t->location, var );115 // return ret;116 }117 118 return t;119 }120 121 91 }; 122 92 -
src/Validate/LinkReferenceToTypes.cpp
ra065f1f ref1da0e2 46 46 void postvisit( ast::UnionDecl const * decl ); 47 47 ast::TraitDecl const * postvisit( ast::TraitDecl const * decl ); 48 ast::QualifiedNameExpr const * previsit( ast::QualifiedNameExpr const * decl);49 48 50 49 private: … … 293 292 } 294 293 295 ast::QualifiedNameExpr const * LinkTypesCore::previsit( ast::QualifiedNameExpr const * decl ) {296 // Try to lookup type297 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 result305 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 result314 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 328 294 } // namespace 329 295 -
src/Validate/ReplaceTypedef.cpp
ra065f1f ref1da0e2 183 183 } else if ( auto enumType = dynamic_cast<ast::EnumInstType const *>( designatorType ) ) { 184 184 declsToAddBefore.push_back( new ast::EnumDecl( 185 decl->location, enumType->name, false,{}, decl->linkage,185 decl->location, enumType->name, {}, decl->linkage, 186 186 ( (enumType->base) ? enumType->base->base : nullptr ) 187 187 ) ); -
tests/enum_tests/structEnum.cfa
ra065f1f ref1da0e2 2 2 3 3 struct Point { 4 int x;5 char y;4 int x; 5 char y; 6 6 }; 7 7 8 8 enum(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 } 17 17 }; 18 19 PointEnum foo(PointEnum in) {20 return in;21 }22 18 23 19 // The only valid usage 24 20 struct Point apple = first; 25 21 // Failed due to Qualified name is currently unimplemented. 22 // struct Point banana = PointEnum.first; 26 23 27 24 int 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; 38 30 }
Note:
See TracChangeset
for help on using the changeset viewer.