Changes in / [f988834:e8b3717]
- Location:
- src
- Files:
-
- 20 edited
-
AST/Expr.cpp (modified) (1 diff)
-
AST/Expr.hpp (modified) (1 diff)
-
AST/Fwd.hpp (modified) (1 diff)
-
AST/Node.cpp (modified) (1 diff)
-
AST/Pass.hpp (modified) (1 diff)
-
AST/Pass.impl.hpp (modified) (1 diff)
-
AST/Print.cpp (modified) (1 diff)
-
AST/Visitor.hpp (modified) (1 diff)
-
CodeGen/CodeGenerator.cpp (modified) (1 diff)
-
CodeGen/CodeGenerator.hpp (modified) (1 diff)
-
Common/CodeLocationTools.cpp (modified) (1 diff)
-
GenPoly/Box.cpp (modified) (2 diffs)
-
InitTweak/InitTweak.cc (modified) (1 diff)
-
Parser/ExpressionNode.cc (modified) (1 diff)
-
Parser/ExpressionNode.h (modified) (1 diff)
-
ResolvExpr/CandidateFinder.cpp (modified) (3 diffs)
-
ResolvExpr/Resolver.cc (modified) (2 diffs)
-
Validate/Autogen.cpp (modified) (3 diffs)
-
Validate/module.mk (modified) (1 diff)
-
main.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Expr.cpp
rf988834 re8b3717 307 307 } 308 308 309 //310 311 // --- EnumPosExpr312 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 323 309 // --- LogicalExpr 324 310 -
src/AST/Expr.hpp
rf988834 re8b3717 548 548 }; 549 549 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_FRIEND561 };562 563 550 /// Variants of short-circuiting logical expression 564 551 enum LogicalFlag { OrExpr, AndExpr }; -
src/AST/Fwd.hpp
rf988834 re8b3717 89 89 class OffsetofExpr; 90 90 class OffsetPackExpr; 91 class EnumPosExpr;92 91 class LogicalExpr; 93 92 class ConditionalExpr; -
src/AST/Node.cpp
rf988834 re8b3717 232 232 template class ast::ptr_base< ast::OffsetPackExpr, ast::Node::ref_type::weak >; 233 233 template 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 >;236 234 template class ast::ptr_base< ast::LogicalExpr, ast::Node::ref_type::weak >; 237 235 template class ast::ptr_base< ast::LogicalExpr, ast::Node::ref_type::strong >; -
src/AST/Pass.hpp
rf988834 re8b3717 191 191 const ast::Expr * visit( const ast::OffsetofExpr * ) override final; 192 192 const ast::Expr * visit( const ast::OffsetPackExpr * ) override final; 193 const ast::Expr * visit( const ast::EnumPosExpr * ) override final;194 193 const ast::Expr * visit( const ast::LogicalExpr * ) override final; 195 194 const ast::Expr * visit( const ast::ConditionalExpr * ) override final; -
src/AST/Pass.impl.hpp
rf988834 re8b3717 1452 1452 1453 1453 //-------------------------------------------------------------------------- 1454 // EnumPosExpr1455 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 //--------------------------------------------------------------------------1469 1454 // LogicalExpr 1470 1455 template< typename core_t > -
src/AST/Print.cpp
rf988834 re8b3717 1183 1183 } 1184 1184 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 1194 1185 virtual const ast::Expr * visit( const ast::LogicalExpr * node ) override final { 1195 1186 os << "Short-circuited operation (" << (node->isAnd ? "and" : "or") << ") on: "; -
src/AST/Visitor.hpp
rf988834 re8b3717 79 79 virtual const ast::Expr * visit( const ast::OffsetofExpr * ) = 0; 80 80 virtual const ast::Expr * visit( const ast::OffsetPackExpr * ) = 0; 81 virtual const ast::Expr * visit( const ast::EnumPosExpr * ) = 0;82 81 virtual const ast::Expr * visit( const ast::LogicalExpr * ) = 0; 83 82 virtual const ast::Expr * visit( const ast::ConditionalExpr * ) = 0; -
src/CodeGen/CodeGenerator.cpp
rf988834 re8b3717 778 778 } 779 779 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 785 780 void CodeGenerator::postvisit( ast::LogicalExpr const * expr ) { 786 781 extension( expr ); -
src/CodeGen/CodeGenerator.hpp
rf988834 re8b3717 77 77 void postvisit( ast::OffsetPackExpr const * ); 78 78 void postvisit( ast::LogicalExpr const * ); 79 void postvisit( ast::EnumPosExpr const * );80 79 void postvisit( ast::ConditionalExpr const * ); 81 80 void postvisit( ast::CommaExpr const * ); -
src/Common/CodeLocationTools.cpp
rf988834 re8b3717 158 158 macro(OffsetPackExpr, Expr) \ 159 159 macro(LogicalExpr, Expr) \ 160 macro(EnumPosExpr, Expr) \161 160 macro(ConditionalExpr, Expr) \ 162 161 macro(CommaExpr, Expr) \ -
src/GenPoly/Box.cpp
rf988834 re8b3717 1580 1580 ast::Expr const * postvisit( ast::OffsetPackExpr const * expr ); 1581 1581 1582 ast::Expr const * postvisit( ast::EnumPosExpr const * expr );1583 1584 1582 void beginScope(); 1585 1583 void endScope(); … … 1952 1950 1953 1951 return new ast::VariableExpr( expr->location, offsetArray ); 1954 }1955 1956 // TODO1957 ast::Expr const * PolyGenericCalculator::postvisit( ast::EnumPosExpr const * expr ) {1958 return expr;1959 1952 } 1960 1953 -
src/InitTweak/InitTweak.cc
rf988834 re8b3717 271 271 void previsit( const ast::OffsetofExpr * ) {} 272 272 void previsit( const ast::OffsetPackExpr * ) {} 273 void previsit( const ast::EnumPosExpr * ) {}274 273 void previsit( const ast::CommaExpr * ) {} 275 274 void previsit( const ast::LogicalExpr * ) {} -
src/Parser/ExpressionNode.cc
rf988834 re8b3717 690 690 } // build_unary_val 691 691 692 ast::Expr * build_enum_pos_expr( const CodeLocation & location, ast::Expr * expr_node ) {693 // return nullptr694 return new ast::EnumPosExpr( location, std::move( expr_node ) );695 }696 697 692 ast::Expr * build_binary_val( const CodeLocation & location, 698 693 OperKinds op, -
src/Parser/ExpressionNode.h
rf988834 re8b3717 83 83 ast::Expr * build_func( const CodeLocation &, ExpressionNode * function, ExpressionNode * expr_node ); 84 84 ast::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 52 52 #include "Common/Stats/Counter.h" 53 53 54 #include "AST/Inspect.hpp" // for getFunctionName55 56 54 #define PRINT( text ) if ( resolvep ) { text } 57 55 … … 658 656 void postvisit( const ast::OffsetofExpr * offsetofExpr ); 659 657 void postvisit( const ast::OffsetPackExpr * offsetPackExpr ); 660 void postvisit( const ast::EnumPosExpr * enumPosExpr );661 658 void postvisit( const ast::LogicalExpr * logicalExpr ); 662 659 void postvisit( const ast::ConditionalExpr * conditionalExpr ); … … 1474 1471 void Finder::postvisit( const ast::OffsetPackExpr * offsetPackExpr ) { 1475 1472 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 );1500 1473 } 1501 1474 -
src/ResolvExpr/Resolver.cc
rf988834 re8b3717 420 420 const ast::ConstructorInit * previsit( const ast::ConstructorInit * ); 421 421 422 const ast::EnumPosExpr * previsit( const ast::EnumPosExpr * );423 424 422 void resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd); 425 423 … … 1241 1239 } 1242 1240 1243 const ast::EnumPosExpr * Resolver::previsit( const ast::EnumPosExpr * enumPos ) {1244 visitor->maybe_accept( enumPos, &ast::EnumPosExpr::expr );1245 return enumPos;1246 }1247 1248 1241 // suppress error on autogen functions and mark invalid autogen as deleted. 1249 1242 bool Resolver::on_error(ast::ptr<ast::Decl> & decl) { -
src/Validate/Autogen.cpp
rf988834 re8b3717 186 186 // could possibly use a new linkage type. For now we just make the 187 187 // 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; 196 191 } 197 192 … … 749 744 } 750 745 ); 751 // auto fname = ast::getFunctionName( callExpr );752 // if (fname == "posE" ) {753 // std::cerr << "Found posE autogen" << std::endl;754 // }755 746 functionDecl->stmts = new ast::CompoundStmt( location, 756 747 { new ast::ExprStmt( location, callExpr ) } … … 803 794 } 804 795 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::DynamicDim833 )834 ,init835 ,836 ast::Storage::Static,837 ast::Linkage::AutoGen838 );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::DynamicDim846 ),847 label_strings,848 ast::Storage::Static,849 ast::Linkage::AutoGen850 );851 852 declsToAddAfter.push_back( values );853 declsToAddAfter.push_back( label_arr );854 }855 856 796 } // namespace 857 797 858 798 void autogenerateRoutines( ast::TranslationUnit & translationUnit ) { 859 799 ast::Pass<AutogenerateRoutines>::run( translationUnit ); 860 // ast::Pass<PseudoFuncGenerateRoutine>::run( translationUnit );861 800 } 862 801 -
src/Validate/module.mk
rf988834 re8b3717 52 52 Validate/ReturnCheck.hpp \ 53 53 Validate/VerifyCtorDtorAssign.cpp \ 54 Validate/VerifyCtorDtorAssign.hpp \ 55 Validate/ReplacePseudoFunc.cpp \ 56 Validate/ReplacePseudoFunc.hpp 54 Validate/VerifyCtorDtorAssign.hpp 57 55 58 56 SRCDEMANGLE += $(SRC_VALIDATE) -
src/main.cc
rf988834 re8b3717 82 82 #include "Validate/ReturnCheck.hpp" // for checkReturnStatements 83 83 #include "Validate/VerifyCtorDtorAssign.hpp" // for verifyCtorDtorAssign 84 #include "Validate/ReplacePseudoFunc.hpp"85 84 #include "Virtual/ExpandCasts.h" // for expandCasts 86 85 #include "Virtual/VirtualDtor.hpp" // for implementVirtDtors … … 288 287 assertf( extras, "cannot open extras.cf\n" ); 289 288 parse( extras, ast::Linkage::BuiltinC ); 289 290 290 if ( ! libcfap ) { 291 291 // read the prelude in, if not generating the cfa library … … 322 322 PASS( "Forall Pointer Decay", Validate::decayForallPointers, transUnit ); 323 323 PASS( "Fix Qualified Types", Validate::fixQualifiedTypes, transUnit ); 324 325 324 PASS( "Eliminate Typedef", Validate::eliminateTypedef, transUnit ); 326 325 PASS( "Hoist Struct", Validate::hoistStruct, transUnit ); … … 382 381 PASS( "Resolve", ResolvExpr::resolve, transUnit ); 383 382 DUMP( exprp, std::move( transUnit ) ); 384 PASS( "Replace Pseudo Func", Validate::replacePseudoFunc, transUnit );385 383 386 384 PASS( "Fix Init", InitTweak::fix, transUnit, buildingLibrary() );
Note:
See TracChangeset
for help on using the changeset viewer.