Changeset 1fb0a883
- Timestamp:
- Jan 24, 2025, 3:00:27 PM (6 weeks ago)
- Branches:
- master
- Children:
- 2a5345b, 35eef3b
- Parents:
- 1cc5c6a (diff), f070ea8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Peter A. Buhr <pabuhr@…> (01/24/25 14:53:59)
- git-committer:
- Peter A. Buhr <pabuhr@…> (01/24/25 15:00:27)
- Files:
-
- 2 deleted
- 13 edited
- 10 moved
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/AST/Expr.cpp ¶
r1cc5c6a r1fb0a883 283 283 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), type( t ) {} 284 284 285 // --- CountExpr286 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 293 285 // --- AlignofExpr 294 286 295 287 AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * t ) 296 288 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), type( t ) {} 289 290 // --- CountofExpr 291 292 CountofExpr::CountofExpr( const CodeLocation & loc, const Type * t ) 293 : Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), type( t ) {} 297 294 298 295 // --- OffsetofExpr -
TabularUnified src/AST/Expr.hpp ¶
r1cc5c6a r1fb0a883 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_FRIEND504 };505 506 492 /// alignof expression, e.g. `alignof(int)`, `alignof 3+4` 507 493 class AlignofExpr final : public Expr { … … 514 500 private: 515 501 AlignofExpr * clone() const override { return new AlignofExpr{ *this }; } 502 MUTATE_FRIEND 503 }; 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 ); } 516 515 MUTATE_FRIEND 517 516 }; -
TabularUnified src/AST/Fwd.hpp ¶
r1cc5c6a r1fb0a883 86 86 class ConstantExpr; 87 87 class SizeofExpr; 88 class CountExpr;89 88 class AlignofExpr; 89 class CountofExpr; 90 90 class UntypedOffsetofExpr; 91 91 class OffsetofExpr; -
TabularUnified src/AST/Pass.hpp ¶
r1cc5c6a r1fb0a883 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;176 175 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; -
TabularUnified src/AST/Pass.impl.hpp ¶
r1cc5c6a r1fb0a883 1350 1350 1351 1351 //-------------------------------------------------------------------------- 1352 // CountExpr1353 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 //--------------------------------------------------------------------------1371 1352 // AlignofExpr 1372 1353 template< typename core_t > … … 1380 1361 } 1381 1362 maybe_accept( node, &AlignofExpr::type ); 1363 } 1364 1365 VISIT_END( Expr, node ); 1366 } 1367 1368 //-------------------------------------------------------------------------- 1369 // CountofExpr 1370 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 ); 1382 1380 } 1383 1381 -
TabularUnified src/AST/Print.cpp ¶
r1cc5c6a r1fb0a883 1207 1207 } 1208 1208 1209 virtual const ast::Expr * visit( const ast::Count Expr * node ) override final {1209 virtual const ast::Expr * visit( const ast::CountofExpr * node ) override final { 1210 1210 os << "Count Expression on: "; 1211 1211 ++indent; 1212 if ( node->type ) node->type->accept( *this ); 1213 else safe_print( node->expr ); 1212 safe_print( node->type ); 1214 1213 --indent; 1215 1214 postprint( node ); -
TabularUnified src/AST/Visitor.hpp ¶
r1cc5c6a r1fb0a883 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;79 78 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; -
TabularUnified src/CodeGen/CodeGenerator.cpp ¶
r1cc5c6a r1fb0a883 251 251 252 252 if ( decl->init ) { 253 output << " = "; 253 bool isGenericInit = options.genC || decl->init->maybeConstructed; 254 output << ( (isGenericInit) ? " = " : " @= " ); 254 255 decl->init->accept( *visitor ); 255 256 } -
TabularUnified src/Common/CodeLocationTools.cpp ¶
r1cc5c6a r1fb0a883 154 154 macro(ConstantExpr, Expr) \ 155 155 macro(SizeofExpr, Expr) \ 156 macro(CountExpr, Expr ) \157 156 macro(AlignofExpr, Expr) \ 157 macro(CountofExpr, Expr ) \ 158 158 macro(UntypedOffsetofExpr, Expr) \ 159 159 macro(OffsetofExpr, Expr) \ -
TabularUnified src/Parser/parser.yy ¶
r1cc5c6a r1fb0a883 946 946 } 947 947 | COUNTOF unary_expression 948 { $$ = new ExpressionNode( new ast::Count Expr( yylloc, maybeMoveBuild( $2) ) ); }948 { $$ = new ExpressionNode( new ast::CountofExpr( yylloc, new ast::TypeofType( maybeMoveBuild( $2 ) ) ) ); } 949 949 | COUNTOF '(' type_no_function ')' 950 { $$ = new ExpressionNode( new ast::Count Expr( yylloc, maybeMoveBuildType( $3 ) ) ); }950 { $$ = new ExpressionNode( new ast::CountofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); } 951 951 ; 952 952 -
TabularUnified src/ResolvExpr/CandidateFinder.cpp ¶
r1cc5c6a r1fb0a883 672 672 void postvisit( const ast::SizeofExpr * sizeofExpr ); 673 673 void postvisit( const ast::AlignofExpr * alignofExpr ); 674 void postvisit( const ast::CountofExpr * countExpr ); 674 675 void postvisit( const ast::AddressExpr * addressExpr ); 675 676 void postvisit( const ast::LabelAddressExpr * labelExpr ); … … 697 698 void postvisit( const ast::UntypedInitExpr * initExpr ); 698 699 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 944 943 945 944 /// Adds aggregate member interpretations … … 1269 1268 ? conversionCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env ) 1270 1269 : castCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env ); 1271 1270 1272 1271 // Redefine enum cast 1273 1272 auto argAsEnum = fromType.as<ast::EnumInstType>(); … … 1493 1492 } 1494 1493 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 } 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 } 1511 1503 ); 1512 1504 CandidateFinder finder( context, tenv ); … … 1514 1506 CandidateList winners = findMinCost( finder.candidates ); 1515 1507 if ( winners.size() == 0 ) { 1516 SemanticError( countExpr ->expr, "Countof is not implemented for operand: " );1517 } 1518 if ( winners.size() != 1519 SemanticError( countExpr ->expr, "Ambiguous expression in countof operand: " );1508 SemanticError( countExpr, "Countof is not implemented: " ); 1509 } 1510 if ( winners.size() != 1 ) { 1511 SemanticError( countExpr, "Ambiguous expression in countof: " ); 1520 1512 } 1521 1513 CandidateRef & choice = winners.front(); -
TabularUnified tests/arithmeticConversions.cfa ¶
r1cc5c6a r1fb0a883 98 98 printf( "%6s %2zd | %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd\n", 99 99 ST(f64xc), SZ(f64xc), SZ(f64xc + c), SZ(f64xc + sc), SZ(f64xc + uc), SZ(f64xc + ssi), SZ(f64xc + usi), SZ(f64xc + si), SZ(f64xc + ui), SZ(f64xc + sli), SZ(f64xc + ulli), SZ(f64xc + ulli), SZ(f64xc + ulli) ); 100 #if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) 100 101 #if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) 101 102 printf( "%6s %2zd | %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd\n", 102 103 ST(f80), SZ(f80), SZ(f80 + c), SZ(f80 + sc), SZ(f80 + uc), SZ(f80 + ssi), SZ(f80 + usi), SZ(f80 + si), SZ(f80 + ui), SZ(f80 + sli), SZ(f80 + ulli), SZ(f80 + ulli), SZ(f80 + ulli) ); 103 #endif 104 #endif 105 104 106 printf( "%6s %2zd | %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd\n", 105 107 ST(ld), SZ(ld), SZ(ld + c), SZ(ld + sc), SZ(ld + uc), SZ(ld + ssi), SZ(ld + usi), SZ(ld + si), SZ(ld + ui), SZ(ld + sli), SZ(ld + ulli), SZ(ld + ulli), SZ(ld + ulli) ); 106 108 printf( "%6s %2zd | %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd\n", 107 109 ST(ldc), SZ(ldc), SZ(ldc + c), SZ(ldc + sc), SZ(ldc + uc), SZ(ldc + ssi), SZ(ldc + usi), SZ(ldc + si), SZ(ldc + ui), SZ(ldc + sli), SZ(ldc + ulli), SZ(ldc + ulli), SZ(ldc + ulli) ); 108 #if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) 110 111 #if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) 109 112 printf( "%6s %2zd | %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd\n", 110 113 ST(uuf128), SZ(uuf128), SZ(uuf128 + c), SZ(uuf128 + sc), SZ(uuf128 + uc), SZ(uuf128 + ssi), SZ(uuf128 + usi), SZ(uuf128 + si), SZ(uuf128 + ui), SZ(uuf128 + sli), SZ(uuf128 + ulli), SZ(uuf128 + ulli), SZ(uuf128 + ulli) ); 111 #endif 114 #endif 115 112 116 printf( "%6s %2zd | %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd %4zd\n", 113 117 ST(f128), SZ(f128), SZ(f128 + c), SZ(f128 + sc), SZ(f128 + uc), SZ(f128 + ssi), SZ(f128 + usi), SZ(f128 + si), SZ(f128 + ui), SZ(f128 + sli), SZ(f128 + ulli), SZ(f128 + ulli), SZ(f128 + ulli) ); … … 146 150 printf( "%6s %2zd | %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd" OPT1(" %5zd") " %5zd %5zd" OPT1(" %6zd") " %5zd %5zd\n", 147 151 ST(f64xc), SZ(f64xc), SZ(f64xc + f32), SZ(f64xc + f32c), SZ(f64xc + f), SZ(f64xc + fc), SZ(f64xc + f32x), SZ(f64xc + f32xc), SZ(f64xc + f64), SZ(f64xc + f64c), SZ(f64xc + d), SZ(f64xc + dc), SZ(f64xc + f64x), SZ(f64xc + f64xc) OPT2(, SZ(f64xc + f80)), SZ(f64xc + ld), SZ(f64xc + ldc) OPT2(, SZ(f64xc + uuf128)), SZ(f64xc + f128), SZ(f64xc + f128c) ); 148 #if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) 152 153 #if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) 149 154 printf( "%6s %2zd | %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %6zd %5zd %5zd\n", 150 155 ST(f80), SZ(f80), SZ(f80 + f32), SZ(f80 + f32c), SZ(f80 + f), SZ(f80 + fc), SZ(f80 + f32x), SZ(f80 + f32xc), SZ(f80 + f64), SZ(f80 + f64c), SZ(f80 + d), SZ(f80 + dc), SZ(f80 + f64x), SZ(f80 + f64xc), SZ(f80 + f80), SZ(f80 + ld), SZ(f80 + ldc), SZ(f80 + uuf128), SZ(f80 + f128), SZ(f80 + f128c) ); 151 #endif 156 #endif 157 152 158 printf( "%6s %2zd | %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd" OPT1(" %5zd") " %5zd %5zd" OPT1(" %6zd") " %5zd %5zd\n", 153 159 ST(ld), SZ(ld), SZ(ld + f32), SZ(ld + f32c), SZ(ld + f), SZ(ld + fc), SZ(ld + f32x), SZ(ld + f32xc), SZ(ld + f64), SZ(ld + f64c), SZ(ld + d), SZ(ld + dc), SZ(ld + f64x), SZ(ld + f64xc) OPT2(, SZ(ld + f80)), SZ(ld + ld), SZ(ld + ldc) OPT2(, SZ(ld + uuf128)), SZ(ld + f128), SZ(ld + f128c) ); 154 160 printf( "%6s %2zd | %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd" OPT1(" %5zd") " %5zd %5zd" OPT1(" %6zd") " %5zd %5zd\n", 155 161 ST(ldc), SZ(ldc), SZ(ldc + f32), SZ(ldc + f32c), SZ(ldc + f), SZ(ldc + fc), SZ(ldc + f32x), SZ(ldc + f32xc), SZ(ldc + f64), SZ(ldc + f64c), SZ(ldc + d), SZ(ldc + dc), SZ(ldc + f64x), SZ(ldc + f64xc) OPT2(, SZ(ldc + f80)), SZ(ldc + ld), SZ(ldc + ldc) OPT2(, SZ(ldc + uuf128)), SZ(ldc + f128), SZ(ldc + f128c) ); 156 #if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) 162 163 #if defined(__i386__) || defined(__ia64__) || defined(__x86_64__) 157 164 printf( "%6s %2zd | %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %6zd %5zd %5zd\n", 158 165 ST(uuf128), SZ(uuf128), SZ(uuf128 + f32), SZ(uuf128 + f32c), SZ(uuf128 + f), SZ(uuf128 + fc), SZ(uuf128 + f32x), SZ(uuf128 + f32xc), SZ(uuf128 + f64), SZ(uuf128 + f64c), SZ(uuf128 + d), SZ(uuf128 + dc), SZ(uuf128 + f64x), SZ(uuf128 + f64xc), SZ(uuf128 + f80), SZ(uuf128 + ld), SZ(uuf128 + ldc), SZ(uuf128 + uuf128), SZ(uuf128 + f128), SZ(uuf128 + f128c) ); 159 #endif 166 #endif 167 160 168 printf( "%6s %2zd | %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd %5zd" OPT1(" %5zd") " %5zd %5zd" OPT1(" %6zd") " %5zd %5zd\n", 161 169 ST(f128), SZ(f128), SZ(f128 + f32), SZ(f128 + f32c), SZ(f128 + f), SZ(f128 + fc), SZ(f128 + f32x), SZ(f128 + f32xc), SZ(f128 + f64), SZ(f128 + f64c), SZ(f128 + d), SZ(f128 + dc), SZ(f128 + f64x), SZ(f128 + f64xc) OPT2(, SZ(f128 + f80)), SZ(f128 + ld), SZ(f128 + ldc) OPT2(, SZ(f128 + uuf128)), SZ(f128 + f128), SZ(f128 + f128c) ); -
TabularUnified tests/io/eofType.cfa ¶
r1cc5c6a r1fb0a883 10 10 // Created On : Wed Jan 22 07:41:41 2025 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 22 08:45:51202513 // Update Count : 812 // Last Modified On : Thu Jan 23 14:33:08 2025 13 // Update Count : 9 14 14 // 15 15 … … 33 33 ifstream testfile; 34 34 { 35 char * filenames[] = { INDIR "eof Bool.1.txt", INDIR "eofBool.2.txt" };35 char * filenames[] = { INDIR "eofType.bool.1.txt", INDIR "eofType.bool.2.txt" }; 36 36 bool value; 37 37 … … 50 50 } 51 51 { 52 char * filenames[] = { INDIR "eof Char.1.txt", INDIR "eofChar.2.txt" };52 char * filenames[] = { INDIR "eofType.char.1.txt", INDIR "eofType.char.2.txt" }; 53 53 char value; 54 54 … … 67 67 } 68 68 { 69 char * filenames[] = { INDIR "eof Int.1.txt", INDIR "eofInt.2.txt" };69 char * filenames[] = { INDIR "eofType.int.1.txt", INDIR "eofType.int.2.txt" }; 70 70 int value; 71 71 … … 84 84 } 85 85 { 86 char * filenames[] = { INDIR "eof Double.1.txt", INDIR "eofDouble.2.txt" };86 char * filenames[] = { INDIR "eofType.double.1.txt", INDIR "eofType.double.2.txt" }; 87 87 double value; 88 88 … … 101 101 } 102 102 { 103 char * filenames[] = { INDIR "eof Complex.1.txt", INDIR "eofComplex.2.txt" };103 char * filenames[] = { INDIR "eofType.complex.1.txt", INDIR "eofType.complex.2.txt" }; 104 104 _Complex value; 105 105
Note: See TracChangeset
for help on using the changeset viewer.