Changeset 9ddcee1


Ignore:
Timestamp:
Feb 1, 2024, 5:13:04 PM (15 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
020fa10
Parents:
496ffc17
Message:

Remove EnumPosExpr?, an early design that no longer used. The implementation of the feature has been replaced by ReplacePseudoFunc?

Location:
src
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/AST/Expr.cpp

    r496ffc17 r9ddcee1  
    307307}
    308308
    309 //
    310 
    311 // --- EnumPosExpr
    312 EnumPosExpr::EnumPosExpr( const CodeLocation & loc, const EnumInstType * ty)
    313 : Expr( loc, new BasicType{ BasicType::UnsignedInt }), type( ty ) {
    314         assert( ty );
    315 }
    316 
    317 EnumPosExpr::EnumPosExpr( const CodeLocation & loc, const Expr * expr )
    318 : Expr( loc, new BasicType{ BasicType::UnsignedInt }), expr(expr) {
    319         assert( expr );
    320 }
    321 
    322 
    323309// --- LogicalExpr
    324310
  • TabularUnified src/AST/Expr.hpp

    r496ffc17 r9ddcee1  
    548548};
    549549
    550 class EnumPosExpr final : public Expr {
    551 public:
    552         ptr<EnumInstType> type;
    553         ptr<Expr> expr;
    554        
    555         EnumPosExpr( const CodeLocation & loc, const EnumInstType * ty );
    556         EnumPosExpr( const CodeLocation & loc, const Expr * expr );
    557         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    558 private:
    559         EnumPosExpr * clone() const override { return new EnumPosExpr{ *this }; }
    560         MUTATE_FRIEND
    561 };
    562 
    563550/// Variants of short-circuiting logical expression
    564551enum LogicalFlag { OrExpr, AndExpr };
  • TabularUnified src/AST/Fwd.hpp

    r496ffc17 r9ddcee1  
    8989class OffsetofExpr;
    9090class OffsetPackExpr;
    91 class EnumPosExpr;
    9291class LogicalExpr;
    9392class ConditionalExpr;
  • TabularUnified src/AST/Node.cpp

    r496ffc17 r9ddcee1  
    232232template class ast::ptr_base< ast::OffsetPackExpr, ast::Node::ref_type::weak >;
    233233template class ast::ptr_base< ast::OffsetPackExpr, ast::Node::ref_type::strong >;
    234 template class ast::ptr_base< ast::EnumPosExpr, ast::Node::ref_type::weak >;
    235 template class ast::ptr_base< ast::EnumPosExpr, ast::Node::ref_type::strong >;
    236234template class ast::ptr_base< ast::LogicalExpr, ast::Node::ref_type::weak >;
    237235template class ast::ptr_base< ast::LogicalExpr, ast::Node::ref_type::strong >;
  • TabularUnified src/AST/Pass.hpp

    r496ffc17 r9ddcee1  
    191191        const ast::Expr *             visit( const ast::OffsetofExpr         * ) override final;
    192192        const ast::Expr *             visit( const ast::OffsetPackExpr       * ) override final;
    193         const ast::Expr *             visit( const ast::EnumPosExpr          * ) override final;
    194193        const ast::Expr *             visit( const ast::LogicalExpr          * ) override final;
    195194        const ast::Expr *             visit( const ast::ConditionalExpr      * ) override final;
  • TabularUnified src/AST/Pass.impl.hpp

    r496ffc17 r9ddcee1  
    14521452
    14531453//--------------------------------------------------------------------------
    1454 // EnumPosExpr
    1455 template< typename core_t>
    1456 const ast::Expr * ast::Pass< core_t >::visit( const ast::EnumPosExpr * node ) {
    1457         VISIT_START( node );
    1458 
    1459         if ( __visit_children() ) {
    1460                 guard_symtab guard { *this };
    1461                 maybe_accept( node, &EnumPosExpr::type );
    1462                 maybe_accept( node, &EnumPosExpr::expr );
    1463         }
    1464 
    1465         VISIT_END( Expr, node );
    1466 }
    1467 
    1468 //--------------------------------------------------------------------------
    14691454// LogicalExpr
    14701455template< typename core_t >
  • TabularUnified src/AST/Print.cpp

    r496ffc17 r9ddcee1  
    11861186        }
    11871187
    1188         virtual const ast::Expr * visit( const ast::EnumPosExpr * node ) override final {
    1189                 os << "Enum Position Expression on: ";
    1190                 ++indent;
    1191                 safe_print( node->type );
    1192                 --indent;
    1193                 postprint( node );
    1194                 return node;
    1195         }
    1196 
    11971188        virtual const ast::Expr * visit( const ast::LogicalExpr * node ) override final {
    11981189                os << "Short-circuited operation (" << (node->isAnd ? "and" : "or") << ") on: ";
  • TabularUnified src/AST/Visitor.hpp

    r496ffc17 r9ddcee1  
    7979    virtual const ast::Expr *             visit( const ast::OffsetofExpr         * ) = 0;
    8080    virtual const ast::Expr *             visit( const ast::OffsetPackExpr       * ) = 0;
    81     virtual const ast::Expr *             visit( const ast::EnumPosExpr          * ) = 0;
    8281    virtual const ast::Expr *             visit( const ast::LogicalExpr          * ) = 0;
    8382    virtual const ast::Expr *             visit( const ast::ConditionalExpr      * ) = 0;
  • TabularUnified src/CodeGen/CodeGenerator.cpp

    r496ffc17 r9ddcee1  
    778778}
    779779
    780 void CodeGenerator::postvisit( ast::EnumPosExpr const * expr ) {
    781         assertf( !options.genC, "EnumPosExpr should not reach code generation." );
    782         output << "__CFA_enumeration_pos(" << genType( expr->type, "", options ) << ")";
    783 }
    784 
    785780void CodeGenerator::postvisit( ast::LogicalExpr const * expr ) {
    786781        extension( expr );
  • TabularUnified src/CodeGen/CodeGenerator.hpp

    r496ffc17 r9ddcee1  
    7777        void postvisit( ast::OffsetPackExpr const * );
    7878        void postvisit( ast::LogicalExpr const * );
    79         void postvisit( ast::EnumPosExpr const * );
    8079        void postvisit( ast::ConditionalExpr const * );
    8180        void postvisit( ast::CommaExpr const * );
  • TabularUnified src/Common/CodeLocationTools.cpp

    r496ffc17 r9ddcee1  
    158158    macro(OffsetPackExpr, Expr) \
    159159    macro(LogicalExpr, Expr) \
    160         macro(EnumPosExpr, Expr) \
    161160    macro(ConditionalExpr, Expr) \
    162161    macro(CommaExpr, Expr) \
  • TabularUnified src/GenPoly/Box.cpp

    r496ffc17 r9ddcee1  
    15801580        ast::Expr const * postvisit( ast::OffsetPackExpr const * expr );
    15811581
    1582         ast::Expr const * postvisit( ast::EnumPosExpr const * expr );
    1583 
    15841582        void beginScope();
    15851583        void endScope();
     
    19521950
    19531951        return new ast::VariableExpr( expr->location, offsetArray );
    1954 }
    1955 
    1956 // TODO
    1957 ast::Expr const * PolyGenericCalculator::postvisit( ast::EnumPosExpr const * expr ) {
    1958         return expr;
    19591952}
    19601953
  • TabularUnified src/InitTweak/InitTweak.cc

    r496ffc17 r9ddcee1  
    271271                void previsit( const ast::OffsetofExpr * ) {}
    272272                void previsit( const ast::OffsetPackExpr * ) {}
    273                 void previsit( const ast::EnumPosExpr * ) {}
    274273                void previsit( const ast::CommaExpr * ) {}
    275274                void previsit( const ast::LogicalExpr * ) {}
  • TabularUnified src/Parser/ExpressionNode.cc

    r496ffc17 r9ddcee1  
    690690} // build_unary_val
    691691
    692 ast::Expr * build_enum_pos_expr( const CodeLocation & location, ast::Expr * expr_node ) {
    693         // return nullptr
    694         return new ast::EnumPosExpr( location, std::move( expr_node ) );
    695 }
    696 
    697692ast::Expr * build_binary_val( const CodeLocation & location,
    698693                OperKinds op,
  • TabularUnified src/ResolvExpr/CandidateFinder.cpp

    r496ffc17 r9ddcee1  
    659659                void postvisit( const ast::OffsetofExpr * offsetofExpr );
    660660                void postvisit( const ast::OffsetPackExpr * offsetPackExpr );
    661                 void postvisit( const ast::EnumPosExpr * enumPosExpr );
    662661                void postvisit( const ast::LogicalExpr * logicalExpr );
    663662                void postvisit( const ast::ConditionalExpr * conditionalExpr );
     
    15071506        void Finder::postvisit( const ast::OffsetPackExpr * offsetPackExpr ) {
    15081507                addCandidate( offsetPackExpr, tenv );
    1509         }
    1510 
    1511         void Finder::postvisit( const ast::EnumPosExpr * enumPosExpr ) {
    1512                 CandidateFinder finder( context, tenv );
    1513                 finder.find( enumPosExpr->expr );
    1514                 CandidateList winners = findMinCost( finder.candidates );
    1515                 if ( winners.size() != 1 ) SemanticError( enumPosExpr->expr.get(), "Ambiguous expression in position. ");
    1516                 CandidateRef & choice = winners.front();
    1517                 auto refExpr = referenceToRvalueConversion( choice->expr, choice->cost );
    1518                 auto refResult = (refExpr->result).as<ast::EnumInstType>();
    1519                 if ( !refResult ) {
    1520                         SemanticError( refExpr, "Position for Non enum type is not supported" );
    1521                 }
    1522                 // determineEnumPosConstant( enumPosExpr, refResult );
    1523 
    1524                 const ast::NameExpr * const nameExpr = enumPosExpr->expr.strict_as<ast::NameExpr>();
    1525                 const ast::EnumDecl * base = refResult->base;
    1526                 if ( !base ) {
    1527                         SemanticError( enumPosExpr, "Cannot be reference to a defined enumeration type" );
    1528                 }
    1529                 auto it = std::find_if( std::begin( base->members ), std::end( base->members ),
    1530                         [nameExpr]( ast::ptr<ast::Decl> decl ) { return decl->name == nameExpr->name; } );
    1531                 unsigned position = it - base->members.begin();
    1532                 addCandidate( ast::ConstantExpr::from_int( enumPosExpr->location, position ), tenv );
    15331508        }
    15341509
  • TabularUnified src/ResolvExpr/ConversionCost.cc

    r496ffc17 r9ddcee1  
    361361}
    362362
    363 void ConversionCost::postvisit( const ast::EnumInstType * enumInstType ) {
    364         //      const ast::EnumDecl * baseEnum = enumInstType->base;
    365         // if ( const ast::Type * baseType = baseEnum->base ) {
    366         //      costCalc( baseType, dst, srcIsLvalue, symtab, env );
    367         // } else {
     363void ConversionCost::postvisit( const ast::EnumInstType * ) {
    368364        static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
    369365        cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
  • TabularUnified src/ResolvExpr/Resolver.cc

    r496ffc17 r9ddcee1  
    411411                const ast::ConstructorInit * previsit( const ast::ConstructorInit * );
    412412
    413                 const ast::EnumPosExpr *         previsit( const ast::EnumPosExpr * );
    414 
    415413                void resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd);
    416414
     
    12321230        }
    12331231
    1234         const ast::EnumPosExpr * Resolver::previsit( const ast::EnumPosExpr * enumPos ) {
    1235                 visitor->maybe_accept( enumPos, &ast::EnumPosExpr::expr );
    1236                 return enumPos;
    1237         }
    1238 
    12391232        // suppress error on autogen functions and mark invalid autogen as deleted.
    12401233        bool Resolver::on_error(ast::ptr<ast::Decl> & decl) {
Note: See TracChangeset for help on using the changeset viewer.