Changes in / [def751f:ffec1bf]
- Files:
-
- 10 edited
-
src/CodeGen/CodeGenerator.cc (modified) (1 diff)
-
src/Parser/ExpressionNode.cc (modified) (1 diff)
-
src/Parser/ParseNode.h (modified) (1 diff)
-
src/ResolvExpr/CandidateFinder.cpp (modified) (1 diff)
-
src/ResolvExpr/ConversionCost.cc (modified) (1 diff)
-
src/ResolvExpr/Unify.cc (modified) (2 diffs)
-
src/SynTree/Expression.h (modified) (1 diff)
-
src/SynTree/SynTree.h (modified) (1 diff)
-
src/Validate/Autogen.cpp (modified) (1 diff)
-
tests/enum_tests/structEnum.cfa (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rdef751f rffec1bf 289 289 if ( obj->get_init() ) { 290 290 obj->get_init()->accept( *visitor ); 291 //last_val = ((ConstantExpr *)(((SingleInit *)(obj->init))->value))->constant.get_ival();291 last_val = ((ConstantExpr *)(((SingleInit *)(obj->init))->value))->constant.get_ival(); 292 292 } else { 293 293 output << ++last_val; -
src/Parser/ExpressionNode.cc
rdef751f rffec1bf 509 509 } // build_varref 510 510 511 QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name ) {512 Type * targetType = maybeMoveBuildType( decl_node );513 return new QualifiedNameExpr( targetType, name->name );514 return nullptr;515 }516 517 511 DimensionExpr * build_dimensionref( const string * name ) { 518 512 DimensionExpr * expr = new DimensionExpr( *name ); -
src/Parser/ParseNode.h
rdef751f rffec1bf 183 183 184 184 NameExpr * build_varref( const std::string * name ); 185 QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name );186 185 DimensionExpr * build_dimensionref( const std::string * name ); 187 186 -
src/ResolvExpr/CandidateFinder.cpp
rdef751f rffec1bf 897 897 } 898 898 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; // Here902 //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 // }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 } 910 910 else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type)); 911 911 } -
src/ResolvExpr/ConversionCost.cc
rdef751f rffec1bf 695 695 if ( const ast::Type * baseType = baseEnum->base ) { 696 696 cost = costCalc( baseType, dst, srcIsLvalue, symtab, env ); 697 // cost = Cost::safe;698 697 } else { 699 698 (void)enumInstType; -
src/ResolvExpr/Unify.cc
rdef751f rffec1bf 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 = {}; … … 1002 988 if ( isTuple && isTuple2 ) { 1003 989 ++it; ++jt; // skip ttype parameters before break 1004 } else if ( isTuple ) { 990 } else if ( isTuple ) { 1005 991 // bundle remaining params into tuple 1006 992 pty2 = tupleFromExprs( param2, jt, params2.end(), pty->qualifiers ); -
src/SynTree/Expression.h
rdef751f rffec1bf 163 163 }; 164 164 165 // [Qualifier].name; Qualifier is the type_name from the parser166 class QualifiedNameExpr : public Expression {167 public:168 Type * type; // Convert to [parent] QualifiedNameExpr169 std::string name; // Convert from NameExpr170 171 QualifiedNameExpr( Type * type, std::string name):172 Expression(), type(type), name(name) {173 std::cout << "Making QualifiedNameExpr" << std::endl;174 print( std::cout );175 }176 QualifiedNameExpr( const QualifiedNameExpr & other): Expression(other), type(other.type), name(other.name) {177 178 }179 virtual ~QualifiedNameExpr() {180 delete type;181 }182 183 virtual QualifiedNameExpr * clone() const override {184 return new QualifiedNameExpr( * this );185 }186 virtual void accept( Visitor & v ) override { (void)v; }187 virtual void accept( Visitor & v ) const override { (void)v; }188 virtual Expression * acceptMutator( Mutator & m ) override { (void) m;return nullptr; }189 virtual void print( std::ostream & os, Indenter indent = {} ) const override {190 type->print( os, indent );191 std::cout << name << std::endl;192 }193 };194 195 165 /// VariableExpr represents an expression that simply refers to the value of a named variable. 196 166 /// Does not take ownership of var. -
src/SynTree/SynTree.h
rdef751f rffec1bf 103 103 class DefaultArgExpr; 104 104 class GenericExpr; 105 class QualifiedNameExpr;106 105 107 106 class Type; -
src/Validate/Autogen.cpp
rdef751f rffec1bf 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 ); -
tests/enum_tests/structEnum.cfa
rdef751f rffec1bf 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. 26 struct Point banana = PointEnum.first;22 // struct Point banana = PointEnum.first; 27 23 28 24 int main() { 29 PointEnum vals = second; 30 PointEnum val2; 31 // P1 32 val2 = vals; 33 34 printf("%d %c\n", apple.x, apple.y); 35 // Failed; enumInstType is now not a real type and not instantiated. 36 // Not sure if we want that 37 // printf("%d %c\n", second.x, second.y); 38 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; 39 30 }
Note:
See TracChangeset
for help on using the changeset viewer.