Changes in / [ffec1bf:def751f]


Ignore:
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rffec1bf rdef751f  
    289289                                        if ( obj->get_init() ) {
    290290                                                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();
    292292                                        } else {
    293293                                                output << ++last_val;
  • src/Parser/ExpressionNode.cc

    rffec1bf rdef751f  
    509509} // build_varref
    510510
     511QualifiedNameExpr * 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
    511517DimensionExpr * build_dimensionref( const string * name ) {
    512518        DimensionExpr * expr = new DimensionExpr( *name );
  • src/Parser/ParseNode.h

    rffec1bf rdef751f  
    183183
    184184NameExpr * build_varref( const std::string * name );
     185QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name );
    185186DimensionExpr * build_dimensionref( const std::string * name );
    186187
  • src/ResolvExpr/CandidateFinder.cpp

    rffec1bf rdef751f  
    897897                                                }
    898898
    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                                                 }
     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; // Here
     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                                                // }
    910910                                                else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type));
    911911                                        }
  • src/ResolvExpr/ConversionCost.cc

    rffec1bf rdef751f  
    695695        if ( const ast::Type * baseType = baseEnum->base ) {
    696696                cost = costCalc( baseType, dst, srcIsLvalue, symtab, env );
     697                // cost = Cost::safe;
    697698        } else {
    698699                (void)enumInstType;
  • src/ResolvExpr/Unify.cc

    rffec1bf rdef751f  
    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
    167181                newFirst ->qualifiers = {};
    168182                newSecond->qualifiers = {};
     
    9881002                                if ( isTuple && isTuple2 ) {
    9891003                                        ++it; ++jt;  // skip ttype parameters before break
    990                                 } else if ( isTuple ) {
     1004                                } else if ( isTuple ) { 
    9911005                                        // bundle remaining params into tuple
    9921006                                        pty2 = tupleFromExprs( param2, jt, params2.end(), pty->qualifiers );
  • src/SynTree/Expression.h

    rffec1bf rdef751f  
    163163};
    164164
     165// [Qualifier].name; Qualifier is the type_name from the parser
     166class QualifiedNameExpr : public Expression {
     167  public:
     168        Type * type; // Convert to [parent] QualifiedNameExpr
     169        std::string name; // Convert from NameExpr
     170
     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
    165195/// VariableExpr represents an expression that simply refers to the value of a named variable.
    166196/// Does not take ownership of var.
  • src/SynTree/SynTree.h

    rffec1bf rdef751f  
    103103class DefaultArgExpr;
    104104class GenericExpr;
     105class QualifiedNameExpr;
    105106
    106107class Type;
  • src/Validate/Autogen.cpp

    rffec1bf rdef751f  
    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        // }
    237244
    238245        ast::EnumInstType enumInst( enumDecl->name );
  • tests/enum_tests/structEnum.cfa

    rffec1bf rdef751f  
    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
     19PointEnum foo(PointEnum in) {
     20     return in;
     21}
    1822
    1923// The only valid usage
    2024struct Point apple = first;
    2125// Failed due to Qualified name is currently unimplemented.
    22 // struct Point banana = PointEnum.first;
     26struct Point banana = PointEnum.first;
    2327
    2428int 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;
     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;
    3039}
Note: See TracChangeset for help on using the changeset viewer.