Changeset dc56b9d
- Timestamp:
- Sep 20, 2022, 9:24:55 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- b6c3688
- Parents:
- 1c893ae (diff), 53a768d (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. - Files:
-
- 7 added
- 37 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r1c893ae rdc56b9d 310 310 node->name, 311 311 get<Attribute>().acceptL( node->attributes ), 312 false, // Temporary 312 313 LinkageSpec::Spec( node->linkage.val ), 313 314 get<Type>().accept1(node->base) … … 731 732 } 732 733 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 733 747 const ast::Expr * visit( const ast::AddressExpr * node ) override final { 734 748 auto expr = visitBaseExpr( node, … … 1740 1754 old->location, 1741 1755 old->name, 1756 old->isTyped, 1742 1757 GET_ACCEPT_V(attributes, Attribute), 1743 1758 { old->linkage.val }, … … 2266 2281 } 2267 2282 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 2268 2296 virtual void visit( const CastExpr * old ) override final { 2269 2297 this->node = visitBaseExpr( old, -
src/AST/Decl.hpp
r1c893ae rdc56b9d 312 312 class EnumDecl final : public AggregateDecl { 313 313 public: 314 bool isTyped; 314 315 ptr<Type> base; 315 316 316 EnumDecl( const CodeLocation& loc, const std::string& name, 317 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall, Type const * base = nullptr, 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, 318 320 std::unordered_map< std::string, long long > enumValues = std::unordered_map< std::string, long long >() ) 319 : AggregateDecl( loc, name, std::move(attrs), linkage ), base(base), enumValues(enumValues) {}321 : AggregateDecl( loc, name, std::move(attrs), linkage ), isTyped(isTyped), base(base), enumValues(enumValues) {} 320 322 321 323 /// gets the integer value for this enumerator, returning true iff value found … … 327 329 const char * typeString() const override { return aggrString( Enum ); } 328 330 329 bool isTyped() {return base && base.get();}330 331 331 332 private: -
src/AST/Expr.hpp
r1c893ae rdc56b9d 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_FRIEND 269 }; 270 256 271 /// A reference to a named variable. 257 272 class VariableExpr final : public Expr { -
src/AST/Fwd.hpp
r1c893ae rdc56b9d 67 67 class UntypedExpr; 68 68 class NameExpr; 69 class QualifiedNameExpr; 69 70 class AddressExpr; 70 71 class LabelAddressExpr; -
src/AST/Pass.hpp
r1c893ae rdc56b9d 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; 169 170 const ast::Expr * visit( const ast::AddressExpr * ) override final; 170 171 const ast::Expr * visit( const ast::LabelAddressExpr * ) override final; -
src/AST/Pass.impl.hpp
r1c893ae rdc56b9d 1199 1199 1200 1200 //-------------------------------------------------------------------------- 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 //-------------------------------------------------------------------------- 1201 1214 // CastExpr 1202 1215 template< typename core_t > -
src/AST/Print.cpp
r1c893ae rdc56b9d 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 ); 901 912 return node; 902 913 } -
src/AST/Visitor.hpp
r1c893ae rdc56b9d 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; 61 62 virtual const ast::Expr * visit( const ast::AddressExpr * ) = 0; 62 63 virtual const ast::Expr * visit( const ast::LabelAddressExpr * ) = 0; -
src/CodeGen/CodeGenerator.cc
r1c893ae rdc56b9d 277 277 std::list< Declaration* > &memb = enumDecl->get_members(); 278 278 if (enumDecl->base && ! memb.empty()) { 279 unsigned long long last_val = -1; 279 unsigned long long last_val = -1; // if the first enum value has no explicit initializer, 280 // as other 280 281 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 281 282 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); … … 695 696 output << opInfo->symbol; 696 697 } 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 // }701 698 output << mangleName( variableExpr->get_var() ); 702 699 } // if … … 917 914 } 918 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); 920 } 919 921 920 922 // *** Statements -
src/CodeGen/CodeGenerator.h
r1c893ae rdc56b9d 103 103 void postvisit( DefaultArgExpr * ); 104 104 void postvisit( GenericExpr * ); 105 void postvisit( QualifiedNameExpr *); 105 106 106 107 //*** Statements -
src/Common/CodeLocationTools.cpp
r1c893ae rdc56b9d 137 137 macro(UntypedExpr, Expr) \ 138 138 macro(NameExpr, Expr) \ 139 macro(QualifiedNameExpr, Expr) \ 139 140 macro(AddressExpr, Expr) \ 140 141 macro(LabelAddressExpr, Expr) \ -
src/Common/PassVisitor.h
r1c893ae rdc56b9d 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; 135 137 virtual void visit( CastExpr * castExpr ) override final; 136 138 virtual void visit( const CastExpr * castExpr ) override final; … … 325 327 virtual Expression * mutate( TupleExpr * tupleExpr ) override final; 326 328 virtual Expression * mutate( TupleIndexExpr * tupleExpr ) override final; 327 virtual Expression * mutate( TupleAssignExpr * assignExpr ) override final; 329 virtual Expression * mutate( TupleAssignExpr * assignExpr ) override final; 328 330 virtual Expression * mutate( StmtExpr * stmtExpr ) override final; 329 331 virtual Expression * mutate( UniqueExpr * uniqueExpr ) override final; … … 333 335 virtual Expression * mutate( DefaultArgExpr * argExpr ) override final; 334 336 virtual Expression * mutate( GenericExpr * genExpr ) override final; 337 virtual Expression * mutate( QualifiedNameExpr * qualifiedNameExpr ) override final; 335 338 336 339 virtual Type * mutate( VoidType * basicType ) override final; -
src/Common/PassVisitor.impl.h
r1c893ae rdc56b9d 1927 1927 1928 1928 //-------------------------------------------------------------------------- 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 //-------------------------------------------------------------------------- 1929 1965 // CastExpr 1930 1966 template< typename pass_type > -
src/Parser/DeclarationNode.cc
r1c893ae rdc56b9d 254 254 } // DeclarationNode::newAggregate 255 255 256 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, DeclarationNode * base) {256 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed, 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; 263 264 if ( base && base->type) { 264 265 newnode->type->base = base->type; 265 266 } // if 266 267 267 // Check: if base has TypeData268 268 return newnode; 269 269 } // DeclarationNode::newEnum … … 285 285 286 286 DeclarationNode * DeclarationNode::newEnumValueGeneric( const string * name, InitializerNode * init ) { 287 if ( init ) { // list init {} or a singleInit288 if ( init->get_expression() ) { // singleInit287 if ( init ) { 288 if ( init->get_expression() ) { 289 289 return newEnumConstant( name, init->get_expression() ); 290 } else { // TODO: listInit290 } else { 291 291 DeclarationNode * newnode = newName( name ); 292 292 newnode->initializer = init; … … 294 294 } // if 295 295 } else { 296 return newName( name ); // Not explicitly inited enum value;296 return newName( name ); 297 297 } // if 298 298 } // DeclarationNode::newEnumValueGeneric -
src/Parser/ExpressionNode.cc
r1c893ae rdc56b9d 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 511 535 DimensionExpr * build_dimensionref( const string * name ) { 512 536 DimensionExpr * expr = new DimensionExpr( *name ); -
src/Parser/ParseNode.h
r1c893ae rdc56b9d 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 ); 185 187 DimensionExpr * build_dimensionref( const std::string * name ); 186 188 … … 235 237 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ); 236 238 static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 237 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, DeclarationNode * base = nullptr );239 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base = nullptr ); 238 240 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 239 241 static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init ); -
src/Parser/TypeData.cc
r1c893ae rdc56b9d 546 546 return buildAggInst( td ); 547 547 case TypeData::EnumConstant: 548 // the name gets filled in later -- by SymTab::Validate549 548 return new EnumInstType( buildQualifiers( td ), "" ); 550 549 case TypeData::SymbolicInst: … … 921 920 assert( td->kind == TypeData::Enum ); 922 921 Type * baseType = td->base ? typebuild(td->base) : nullptr; 923 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage, baseType );922 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, td->enumeration.typed, linkage, baseType ); 924 923 buildList( td->enumeration.constants, ret->get_members() ); 925 924 list< Declaration * >::iterator members = ret->get_members().begin(); 926 925 for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 927 if ( cur->has_enumeratorValue() ) { 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() ) { 928 929 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 929 930 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) ); 930 931 } else if ( !cur->initializer ) { 931 932 if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) { 932 SemanticError( td->location, " A non whole number enum value declmust be explicitly initialized." );933 SemanticError( td->location, "Enumerators of an non-integer typed enum must be explicitly initialized." ); 933 934 } 934 935 } -
src/Parser/TypeData.h
r1c893ae rdc56b9d 59 59 bool body; 60 60 bool anon; 61 bool typed; 61 62 }; 62 63 -
src/Parser/parser.yy
r1c893ae rdc56b9d 637 637 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); } 638 638 | type_name '.' identifier // CFA, nested type 639 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }639 { $$ = new ExpressionNode( build_qualified_expr( $1, build_varref( $3 ) ) ); } 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 )->addQualifiers( $2 ); }2540 { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->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 )->addQualifiers( $2 ); }2544 { $$ = DeclarationNode::newEnum( $3, $6, true, false )->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 )->addQualifiers( $2 ); } 2548 | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2549 { SemanticError( yylloc, "Unvalued enumerated type is currently unimplemented." ); $$ = nullptr; } 2547 { $$ = DeclarationNode::newEnum( $3->name, $5, true, false )->addQualifiers( $2 ); } 2550 2548 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2551 2549 { … … 2553 2551 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2554 2552 2555 $$ = DeclarationNode::newEnum( nullptr, $7, true, $3 )->addQualifiers( $5 ); 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 ); 2556 2558 } 2557 2559 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt … … 2562 2564 '{' enumerator_list comma_opt '}' 2563 2565 { 2564 $$ = DeclarationNode::newEnum( $6, $10, true, $3 )->addQualifiers( $5 )->addQualifiers( $7 ); 2565 } 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 } 2566 2573 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' 2567 2574 { 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 ); 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 ); 2571 2580 } 2572 2581 | enum_type_nobody … … 2575 2584 enum_type_nobody: // enum - {...} 2576 2585 ENUM attribute_list_opt identifier 2577 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); }2578 | ENUM attribute_list_opt type_name // qualified type name2579 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); }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 ); } 2580 2589 ; 2581 2590 -
src/ResolvExpr/CandidateFinder.cpp
r1c893ae rdc56b9d 864 864 } 865 865 866 void postvisit( const ast::QualifiedNameExpr * qualifiedNameExpr ) { 867 auto mangleName = Mangle::mangle(qualifiedNameExpr->var); 868 addCandidate( qualifiedNameExpr, tenv ); 869 } 870 866 871 void postvisit( const ast::UntypedExpr * untypedExpr ) { 867 872 std::vector< CandidateFinder > argCandidates = … … 897 902 } 898 903 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 int907 funcFinder.otypeKeys.insert(Mangle::mangle(enumDecl, Mangle::NoGenericParams | Mangle::Type));908 }909 }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 // } 910 915 else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type)); 911 916 } -
src/ResolvExpr/ConversionCost.cc
r1c893ae rdc56b9d 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 ) { // if the base enum has a base (if it is typed)342 if ( const Type * base = base_enum->base ) { 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 ( const ast::Type * enumType = enumDecl->base.get() ) { 636 if ( enumDecl->isTyped && !enumDecl->base.get() ) { 637 cost = Cost::infinity; 638 } else if ( const ast::Type * enumType = enumDecl->base.get() ) { 637 639 if ( const ast::BasicType * enumTypeAsBasic = dynamic_cast<const ast::BasicType *>(enumType) ) { 638 640 conversionCostFromBasicToBasic( basicType, enumTypeAsBasic ); … … 716 718 const ast::EnumDecl * baseEnum = enumInstType->base; 717 719 if ( const ast::Type * baseType = baseEnum->base ) { 718 cost = costCalc( baseType, dst, srcIsLvalue, symtab, env );720 costCalc( baseType, dst, srcIsLvalue, symtab, env ); 719 721 } else { 720 722 (void)enumInstType; -
src/ResolvExpr/Resolver.cc
r1c893ae rdc56b9d 1478 1478 // enum type is still incomplete at this point. Use `int` instead. 1479 1479 1480 if (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base) { 1480 if ( auto enumBase = dynamic_cast< const ast::EnumInstType * > 1481 ( objectDecl->get_type() )->base->base ) { 1481 1482 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
r1c893ae rdc56b9d 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 167 181 newFirst ->qualifiers = {}; 168 182 newSecond->qualifiers = {}; … … 975 989 if ( isTuple && isTuple2 ) { 976 990 ++it; ++jt; // skip ttype parameters before break 977 } else if ( isTuple ) { 991 } else if ( isTuple ) { 978 992 // bundle remaining params into tuple 979 993 pty2 = tupleFromExprs( param2, jt, params2.end(), pty->qualifiers ); -
src/SymTab/Mangler.cc
r1c893ae rdc56b9d 65 65 void postvisit( const QualifiedType * qualType ); 66 66 67 void postvisit( const QualifiedNameExpr * qualNameExpr ); 68 67 69 std::string get_mangleName() { return mangleName; } 68 70 private: … … 305 307 mangleName += Encoding::qualifiedTypeEnd; 306 308 } 309 } 310 311 void Mangler_old::postvisit( const QualifiedNameExpr * qual ) { 312 maybeAccept( qual->var, *visitor ); 307 313 } 308 314 … … 417 423 void postvisit( const ast::OneType * oneType ); 418 424 void postvisit( const ast::QualifiedType * qualType ); 425 void postvisit( const ast::QualifiedNameExpr * qualNameExpr ); 419 426 420 427 std::string get_mangleName() { return mangleName; } … … 645 652 mangleName += Encoding::qualifiedTypeEnd; 646 653 } 654 } 655 void Mangler_new::postvisit( const ast::QualifiedNameExpr * qual ) { 656 maybeAccept( qual->var.get(), *visitor ); 647 657 } 648 658 -
src/SymTab/Validate.cc
r1c893ae rdc56b9d 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 Decl= dynamic_cast< EnumInstType * >( designatorType ) ) {859 } else if ( EnumInstType * enumInst = dynamic_cast< EnumInstType * >( designatorType ) ) { 860 860 // declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) ); 861 if (enumDecl->baseEnum) { 862 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 ) ); 863 864 } else { 864 declsToAddBefore.push_back( new EnumDecl( enum Decl->name, noAttributes, tyDecl->linkage ) );865 declsToAddBefore.push_back( new EnumDecl( enumInst->name, noAttributes, tyDecl->linkage ) ); 865 866 } 866 867 } // if -
src/SymTab/ValidateType.cc
r1c893ae rdc56b9d 82 82 void postvisit( QualifiedType * qualType ); 83 83 84 void postvisit( QualifiedNameExpr * qualExpr ); 85 84 86 void postvisit( EnumDecl * enumDecl ); 85 87 void postvisit( StructDecl * structDecl ); … … 157 159 // linking only makes sense for the 'oldest ancestor' of the qualified type 158 160 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); 159 166 } 160 167 -
src/SynTree/Declaration.h
r1c893ae rdc56b9d 145 145 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; 146 146 147 // TODO: Move to the right place148 147 void checkAssignedValue() const; 149 148 }; … … 338 337 typedef AggregateDecl Parent; 339 338 public: 339 bool isTyped; 340 Type * base; 341 340 342 EnumDecl( const std::string & name, 341 343 const std::list< Attribute * > & attributes = std::list< class Attribute * >(), 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 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 ) {} 346 349 bool valueOf( Declaration * enumerator, long long int & value ); 347 348 350 virtual EnumDecl * clone() const override { return new EnumDecl( *this ); } 349 351 virtual void accept( Visitor & v ) override { v.visit( this ); } 350 352 virtual void accept( Visitor & v ) const override { v.visit( this ); } 351 353 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 352 Type * base; 353 std::unordered_map< std::string, long long int > enumValues; 354 355 std::unordered_map< std::string, long long int > enumValues; // This attribute is unused 354 356 virtual void print( std::ostream & os, Indenter indent = {} ) const override final; 355 357 private: -
src/SynTree/Expression.h
r1c893ae rdc56b9d 163 163 }; 164 164 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 165 197 /// VariableExpr represents an expression that simply refers to the value of a named variable. 166 198 /// Does not take ownership of var. -
src/SynTree/Mutator.h
r1c893ae rdc56b9d 98 98 virtual Expression * mutate( DefaultArgExpr * argExpr ) = 0; 99 99 virtual Expression * mutate( GenericExpr * genExpr ) = 0; 100 virtual Expression * mutate( QualifiedNameExpr * qualifiedNameExpr ) = 0; 100 101 101 102 virtual Type * mutate( VoidType * basicType ) = 0; -
src/SynTree/SynTree.h
r1c893ae rdc56b9d 103 103 class DefaultArgExpr; 104 104 class GenericExpr; 105 class QualifiedNameExpr; 105 106 106 107 class Type; -
src/SynTree/Type.h
r1c893ae rdc56b9d 345 345 Type * parent; 346 346 Type * child; 347 348 347 QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ); 349 348 QualifiedType( const QualifiedType & tq ); -
src/SynTree/Visitor.h
r1c893ae rdc56b9d 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; 103 105 virtual void visit( CastExpr * node ) { visit( const_cast<const CastExpr *>(node) ); } 104 106 virtual void visit( const CastExpr * castExpr ) = 0; -
src/Validate/Autogen.cpp
r1c893ae rdc56b9d 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 // } 237 244 238 245 ast::EnumInstType enumInst( enumDecl->name ); -
src/Validate/FixQualifiedTypes.cpp
r1c893ae rdc56b9d 19 19 #include "AST/TranslationUnit.hpp" 20 20 #include "Validate/NoIdSymbolTable.hpp" 21 #include "SymTab/Mangler.h" // for Mangler 22 #include "AST/LinkageSpec.hpp" // for Linkage 21 23 22 24 namespace Validate { … … 89 91 } 90 92 } 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 91 121 }; 92 122 -
src/Validate/LinkReferenceToTypes.cpp
r1c893ae rdc56b9d 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); 48 49 49 50 private: … … 292 293 } 293 294 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 294 328 } // namespace 295 329 -
src/Validate/ReplaceTypedef.cpp
r1c893ae rdc56b9d 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, {}, decl->linkage,185 decl->location, enumType->name, false, {}, decl->linkage, 186 186 ( (enumType->base) ? enumType->base->base : nullptr ) 187 187 ) ); -
tests/enum_tests/structEnum.cfa
r1c893ae rdc56b9d 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 } 18 22 19 23 // The only valid usage 20 24 struct Point apple = first; 21 25 // Failed due to Qualified name is currently unimplemented. 22 // struct Point banana = PointEnum.first;23 26 24 27 int main() { 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; 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; 30 38 }
Note: See TracChangeset
for help on using the changeset viewer.