Changes in / [9e72bae3:a750c71b]
- Files:
-
- 12 edited
-
src/AST/Expr.cpp (modified) (1 diff)
-
src/AST/Expr.hpp (modified) (2 diffs)
-
src/AST/Fwd.hpp (modified) (1 diff)
-
src/AST/Pass.hpp (modified) (1 diff)
-
src/AST/Pass.impl.hpp (modified) (2 diffs)
-
src/AST/Print.cpp (modified) (1 diff)
-
src/AST/Visitor.hpp (modified) (1 diff)
-
src/Common/CodeLocationTools.cpp (modified) (1 diff)
-
src/Parser/parser.yy (modified) (1 diff)
-
src/ResolvExpr/CandidateFinder.cpp (modified) (6 diffs)
-
tests/array-collections/boxed.bookend.cfa (modified) (2 diffs)
-
tests/malloc.cfa (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Expr.cpp
r9e72bae3 ra750c71b 283 283 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), type( t ) {} 284 284 285 // --- CountExpr 286 287 CountExpr::CountExpr( const CodeLocation & loc, const Expr * e ) 288 : Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), expr(e), type( nullptr ) {} 289 290 CountExpr::CountExpr( const CodeLocation & loc, const Type * t ) 291 : Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), expr(nullptr), type( t ) {} 292 285 293 // --- AlignofExpr 286 294 287 295 AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * t ) 288 296 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), type( t ) {} 289 290 // --- CountofExpr291 292 CountofExpr::CountofExpr( const CodeLocation & loc, const Type * t )293 : Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), type( t ) {}294 297 295 298 // --- OffsetofExpr -
src/AST/Expr.hpp
r9e72bae3 ra750c71b 490 490 }; 491 491 492 class CountExpr final : public Expr { 493 public: 494 ptr<Expr> expr; 495 ptr<Type> type; 496 497 CountExpr( const CodeLocation & loc, const Expr * t ); 498 CountExpr( const CodeLocation & loc, const Type * t ); 499 500 const Expr * accept( Visitor & v )const override { return v.visit( this ); } 501 private: 502 CountExpr * clone() const override { return new CountExpr( *this ); } 503 MUTATE_FRIEND 504 }; 505 492 506 /// alignof expression, e.g. `alignof(int)`, `alignof 3+4` 493 507 class AlignofExpr final : public Expr { … … 500 514 private: 501 515 AlignofExpr * clone() const override { return new AlignofExpr{ *this }; } 502 MUTATE_FRIEND503 };504 505 /// countof expression, e.g. `countof(AnEnum)`, `countof pred(Head)`506 class CountofExpr final : public Expr {507 public:508 ptr<Type> type;509 510 CountofExpr( const CodeLocation & loc, const Type * t );511 512 const Expr * accept( Visitor & v ) const override { return v.visit( this ); }513 private:514 CountofExpr * clone() const override { return new CountofExpr( *this ); }515 516 MUTATE_FRIEND 516 517 }; -
src/AST/Fwd.hpp
r9e72bae3 ra750c71b 86 86 class ConstantExpr; 87 87 class SizeofExpr; 88 class CountExpr; 88 89 class AlignofExpr; 89 class CountofExpr;90 90 class UntypedOffsetofExpr; 91 91 class OffsetofExpr; -
src/AST/Pass.hpp
r9e72bae3 ra750c71b 173 173 const ast::Expr * visit( const ast::ConstantExpr * ) override final; 174 174 const ast::Expr * visit( const ast::SizeofExpr * ) override final; 175 const ast::Expr * visit( const ast::CountExpr * ) override final; 175 176 const ast::Expr * visit( const ast::AlignofExpr * ) override final; 176 const ast::Expr * visit( const ast::CountofExpr * ) override final;177 177 const ast::Expr * visit( const ast::UntypedOffsetofExpr * ) override final; 178 178 const ast::Expr * visit( const ast::OffsetofExpr * ) override final; -
src/AST/Pass.impl.hpp
r9e72bae3 ra750c71b 1350 1350 1351 1351 //-------------------------------------------------------------------------- 1352 // CountExpr 1353 template< typename core_t > 1354 const ast::Expr * ast::Pass< core_t >::visit( const ast::CountExpr * node ) { 1355 VISIT_START( node ); 1356 if ( __visit_children() ) { 1357 { 1358 guard_symtab guard { *this }; 1359 maybe_accept( node, &CountExpr::result ); 1360 } 1361 if ( node->type ) { 1362 maybe_accept( node, &CountExpr::type ); 1363 } else { 1364 maybe_accept( node, &CountExpr::expr ); 1365 } 1366 } 1367 VISIT_END( Expr, node ); 1368 } 1369 1370 //-------------------------------------------------------------------------- 1352 1371 // AlignofExpr 1353 1372 template< typename core_t > … … 1361 1380 } 1362 1381 maybe_accept( node, &AlignofExpr::type ); 1363 }1364 1365 VISIT_END( Expr, node );1366 }1367 1368 //--------------------------------------------------------------------------1369 // CountofExpr1370 template< typename core_t >1371 const ast::Expr * ast::Pass< core_t >::visit( const ast::CountofExpr * node ) {1372 VISIT_START( node );1373 1374 if ( __visit_children() ) {1375 {1376 guard_symtab guard { *this };1377 maybe_accept( node, &CountofExpr::result );1378 }1379 maybe_accept( node, &CountofExpr::type );1380 1382 } 1381 1383 -
src/AST/Print.cpp
r9e72bae3 ra750c71b 1207 1207 } 1208 1208 1209 virtual const ast::Expr * visit( const ast::Count ofExpr * node ) override final {1209 virtual const ast::Expr * visit( const ast::CountExpr * node ) override final { 1210 1210 os << "Count Expression on: "; 1211 1211 ++indent; 1212 safe_print( node->type ); 1212 if ( node->type ) node->type->accept( *this ); 1213 else safe_print( node->expr ); 1213 1214 --indent; 1214 1215 postprint( node ); -
src/AST/Visitor.hpp
r9e72bae3 ra750c71b 76 76 virtual const ast::Expr * visit( const ast::ConstantExpr * ) = 0; 77 77 virtual const ast::Expr * visit( const ast::SizeofExpr * ) = 0; 78 virtual const ast::Expr * visit( const ast::CountExpr * ) = 0; 78 79 virtual const ast::Expr * visit( const ast::AlignofExpr * ) = 0; 79 virtual const ast::Expr * visit( const ast::CountofExpr * ) = 0;80 80 virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * ) = 0; 81 81 virtual const ast::Expr * visit( const ast::OffsetofExpr * ) = 0; -
src/Common/CodeLocationTools.cpp
r9e72bae3 ra750c71b 154 154 macro(ConstantExpr, Expr) \ 155 155 macro(SizeofExpr, Expr) \ 156 macro(CountExpr, Expr ) \ 156 157 macro(AlignofExpr, Expr) \ 157 macro(CountofExpr, Expr ) \158 158 macro(UntypedOffsetofExpr, Expr) \ 159 159 macro(OffsetofExpr, Expr) \ -
src/Parser/parser.yy
r9e72bae3 ra750c71b 946 946 } 947 947 | COUNTOF unary_expression 948 { $$ = new ExpressionNode( new ast::Count ofExpr( yylloc, new ast::TypeofType( maybeMoveBuild( $2 )) ) ); }948 { $$ = new ExpressionNode( new ast::CountExpr( yylloc, maybeMoveBuild( $2 ) ) ); } 949 949 | COUNTOF '(' type_no_function ')' 950 { $$ = new ExpressionNode( new ast::Count ofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }950 { $$ = new ExpressionNode( new ast::CountExpr( yylloc, maybeMoveBuildType( $3 ) ) ); } 951 951 ; 952 952 -
src/ResolvExpr/CandidateFinder.cpp
r9e72bae3 ra750c71b 672 672 void postvisit( const ast::SizeofExpr * sizeofExpr ); 673 673 void postvisit( const ast::AlignofExpr * alignofExpr ); 674 void postvisit( const ast::CountofExpr * countExpr );675 674 void postvisit( const ast::AddressExpr * addressExpr ); 676 675 void postvisit( const ast::LabelAddressExpr * labelExpr ); … … 698 697 void postvisit( const ast::UntypedInitExpr * initExpr ); 699 698 void postvisit( const ast::QualifiedNameExpr * qualifiedExpr ); 699 void postvisit( const ast::CountExpr * countExpr ); 700 700 701 701 void postvisit( const ast::InitExpr * ) { … … 941 941 } 942 942 } 943 943 944 944 945 /// Adds aggregate member interpretations … … 1268 1269 ? conversionCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env ) 1269 1270 : castCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env ); 1270 1271 1271 1272 // Redefine enum cast 1272 1273 auto argAsEnum = fromType.as<ast::EnumInstType>(); … … 1492 1493 } 1493 1494 1494 void Finder::postvisit( const ast::CountofExpr * countExpr ) { 1495 if ( auto enumInst = countExpr->type.as<ast::EnumInstType>() ) { 1496 addCandidate( ast::ConstantExpr::from_ulong( countExpr->location, enumInst->base->members.size()), tenv ); 1497 return; 1498 } 1499 auto untypedFirst = ast::UntypedExpr::createCall( countExpr->location, "lowerBound", {} ); 1500 auto castFirst = new ast::CastExpr( countExpr->location, untypedFirst , countExpr->type ); 1501 const ast::UntypedExpr * untyped = ast::UntypedExpr::createCall( 1502 countExpr->location, "Countof", { castFirst } 1495 void Finder::postvisit( const ast::CountExpr * countExpr ) { 1496 const ast::UntypedExpr * untyped = nullptr; 1497 if ( countExpr->type ) { 1498 auto enumInst = countExpr->type.as<ast::EnumInstType>(); 1499 if ( enumInst ) { 1500 addCandidate( ast::ConstantExpr::from_ulong(countExpr->location, enumInst->base->members.size()), tenv ); 1501 return; 1502 } 1503 auto untypedFirst = ast::UntypedExpr::createCall( countExpr->location, "lowerBound", {} ); 1504 auto castFirst = new ast::CastExpr( countExpr->location, untypedFirst , countExpr->type ); 1505 untyped = ast::UntypedExpr::createCall( 1506 countExpr->location, "Countof", { castFirst } 1507 ); 1508 } 1509 if (!untyped) untyped = ast::UntypedExpr::createCall( 1510 countExpr->location, "Countof", { countExpr->expr } 1503 1511 ); 1504 1512 CandidateFinder finder( context, tenv ); … … 1506 1514 CandidateList winners = findMinCost( finder.candidates ); 1507 1515 if ( winners.size() == 0 ) { 1508 SemanticError( countExpr , "Countof is not implemented: " );1509 } 1510 if ( winners.size() != 1 ) {1511 SemanticError( countExpr , "Ambiguous expression in countof: " );1516 SemanticError( countExpr->expr, "Countof is not implemented for operand: " ); 1517 } 1518 if ( winners.size() != 1 ) { 1519 SemanticError( countExpr->expr, "Ambiguous expression in countof operand: " ); 1512 1520 } 1513 1521 CandidateRef & choice = winners.front(); -
tests/array-collections/boxed.bookend.cfa
r9e72bae3 ra750c71b 27 27 static char * bookend_hi = 0p; 28 28 29 // bookend pointers are set to stack addresses and compared (but not dereferenced)30 // after their functions exit; they are "dangling"31 #pragma GCC diagnostic push32 #pragma GCC diagnostic ignored "-Wpragmas" // -Wdangling-pointer unrecognized until GCC 1233 #pragma GCC diagnostic ignored "-Wdangling-pointer"34 35 29 void bookendInner( void ) { 36 30 char var = 'x'; … … 41 35 #define TC(...) 42 36 #define TR( TRID, SZS, SZV, ETG, ACCS, SPS, OVLD ) \ 43 F_SIG( bookendOuter, TRID, SZS, SZV, ACCS, SPS, OVLD ) { \37 F_SIG( bookendOuter, TRID, SZS, SZV, ACCS, SPS, OVLD ) { \ 44 38 char var = 'x'; \ 45 39 (void) var; \ 46 40 bookend_hi = & var; \ 47 return CALL( allocAndAccess, TRID, SZS, n, expectedElmSz, tcid, vart ); \41 return CALL( allocAndAccess, TRID, SZS, n, expectedElmSz, tcid, vart ); \ 48 42 } 49 43 #include "boxed.cases.hfa" 50 44 #undef TC 51 45 #undef TR 52 53 #pragma GCC diagnostic pop54 46 55 47 void resetBookends( void ) { -
tests/malloc.cfa
r9e72bae3 ra750c71b 64 64 free( ip ); 65 65 66 #pragma GCC diagnostic push67 #pragma GCC diagnostic ignored "-Wpragmas" // -Walloc-size unrecognized until GCC 1468 #pragma GCC diagnostic ignored "-Walloc-size"69 66 ip = (int *)malloc( 0 ); 70 #pragma GCC diagnostic pop71 67 test_base( ip, 0, libAlign ); 72 68 test_use( ip );
Note:
See TracChangeset
for help on using the changeset viewer.