Changes in / [57e43cd:348f8992]


Ignore:
Files:
1 deleted
18 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/enum.cfa

    r57e43cd r348f8992  
    1313    return os | type_name(e) | "." | labelE(e);
    1414}
    15 
    16 forall(ostype & | basic_ostream(ostype), E, V| CfaEnum(E, V)) {
    17     int ?==?(E l, E r) { return posE(l) == posE(r); }
    18     int ?<=?(E l, E r) { return posE(l) <= posE(r); }
    19     int ?>=?(E l, E r) { return posE(l) >= posE(r); }
    20     int ?<?(E l, E r) { return posE(l) < posE(r); }
    21     int ?>?(E l, E r) { return posE(l) > posE(r); }
    22 }
  • libcfa/src/enum.hfa

    r57e43cd r348f8992  
    3838//     V valueE(E e);
    3939// };
    40 
    41 forall(ostype & | basic_ostream(ostype), E, V| CfaEnum(E, V)) {
    42     int ?==?(E, E);
    43     int ?<=?(E, E);
    44     int ?>=?(E, E);
    45     int ?<?(E, E);
    46     int ?>?(E, E);
    47 
    48         // E ++?( E & lhs );
    49         // E ?++( E & lhs );
    50 }
  • src/AST/Expr.cpp

    r57e43cd r348f8992  
    282282: Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( nullptr ), type( t ) {}
    283283
    284 // --- CountExpr
    285 
    286 CountExpr::CountExpr( const CodeLocation & loc, const Type * t )
    287 : Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), type( t ) {}
    288 
    289284// --- AlignofExpr
    290285
  • src/AST/Expr.hpp

    r57e43cd r348f8992  
    494494};
    495495
    496 class CountExpr final : public Expr {
    497 public:
    498         ptr<Type> type;
    499 
    500         CountExpr( const CodeLocation & loc, const Type * t );
    501 
    502         const Expr * accept( Visitor & v )const override { return v.visit( this ); }
    503 private:
    504         CountExpr * clone() const override { return new CountExpr( *this ); }
    505         MUTATE_FRIEND
    506 };
    507 
    508496/// alignof expression, e.g. `alignof(int)`, `alignof 3+4`
    509497class AlignofExpr final : public Expr {
  • src/AST/Fwd.hpp

    r57e43cd r348f8992  
    8585class ConstantExpr;
    8686class SizeofExpr;
    87 class CountExpr;
    8887class AlignofExpr;
    8988class UntypedOffsetofExpr;
  • src/AST/Pass.hpp

    r57e43cd r348f8992  
    172172        const ast::Expr *             visit( const ast::ConstantExpr         * ) override final;
    173173        const ast::Expr *             visit( const ast::SizeofExpr           * ) override final;
    174         const ast::Expr *             visit( const ast::CountExpr            * ) override final;
    175174        const ast::Expr *             visit( const ast::AlignofExpr          * ) override final;
    176175        const ast::Expr *             visit( const ast::UntypedOffsetofExpr  * ) override final;
  • src/AST/Pass.impl.hpp

    r57e43cd r348f8992  
    802802                maybe_accept_top( node, &ForStmt::cond  );
    803803                maybe_accept_top( node, &ForStmt::inc   );
    804                 maybe_accept_top( node, &ForStmt::range_over );
    805804                maybe_accept_as_compound( node, &ForStmt::body  );
    806805        }
     
    13241323        }
    13251324
    1326         VISIT_END( Expr, node );
    1327 }
    1328 
    1329 //--------------------------------------------------------------------------
    1330 // CountExpr
    1331 template< typename core_t >
    1332 const ast::Expr * ast::Pass< core_t >::visit( const ast::CountExpr * node ) {
    1333         VISIT_START( node );
    1334         if ( __visit_children() ) {
    1335                 {
    1336                         guard_symtab guard { *this };
    1337                         maybe_accept( node, &CountExpr::result );
    1338                 }
    1339                 maybe_accept( node, &CountExpr::type );
    1340         }
    13411325        VISIT_END( Expr, node );
    13421326}
  • src/AST/Print.cpp

    r57e43cd r348f8992  
    11431143        }
    11441144
    1145         virtual const ast::Expr * visit( const ast::CountExpr * node ) override final {
    1146                 os << "Count Expression on: ";
    1147                 ++indent;
    1148                 node->type->accept( *this );
    1149                 --indent;
    1150                 postprint( node );
    1151                 return node;
    1152         }
    1153 
    11541145        virtual const ast::Expr * visit( const ast::AlignofExpr * node ) override final {
    11551146                os << "Alignof Expression on: ";
  • src/AST/Stmt.hpp

    r57e43cd r348f8992  
    237237        ptr<Expr> cond;
    238238        ptr<Expr> inc;
    239         ptr<Expr> range_over;
    240239        ptr<Stmt> body;
    241240        ptr<Stmt> else_;
     
    243242        ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond,
    244243                         const Expr * inc, const Stmt * body, const std::vector<Label> && label = {} )
    245                 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc),
    246                         range_over(nullptr), body(body), else_(nullptr) {}
     244                : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(nullptr) {}
    247245
    248246        ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond,
    249247                         const Expr * inc, const Stmt * body, const Stmt * else_, const std::vector<Label> && labels = {} )
    250                 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc),
    251                         range_over(nullptr), body(body), else_(else_) {}
    252 
    253         ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * range_over,
    254                          const Stmt * body, const Stmt * else_ )
    255                 : Stmt(loc, std::move(labels)), inits(std::move(inits)), range_over(range_over), body(body), else_(else_) {}
     248                : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(else_) {}
    256249
    257250        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/Visitor.hpp

    r57e43cd r348f8992  
    7575    virtual const ast::Expr *             visit( const ast::ConstantExpr         * ) = 0;
    7676    virtual const ast::Expr *             visit( const ast::SizeofExpr           * ) = 0;
    77     virtual const ast::Expr *             visit( const ast::CountExpr            * ) = 0;
    7877    virtual const ast::Expr *             visit( const ast::AlignofExpr          * ) = 0;
    7978    virtual const ast::Expr *             visit( const ast::UntypedOffsetofExpr  * ) = 0;
  • src/Common/CodeLocationTools.cpp

    r57e43cd r348f8992  
    153153    macro(ConstantExpr, Expr) \
    154154    macro(SizeofExpr, Expr) \
    155     macro(CountExpr, Expr ) \
    156155    macro(AlignofExpr, Expr) \
    157156    macro(UntypedOffsetofExpr, Expr) \
  • src/ControlStruct/module.mk

    r57e43cd r348f8992  
    2727        ControlStruct/LabelGenerator.hpp \
    2828        ControlStruct/MultiLevelExit.cpp \
    29         ControlStruct/MultiLevelExit.hpp \
    30         ControlStruct/TranslateEnumRange.cpp \
    31         ControlStruct/TranslateEnumRange.hpp
     29        ControlStruct/MultiLevelExit.hpp
    3230
  • src/Parser/StatementNode.cpp

    r57e43cd r348f8992  
    211211        buildMoveList( forctl->init, astinit );
    212212
    213         if ( forctl->range_over ) {
    214                 ast::Expr * range_over = maybeMoveBuild( forctl->range_over );
    215                 delete forctl;
    216                 return new ast::ForStmt( location,
    217                         std::move( astinit ),
    218                         range_over,
    219                         buildMoveSingle( stmt ),
    220                         buildMoveOptional( else_ )
    221                 );
    222         }
    223 
    224213        ast::Expr * astcond = nullptr;                                          // maybe empty
    225214        astcond = maybeMoveBuild( forctl->condition );
  • src/Parser/StatementNode.hpp

    r57e43cd r348f8992  
    6363struct ForCtrl {
    6464        ForCtrl( StatementNode * stmt, ExpressionNode * condition, ExpressionNode * change ) :
    65                 init( stmt ), condition( condition ), change( change ), range_over( nullptr ) {}
    66         ForCtrl( StatementNode * decl, ExpressionNode * _range_over) :
    67                 init( decl ), condition( nullptr ), change( nullptr ),  range_over( _range_over ) {}
     65                init( stmt ), condition( condition ), change( change ) {}
    6866
    6967        StatementNode * init;
    7068        ExpressionNode * condition;
    7169        ExpressionNode * change;
    72         ExpressionNode * range_over;
    7370};
    7471
  • src/Parser/lex.ll

    r57e43cd r348f8992  
    321321__signed__              { KEYWORD_RETURN(SIGNED); }                             // GCC
    322322sizeof                  { KEYWORD_RETURN(SIZEOF); }
    323 __count_e__             { KEYWORD_RETURN(COUNT); }                              // GCC
    324323static                  { KEYWORD_RETURN(STATIC); }
    325324_Static_assert  { KEYWORD_RETURN(STATICASSERT); }               // C11
  • src/Parser/parser.yy

    r57e43cd r348f8992  
    284284} // forCtrl
    285285
    286 ForCtrl * enumRangeCtrl( ExpressionNode * index_expr, ExpressionNode * range_over_expr ) {
    287         if ( auto identifier = dynamic_cast<ast::NameExpr *>(index_expr->expr.get()) ) {
    288                 DeclarationNode * indexDecl =
    289                         DeclarationNode::newName( new std::string(identifier->name) );
    290                 assert( range_over_expr );
    291                 auto node = new StatementNode( indexDecl ); // <- this cause this error
    292                 return new ForCtrl( node, range_over_expr );
    293         } else if (auto commaExpr = dynamic_cast<ast::CommaExpr *>( index_expr->expr.get() )) {
    294                 if ( auto identifier = commaExpr->arg1.as<ast::NameExpr>() ) {
    295                         assert( range_over_expr );
    296                         DeclarationNode * indexDecl = distAttr(
    297                                 DeclarationNode::newTypeof( range_over_expr, true ),
    298                                 DeclarationNode::newName( new std::string( identifier->name) ) );
    299                         return new ForCtrl( new StatementNode( indexDecl ), range_over_expr );
    300                 } else {
    301                         SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;
    302                 } // if
    303         } else {
    304                 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;
    305         } // if
    306 } // enumRangeCtrl
    307 
    308286static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) {
    309287        SemanticError( yylloc, "syntax error, adjacent identifiers \"%s\" and \"%s\" are not meaningful in an %s.\n"
     
    390368%token DECIMAL32 DECIMAL64 DECIMAL128                                   // GCC
    391369%token ZERO_T ONE_T                                                                             // CFA
    392 %token SIZEOF TYPEOF VA_LIST VA_ARG AUTO_TYPE COUNT             // GCC
     370%token SIZEOF TYPEOF VA_LIST VA_ARG AUTO_TYPE                   // GCC
    393371%token OFFSETOF BASETYPEOF TYPEID                                               // CFA
    394372%token ENUM STRUCT UNION
     
    990968                        // $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) );
    991969                }
    992         | COUNT '(' type ')'
    993                 {
    994                         // SemanticError( yylloc, "Count is currently unimplemented. "); $$ = nullptr;
    995                         $$ = new ExpressionNode( new ast::CountExpr( yylloc, maybeMoveBuildType( $3 ) ) );
    996                 }
    997970        ;
    998971
     
    16261599                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    16271600
    1628         | comma_expression ';' enum_type                                        // CFA, enum type
    1629                 {
    1630                         $$ = enumRangeCtrl( $1, new ExpressionNode( new ast::TypeExpr(yylloc, $3->buildType() ) ) );
    1631                 }
    1632         | comma_expression ';' downupdowneq enum_type           // CFA, enum type, reverse direction
     1601        | comma_expression ';' enum_key                                         // CFA, enum type
     1602                {
     1603                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
     1604                        //$$ = forCtrl( new ExpressionNode( build_varref( $3 ) ), $1, nullptr, OperKinds::Range, nullptr, nullptr );
     1605                }
     1606        | comma_expression ';' downupdowneq enum_key            // CFA, enum type, reverse direction
    16331607                {
    16341608                        if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) {
     
    16371611                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
    16381612                }
     1613        ;
     1614
     1615enum_key:
     1616        TYPEDEFname
     1617        | ENUM identifier_or_type_name
    16391618        ;
    16401619
  • src/ResolvExpr/CandidateFinder.cpp

    r57e43cd r348f8992  
    696696                void postvisit( const ast::UntypedInitExpr * initExpr );
    697697                void postvisit( const ast::QualifiedNameExpr * qualifiedExpr );
    698                 void postvisit( const ast::CountExpr * countExpr );
    699698
    700699                const ast::Expr * makeEnumOffsetCast( const ast::EnumInstType * src,
     
    15281527                        addCandidate( *choice, new ast::SizeofExpr{ sizeofExpr->location, choice->expr } );
    15291528                }
    1530         }
    1531 
    1532         void Finder::postvisit( const ast::CountExpr * countExpr ) {
    1533                 assert( countExpr->type );
    1534                 auto enumInst = countExpr->type.as<ast::EnumInstType>();
    1535                 if ( !enumInst ) {
    1536                         SemanticError( countExpr, "Count Expression only supports Enum Type as operand: ");
    1537                 }
    1538                 addCandidate( ast::ConstantExpr::from_ulong(countExpr->location, enumInst->base->members.size()), tenv );
    15391529        }
    15401530
  • src/main.cpp

    r57e43cd r348f8992  
    5353#include "ControlStruct/FixLabels.hpp"      // for fixLabels
    5454#include "ControlStruct/HoistControlDecls.hpp" //  hoistControlDecls
    55 #include "ControlStruct/TrasnlateEnumRange.hpp" // translateEnumRange
    5655#include "GenPoly/Box.hpp"                  // for box
    5756#include "GenPoly/InstantiateGeneric.hpp"   // for instantiateGeneric
     
    324323                PASS( "Hoist Struct", Validate::hoistStruct, transUnit );
    325324                PASS( "Validate Generic Parameters", Validate::fillGenericParameters, transUnit );
    326                 PASS( "Translate Enum Range Expression", ControlStruct::translateEnumRange, transUnit );
    327325                PASS( "Translate Dimensions", Validate::translateDimensionParameters, transUnit );
    328326                // Need to happen before fixing returns because implementEnumFunc has ReturnStmt
Note: See TracChangeset for help on using the changeset viewer.