Changes in / [f988834:e8b3717]


Ignore:
Location:
src
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    rf988834 re8b3717  
    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
  • src/AST/Expr.hpp

    rf988834 re8b3717  
    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 };
  • src/AST/Fwd.hpp

    rf988834 re8b3717  
    8989class OffsetofExpr;
    9090class OffsetPackExpr;
    91 class EnumPosExpr;
    9291class LogicalExpr;
    9392class ConditionalExpr;
  • src/AST/Node.cpp

    rf988834 re8b3717  
    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 >;
  • src/AST/Pass.hpp

    rf988834 re8b3717  
    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;
  • src/AST/Pass.impl.hpp

    rf988834 re8b3717  
    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 >
  • src/AST/Print.cpp

    rf988834 re8b3717  
    11831183        }
    11841184
    1185         virtual const ast::Expr * visit( const ast::EnumPosExpr * node ) override final {
    1186                 os << "Enum Position Expression on: ";
    1187                 ++indent;
    1188                 safe_print( node->type );
    1189                 --indent;
    1190                 postprint( node );
    1191                 return node;
    1192         }
    1193 
    11941185        virtual const ast::Expr * visit( const ast::LogicalExpr * node ) override final {
    11951186                os << "Short-circuited operation (" << (node->isAnd ? "and" : "or") << ") on: ";
  • src/AST/Visitor.hpp

    rf988834 re8b3717  
    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;
  • src/CodeGen/CodeGenerator.cpp

    rf988834 re8b3717  
    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 );
  • src/CodeGen/CodeGenerator.hpp

    rf988834 re8b3717  
    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 * );
  • src/Common/CodeLocationTools.cpp

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

    rf988834 re8b3717  
    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
  • src/InitTweak/InitTweak.cc

    rf988834 re8b3717  
    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 * ) {}
  • src/Parser/ExpressionNode.cc

    rf988834 re8b3717  
    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,
  • src/Parser/ExpressionNode.h

    rf988834 re8b3717  
    8383ast::Expr * build_func( const CodeLocation &, ExpressionNode * function, ExpressionNode * expr_node );
    8484ast::Expr * build_compoundLiteral( const CodeLocation &, DeclarationNode * decl_node, InitializerNode * kids );
    85 
    86 ast::Expr * build_enum_pos_expr( const CodeLocation &, ast::Expr * expr_node );
  • src/ResolvExpr/CandidateFinder.cpp

    rf988834 re8b3717  
    5252#include "Common/Stats/Counter.h"
    5353
    54 #include "AST/Inspect.hpp"             // for getFunctionName
    55 
    5654#define PRINT( text ) if ( resolvep ) { text }
    5755
     
    658656                void postvisit( const ast::OffsetofExpr * offsetofExpr );
    659657                void postvisit( const ast::OffsetPackExpr * offsetPackExpr );
    660                 void postvisit( const ast::EnumPosExpr * enumPosExpr );
    661658                void postvisit( const ast::LogicalExpr * logicalExpr );
    662659                void postvisit( const ast::ConditionalExpr * conditionalExpr );
     
    14741471        void Finder::postvisit( const ast::OffsetPackExpr * offsetPackExpr ) {
    14751472                addCandidate( offsetPackExpr, tenv );
    1476         }
    1477 
    1478         void Finder::postvisit( const ast::EnumPosExpr * enumPosExpr ) {
    1479                 CandidateFinder finder( context, tenv );
    1480                 finder.find( enumPosExpr->expr );
    1481                 CandidateList winners = findMinCost( finder.candidates );
    1482                 if ( winners.size() != 1 ) SemanticError( enumPosExpr->expr.get(), "Ambiguous expression in position. ");
    1483                 CandidateRef & choice = winners.front();
    1484                 auto refExpr = referenceToRvalueConversion( choice->expr, choice->cost );
    1485                 auto refResult = (refExpr->result).as<ast::EnumInstType>();
    1486                 if ( !refResult ) {
    1487                         SemanticError( refExpr, "Position for Non enum type is not supported" );
    1488                 }
    1489                 // determineEnumPosConstant( enumPosExpr, refResult );
    1490 
    1491                 const ast::NameExpr * const nameExpr = enumPosExpr->expr.strict_as<ast::NameExpr>();
    1492                 const ast::EnumDecl * base = refResult->base;
    1493                 if ( !base ) {
    1494                         SemanticError( enumPosExpr, "Cannot be reference to a defined enumeration type" );
    1495                 }
    1496                 auto it = std::find_if( std::begin( base->members ), std::end( base->members ),
    1497                         [nameExpr]( ast::ptr<ast::Decl> decl ) { return decl->name == nameExpr->name; } );
    1498                 unsigned position = it - base->members.begin();
    1499                 addCandidate( ast::ConstantExpr::from_int( enumPosExpr->location, position ), tenv );
    15001473        }
    15011474
  • src/ResolvExpr/Resolver.cc

    rf988834 re8b3717  
    420420                const ast::ConstructorInit * previsit( const ast::ConstructorInit * );
    421421
    422                 const ast::EnumPosExpr *         previsit( const ast::EnumPosExpr * );
    423 
    424422                void resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd);
    425423
     
    12411239        }
    12421240
    1243         const ast::EnumPosExpr * Resolver::previsit( const ast::EnumPosExpr * enumPos ) {
    1244                 visitor->maybe_accept( enumPos, &ast::EnumPosExpr::expr );
    1245                 return enumPos;
    1246         }
    1247 
    12481241        // suppress error on autogen functions and mark invalid autogen as deleted.
    12491242        bool Resolver::on_error(ast::ptr<ast::Decl> & decl) {
  • src/Validate/Autogen.cpp

    rf988834 re8b3717  
    186186                // could possibly use a new linkage type. For now we just make the
    187187                // basic ones intrinsic to code-gen them as C assignments.
    188                 // const auto & real_type = decl->base;
    189                 // const auto & basic = real_type.as<ast::BasicType>();
    190 
    191                 // if(!real_type || (basic && basic->isInteger())) proto_linkage = ast::Linkage::Intrinsic;
    192 
    193                 // Turns other enumeration type into Intrinstic as well to temporarily fix the recursive
    194                 // construction bug
    195                 proto_linkage = ast::Linkage::Intrinsic;
     188                const auto & real_type = decl->base;
     189                const auto & basic = real_type.as<ast::BasicType>();
     190                if(!real_type || (basic && basic->isInteger())) proto_linkage = ast::Linkage::Intrinsic;
    196191        }
    197192
     
    749744                        }
    750745                );
    751                 // auto fname = ast::getFunctionName( callExpr );
    752                 // if (fname == "posE" ) {
    753                 //      std::cerr << "Found posE autogen" << std::endl;
    754                 // }
    755746                functionDecl->stmts = new ast::CompoundStmt( location,
    756747                        { new ast::ExprStmt( location, callExpr ) }
     
    803794}
    804795
    805 struct PseudoFuncGenerateRoutine final :
    806                 public ast::WithDeclsToAdd<>,
    807                 public ast::WithShortCircuiting {
    808         void previsit( const ast::EnumDecl * enumDecl );
    809 };
    810 
    811 void PseudoFuncGenerateRoutine::previsit( const ast::EnumDecl * enumDecl ) {
    812         const CodeLocation& location = enumDecl->location;
    813         if ( enumDecl->members.size() == 0 || !enumDecl->base || enumDecl->name == "" ) return;
    814 
    815         std::vector<ast::ptr<ast::Init>> inits;
    816         std::vector<ast::ptr<ast::Init>> labels;
    817         for ( const ast::Decl * mem: enumDecl->members ) {
    818                 auto memAsObjectDecl = dynamic_cast< const ast::ObjectDecl * >( mem );
    819                 inits.emplace_back( memAsObjectDecl->init );
    820                 labels.emplace_back( new ast::SingleInit(
    821                         location, ast::ConstantExpr::from_string(location, mem->name) ) );
    822         }
    823         auto init = new ast::ListInit( location, std::move( inits ) );
    824         auto label_strings = new ast::ListInit( location, std::move(labels) );
    825         auto values = new ast::ObjectDecl(
    826                 location,
    827                 "__enum_values_"+enumDecl->name,
    828                 new ast::ArrayType(
    829                         // new ast::PointerType( new ast::BasicType{ ast::BasicType::Char} ),
    830                         enumDecl->base,
    831                         ast::ConstantExpr::from_int( location, enumDecl->members.size() ),
    832                         ast::LengthFlag::FixedLen, ast::DimensionFlag::DynamicDim
    833                 )
    834                 ,init
    835                 ,
    836                 ast::Storage::Static,
    837                 ast::Linkage::AutoGen
    838         );
    839         auto label_arr = new ast::ObjectDecl(
    840                 location,
    841                 "__enum_labels_"+enumDecl->name,
    842                 new ast::ArrayType(
    843                         new ast::PointerType( new ast::BasicType{ ast::BasicType::Char} ),
    844                         ast::ConstantExpr::from_int( location, enumDecl->members.size() ),
    845                         ast::LengthFlag::FixedLen, ast::DimensionFlag::DynamicDim
    846                 ),
    847                 label_strings,
    848                 ast::Storage::Static,
    849                 ast::Linkage::AutoGen
    850         );
    851 
    852         declsToAddAfter.push_back( values );
    853         declsToAddAfter.push_back( label_arr );
    854 }
    855 
    856796} // namespace
    857797
    858798void autogenerateRoutines( ast::TranslationUnit & translationUnit ) {
    859799        ast::Pass<AutogenerateRoutines>::run( translationUnit );
    860         // ast::Pass<PseudoFuncGenerateRoutine>::run( translationUnit );
    861800}
    862801
  • src/Validate/module.mk

    rf988834 re8b3717  
    5252        Validate/ReturnCheck.hpp \
    5353        Validate/VerifyCtorDtorAssign.cpp \
    54         Validate/VerifyCtorDtorAssign.hpp \
    55         Validate/ReplacePseudoFunc.cpp \
    56         Validate/ReplacePseudoFunc.hpp
     54        Validate/VerifyCtorDtorAssign.hpp
    5755
    5856SRCDEMANGLE += $(SRC_VALIDATE)
  • src/main.cc

    rf988834 re8b3717  
    8282#include "Validate/ReturnCheck.hpp"         // for checkReturnStatements
    8383#include "Validate/VerifyCtorDtorAssign.hpp" // for verifyCtorDtorAssign
    84 #include "Validate/ReplacePseudoFunc.hpp"
    8584#include "Virtual/ExpandCasts.h"            // for expandCasts
    8685#include "Virtual/VirtualDtor.hpp"          // for implementVirtDtors
     
    288287                        assertf( extras, "cannot open extras.cf\n" );
    289288                        parse( extras, ast::Linkage::BuiltinC );
     289
    290290                        if ( ! libcfap ) {
    291291                                // read the prelude in, if not generating the cfa library
     
    322322                PASS( "Forall Pointer Decay", Validate::decayForallPointers, transUnit );
    323323                PASS( "Fix Qualified Types", Validate::fixQualifiedTypes, transUnit );
    324 
    325324                PASS( "Eliminate Typedef", Validate::eliminateTypedef, transUnit );
    326325                PASS( "Hoist Struct", Validate::hoistStruct, transUnit );
     
    382381                PASS( "Resolve", ResolvExpr::resolve, transUnit );
    383382                DUMP( exprp, std::move( transUnit ) );
    384                 PASS( "Replace Pseudo Func", Validate::replacePseudoFunc, transUnit );
    385383
    386384                PASS( "Fix Init", InitTweak::fix, transUnit, buildingLibrary() );
Note: See TracChangeset for help on using the changeset viewer.