Changeset 525f7ad
- Timestamp:
- Jun 19, 2024, 3:20:39 PM (5 months ago)
- Branches:
- master
- Children:
- 57e43cd
- Parents:
- 1725989
- Files:
-
- 1 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/enum.cfa
r1725989 r525f7ad 13 13 return os | type_name(e) | "." | labelE(e); 14 14 } 15 16 forall(ostype & | basic_ostream(ostype), E, V| CfaEnum(E, V)) { 17 int ?==?(E l, E r) { return posE(l) == posE(r); } 18 int ?<=?(E l, E r) { return posE(l) <= posE(r); } 19 int ?>=?(E l, E r) { return posE(l) >= posE(r); } 20 int ?<?(E l, E r) { return posE(l) < posE(r); } 21 int ?>?(E l, E r) { return posE(l) > posE(r); } 22 } -
libcfa/src/enum.hfa
r1725989 r525f7ad 38 38 // V valueE(E e); 39 39 // }; 40 41 forall(ostype & | basic_ostream(ostype), E, V| CfaEnum(E, V)) { 42 int ?==?(E, E); 43 int ?<=?(E, E); 44 int ?>=?(E, E); 45 int ?<?(E, E); 46 int ?>?(E, E); 47 48 // E ++?( E & lhs ); 49 // E ?++( E & lhs ); 50 } -
src/AST/Expr.cpp
r1725989 r525f7ad 282 282 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( nullptr ), type( t ) {} 283 283 284 // --- CountExpr 285 286 CountExpr::CountExpr( const CodeLocation & loc, const Type * t ) 287 : Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), type( t ) {} 288 284 289 // --- AlignofExpr 285 290 -
src/AST/Expr.hpp
r1725989 r525f7ad 494 494 }; 495 495 496 class CountExpr final : public Expr { 497 public: 498 ptr<Type> type; 499 500 CountExpr( const CodeLocation & loc, const Type * t ); 501 502 const Expr * accept( Visitor & v )const override { return v.visit( this ); } 503 private: 504 CountExpr * clone() const override { return new CountExpr( *this ); } 505 MUTATE_FRIEND 506 }; 507 496 508 /// alignof expression, e.g. `alignof(int)`, `alignof 3+4` 497 509 class AlignofExpr final : public Expr { -
src/AST/Fwd.hpp
r1725989 r525f7ad 85 85 class ConstantExpr; 86 86 class SizeofExpr; 87 class CountExpr; 87 88 class AlignofExpr; 88 89 class UntypedOffsetofExpr; -
src/AST/Pass.hpp
r1725989 r525f7ad 172 172 const ast::Expr * visit( const ast::ConstantExpr * ) override final; 173 173 const ast::Expr * visit( const ast::SizeofExpr * ) override final; 174 const ast::Expr * visit( const ast::CountExpr * ) override final; 174 175 const ast::Expr * visit( const ast::AlignofExpr * ) override final; 175 176 const ast::Expr * visit( const ast::UntypedOffsetofExpr * ) override final; -
src/AST/Pass.impl.hpp
r1725989 r525f7ad 802 802 maybe_accept_top( node, &ForStmt::cond ); 803 803 maybe_accept_top( node, &ForStmt::inc ); 804 maybe_accept_top( node, &ForStmt::range_over ); 804 805 maybe_accept_as_compound( node, &ForStmt::body ); 805 806 } … … 1323 1324 } 1324 1325 1326 VISIT_END( Expr, node ); 1327 } 1328 1329 //-------------------------------------------------------------------------- 1330 // CountExpr 1331 template< typename core_t > 1332 const ast::Expr * ast::Pass< core_t >::visit( const ast::CountExpr * node ) { 1333 VISIT_START( node ); 1334 if ( __visit_children() ) { 1335 { 1336 guard_symtab guard { *this }; 1337 maybe_accept( node, &CountExpr::result ); 1338 } 1339 maybe_accept( node, &CountExpr::type ); 1340 } 1325 1341 VISIT_END( Expr, node ); 1326 1342 } -
src/AST/Print.cpp
r1725989 r525f7ad 1143 1143 } 1144 1144 1145 virtual const ast::Expr * visit( const ast::CountExpr * node ) override final { 1146 os << "Count Expression on: "; 1147 ++indent; 1148 node->type->accept( *this ); 1149 --indent; 1150 postprint( node ); 1151 return node; 1152 } 1153 1145 1154 virtual const ast::Expr * visit( const ast::AlignofExpr * node ) override final { 1146 1155 os << "Alignof Expression on: "; -
src/AST/Stmt.hpp
r1725989 r525f7ad 237 237 ptr<Expr> cond; 238 238 ptr<Expr> inc; 239 ptr<Expr> range_over; 239 240 ptr<Stmt> body; 240 241 ptr<Stmt> else_; … … 242 243 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond, 243 244 const Expr * inc, const Stmt * body, const std::vector<Label> && label = {} ) 244 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(nullptr) {} 245 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), 246 range_over(nullptr), body(body), else_(nullptr) {} 245 247 246 248 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond, 247 249 const Expr * inc, const Stmt * body, const Stmt * else_, const std::vector<Label> && labels = {} ) 248 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(else_) {} 250 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), 251 range_over(nullptr), body(body), else_(else_) {} 252 253 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * range_over, 254 const Stmt * body, const Stmt * else_ ) 255 : Stmt(loc, std::move(labels)), inits(std::move(inits)), range_over(range_over), body(body), else_(else_) {} 249 256 250 257 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/Visitor.hpp
r1725989 r525f7ad 75 75 virtual const ast::Expr * visit( const ast::ConstantExpr * ) = 0; 76 76 virtual const ast::Expr * visit( const ast::SizeofExpr * ) = 0; 77 virtual const ast::Expr * visit( const ast::CountExpr * ) = 0; 77 78 virtual const ast::Expr * visit( const ast::AlignofExpr * ) = 0; 78 79 virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * ) = 0; -
src/Common/CodeLocationTools.cpp
r1725989 r525f7ad 153 153 macro(ConstantExpr, Expr) \ 154 154 macro(SizeofExpr, Expr) \ 155 macro(CountExpr, Expr ) \ 155 156 macro(AlignofExpr, Expr) \ 156 157 macro(UntypedOffsetofExpr, Expr) \ -
src/ControlStruct/module.mk
r1725989 r525f7ad 27 27 ControlStruct/LabelGenerator.hpp \ 28 28 ControlStruct/MultiLevelExit.cpp \ 29 ControlStruct/MultiLevelExit.hpp 29 ControlStruct/MultiLevelExit.hpp \ 30 ControlStruct/TranslateEnumRange.cpp \ 31 ControlStruct/TranslateEnumRange.hpp 30 32 -
src/Parser/StatementNode.cpp
r1725989 r525f7ad 211 211 buildMoveList( forctl->init, astinit ); 212 212 213 if ( forctl->range_over ) { 214 ast::Expr * range_over = maybeMoveBuild( forctl->range_over ); 215 delete forctl; 216 return new ast::ForStmt( location, 217 std::move( astinit ), 218 range_over, 219 buildMoveSingle( stmt ), 220 buildMoveOptional( else_ ) 221 ); 222 } 223 213 224 ast::Expr * astcond = nullptr; // maybe empty 214 225 astcond = maybeMoveBuild( forctl->condition ); -
src/Parser/StatementNode.hpp
r1725989 r525f7ad 63 63 struct ForCtrl { 64 64 ForCtrl( StatementNode * stmt, ExpressionNode * condition, ExpressionNode * change ) : 65 init( stmt ), condition( condition ), change( change ) {} 65 init( stmt ), condition( condition ), change( change ), range_over( nullptr ) {} 66 ForCtrl( StatementNode * decl, ExpressionNode * _range_over) : 67 init( decl ), condition( nullptr ), change( nullptr ), range_over( _range_over ) {} 66 68 67 69 StatementNode * init; 68 70 ExpressionNode * condition; 69 71 ExpressionNode * change; 72 ExpressionNode * range_over; 70 73 }; 71 74 -
src/Parser/lex.ll
r1725989 r525f7ad 321 321 __signed__ { KEYWORD_RETURN(SIGNED); } // GCC 322 322 sizeof { KEYWORD_RETURN(SIZEOF); } 323 __count_e__ { KEYWORD_RETURN(COUNT); } // GCC 323 324 static { KEYWORD_RETURN(STATIC); } 324 325 _Static_assert { KEYWORD_RETURN(STATICASSERT); } // C11 -
src/Parser/parser.yy
r1725989 r525f7ad 284 284 } // forCtrl 285 285 286 ForCtrl * enumRangeCtrl( ExpressionNode * index_expr, ExpressionNode * range_over_expr ) { 287 if ( auto identifier = dynamic_cast<ast::NameExpr *>(index_expr->expr.get()) ) { 288 DeclarationNode * indexDecl = 289 DeclarationNode::newName( new std::string(identifier->name) ); 290 assert( range_over_expr ); 291 auto node = new StatementNode( indexDecl ); // <- this cause this error 292 return new ForCtrl( node, range_over_expr ); 293 } else if (auto commaExpr = dynamic_cast<ast::CommaExpr *>( index_expr->expr.get() )) { 294 if ( auto identifier = commaExpr->arg1.as<ast::NameExpr>() ) { 295 assert( range_over_expr ); 296 DeclarationNode * indexDecl = distAttr( 297 DeclarationNode::newTypeof( range_over_expr, true ), 298 DeclarationNode::newName( new std::string( identifier->name) ) ); 299 return new ForCtrl( new StatementNode( indexDecl ), range_over_expr ); 300 } else { 301 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr; 302 } // if 303 } else { 304 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr; 305 } // if 306 } // enumRangeCtrl 307 286 308 static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) { 287 309 SemanticError( yylloc, "syntax error, adjacent identifiers \"%s\" and \"%s\" are not meaningful in an %s.\n" … … 368 390 %token DECIMAL32 DECIMAL64 DECIMAL128 // GCC 369 391 %token ZERO_T ONE_T // CFA 370 %token SIZEOF TYPEOF VA_LIST VA_ARG AUTO_TYPE 392 %token SIZEOF TYPEOF VA_LIST VA_ARG AUTO_TYPE COUNT // GCC 371 393 %token OFFSETOF BASETYPEOF TYPEID // CFA 372 394 %token ENUM STRUCT UNION … … 968 990 // $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); 969 991 } 992 | COUNT '(' type ')' 993 { 994 // SemanticError( yylloc, "Count is currently unimplemented. "); $$ = nullptr; 995 $$ = new ExpressionNode( new ast::CountExpr( yylloc, maybeMoveBuildType( $3 ) ) ); 996 } 970 997 ; 971 998 … … 1599 1626 { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; } 1600 1627 1601 | comma_expression ';' enum_key // CFA, enum type 1602 { 1603 SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr; 1604 //$$ = forCtrl( new ExpressionNode( build_varref( $3 ) ), $1, nullptr, OperKinds::Range, nullptr, nullptr ); 1605 } 1606 | comma_expression ';' downupdowneq enum_key // CFA, enum type, reverse direction 1628 | comma_expression ';' enum_type // CFA, enum type 1629 { 1630 $$ = enumRangeCtrl( $1, new ExpressionNode( new ast::TypeExpr(yylloc, $3->buildType() ) ) ); 1631 } 1632 | comma_expression ';' downupdowneq enum_type // CFA, enum type, reverse direction 1607 1633 { 1608 1634 if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { … … 1611 1637 SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr; 1612 1638 } 1613 ;1614 1615 enum_key:1616 TYPEDEFname1617 | ENUM identifier_or_type_name1618 1639 ; 1619 1640 -
src/ResolvExpr/CandidateFinder.cpp
r1725989 r525f7ad 696 696 void postvisit( const ast::UntypedInitExpr * initExpr ); 697 697 void postvisit( const ast::QualifiedNameExpr * qualifiedExpr ); 698 void postvisit( const ast::CountExpr * countExpr ); 698 699 699 700 const ast::Expr * makeEnumOffsetCast( const ast::EnumInstType * src, … … 1527 1528 addCandidate( *choice, new ast::SizeofExpr{ sizeofExpr->location, choice->expr } ); 1528 1529 } 1530 } 1531 1532 void Finder::postvisit( const ast::CountExpr * countExpr ) { 1533 assert( countExpr->type ); 1534 auto enumInst = countExpr->type.as<ast::EnumInstType>(); 1535 if ( !enumInst ) { 1536 SemanticError( countExpr, "Count Expression only supports Enum Type as operand: "); 1537 } 1538 addCandidate( ast::ConstantExpr::from_ulong(countExpr->location, enumInst->base->members.size()), tenv ); 1529 1539 } 1530 1540 -
src/main.cpp
r1725989 r525f7ad 53 53 #include "ControlStruct/FixLabels.hpp" // for fixLabels 54 54 #include "ControlStruct/HoistControlDecls.hpp" // hoistControlDecls 55 #include "ControlStruct/TrasnlateEnumRange.hpp" // translateEnumRange 55 56 #include "GenPoly/Box.hpp" // for box 56 57 #include "GenPoly/InstantiateGeneric.hpp" // for instantiateGeneric … … 323 324 PASS( "Hoist Struct", Validate::hoistStruct, transUnit ); 324 325 PASS( "Validate Generic Parameters", Validate::fillGenericParameters, transUnit ); 326 PASS( "Translate Enum Range Expression", ControlStruct::translateEnumRange, transUnit ); 325 327 PASS( "Translate Dimensions", Validate::translateDimensionParameters, transUnit ); 326 328 // Need to happen before fixing returns because implementEnumFunc has ReturnStmt
Note: See TracChangeset
for help on using the changeset viewer.