Changeset 9ddcee1
- Timestamp:
- Feb 1, 2024, 5:13:04 PM (15 months ago)
- Branches:
- master
- Children:
- 020fa10
- Parents:
- 496ffc17
- Location:
- src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/AST/Expr.cpp ¶
r496ffc17 r9ddcee1 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 -
TabularUnified src/AST/Expr.hpp ¶
r496ffc17 r9ddcee1 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 }; -
TabularUnified src/AST/Fwd.hpp ¶
r496ffc17 r9ddcee1 89 89 class OffsetofExpr; 90 90 class OffsetPackExpr; 91 class EnumPosExpr;92 91 class LogicalExpr; 93 92 class ConditionalExpr; -
TabularUnified src/AST/Node.cpp ¶
r496ffc17 r9ddcee1 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 >; -
TabularUnified src/AST/Pass.hpp ¶
r496ffc17 r9ddcee1 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; -
TabularUnified src/AST/Pass.impl.hpp ¶
r496ffc17 r9ddcee1 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 > -
TabularUnified src/AST/Print.cpp ¶
r496ffc17 r9ddcee1 1186 1186 } 1187 1187 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 1197 1188 virtual const ast::Expr * visit( const ast::LogicalExpr * node ) override final { 1198 1189 os << "Short-circuited operation (" << (node->isAnd ? "and" : "or") << ") on: "; -
TabularUnified src/AST/Visitor.hpp ¶
r496ffc17 r9ddcee1 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; -
TabularUnified src/CodeGen/CodeGenerator.cpp ¶
r496ffc17 r9ddcee1 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 ); -
TabularUnified src/CodeGen/CodeGenerator.hpp ¶
r496ffc17 r9ddcee1 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 * ); -
TabularUnified src/Common/CodeLocationTools.cpp ¶
r496ffc17 r9ddcee1 158 158 macro(OffsetPackExpr, Expr) \ 159 159 macro(LogicalExpr, Expr) \ 160 macro(EnumPosExpr, Expr) \161 160 macro(ConditionalExpr, Expr) \ 162 161 macro(CommaExpr, Expr) \ -
TabularUnified src/GenPoly/Box.cpp ¶
r496ffc17 r9ddcee1 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 -
TabularUnified src/InitTweak/InitTweak.cc ¶
r496ffc17 r9ddcee1 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 * ) {} -
TabularUnified src/Parser/ExpressionNode.cc ¶
r496ffc17 r9ddcee1 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, -
TabularUnified src/ResolvExpr/CandidateFinder.cpp ¶
r496ffc17 r9ddcee1 659 659 void postvisit( const ast::OffsetofExpr * offsetofExpr ); 660 660 void postvisit( const ast::OffsetPackExpr * offsetPackExpr ); 661 void postvisit( const ast::EnumPosExpr * enumPosExpr );662 661 void postvisit( const ast::LogicalExpr * logicalExpr ); 663 662 void postvisit( const ast::ConditionalExpr * conditionalExpr ); … … 1507 1506 void Finder::postvisit( const ast::OffsetPackExpr * offsetPackExpr ) { 1508 1507 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 );1533 1508 } 1534 1509 -
TabularUnified src/ResolvExpr/ConversionCost.cc ¶
r496ffc17 r9ddcee1 361 361 } 362 362 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 { 363 void ConversionCost::postvisit( const ast::EnumInstType * ) { 368 364 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 369 365 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); -
TabularUnified src/ResolvExpr/Resolver.cc ¶
r496ffc17 r9ddcee1 411 411 const ast::ConstructorInit * previsit( const ast::ConstructorInit * ); 412 412 413 const ast::EnumPosExpr * previsit( const ast::EnumPosExpr * );414 415 413 void resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd); 416 414 … … 1232 1230 } 1233 1231 1234 const ast::EnumPosExpr * Resolver::previsit( const ast::EnumPosExpr * enumPos ) {1235 visitor->maybe_accept( enumPos, &ast::EnumPosExpr::expr );1236 return enumPos;1237 }1238 1239 1232 // suppress error on autogen functions and mark invalid autogen as deleted. 1240 1233 bool Resolver::on_error(ast::ptr<ast::Decl> & decl) {
Note: See TracChangeset
for help on using the changeset viewer.