Changes in / [57e43cd:348f8992]
- Files:
-
- 1 deleted
- 18 edited
-
doc/theses/jiada_liang_MMath/planet.cfa (deleted)
-
libcfa/src/enum.cfa (modified) (1 diff)
-
libcfa/src/enum.hfa (modified) (1 diff)
-
src/AST/Expr.cpp (modified) (1 diff)
-
src/AST/Expr.hpp (modified) (1 diff)
-
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/Stmt.hpp (modified) (2 diffs)
-
src/AST/Visitor.hpp (modified) (1 diff)
-
src/Common/CodeLocationTools.cpp (modified) (1 diff)
-
src/ControlStruct/module.mk (modified) (1 diff)
-
src/Parser/StatementNode.cpp (modified) (1 diff)
-
src/Parser/StatementNode.hpp (modified) (1 diff)
-
src/Parser/lex.ll (modified) (1 diff)
-
src/Parser/parser.yy (modified) (5 diffs)
-
src/ResolvExpr/CandidateFinder.cpp (modified) (2 diffs)
-
src/main.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/enum.cfa
r57e43cd r348f8992 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
r57e43cd r348f8992 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
r57e43cd r348f8992 282 282 : Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( nullptr ), type( t ) {} 283 283 284 // --- CountExpr285 286 CountExpr::CountExpr( const CodeLocation & loc, const Type * t )287 : Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), type( t ) {}288 289 284 // --- AlignofExpr 290 285 -
src/AST/Expr.hpp
r57e43cd r348f8992 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_FRIEND506 };507 508 496 /// alignof expression, e.g. `alignof(int)`, `alignof 3+4` 509 497 class AlignofExpr final : public Expr { -
src/AST/Fwd.hpp
r57e43cd r348f8992 85 85 class ConstantExpr; 86 86 class SizeofExpr; 87 class CountExpr;88 87 class AlignofExpr; 89 88 class UntypedOffsetofExpr; -
src/AST/Pass.hpp
r57e43cd r348f8992 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;175 174 const ast::Expr * visit( const ast::AlignofExpr * ) override final; 176 175 const ast::Expr * visit( const ast::UntypedOffsetofExpr * ) override final; -
src/AST/Pass.impl.hpp
r57e43cd r348f8992 802 802 maybe_accept_top( node, &ForStmt::cond ); 803 803 maybe_accept_top( node, &ForStmt::inc ); 804 maybe_accept_top( node, &ForStmt::range_over );805 804 maybe_accept_as_compound( node, &ForStmt::body ); 806 805 } … … 1324 1323 } 1325 1324 1326 VISIT_END( Expr, node );1327 }1328 1329 //--------------------------------------------------------------------------1330 // CountExpr1331 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 }1341 1325 VISIT_END( Expr, node ); 1342 1326 } -
src/AST/Print.cpp
r57e43cd r348f8992 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 1154 1145 virtual const ast::Expr * visit( const ast::AlignofExpr * node ) override final { 1155 1146 os << "Alignof Expression on: "; -
src/AST/Stmt.hpp
r57e43cd r348f8992 237 237 ptr<Expr> cond; 238 238 ptr<Expr> inc; 239 ptr<Expr> range_over;240 239 ptr<Stmt> body; 241 240 ptr<Stmt> else_; … … 243 242 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond, 244 243 const Expr * inc, const Stmt * body, const std::vector<Label> && label = {} ) 245 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), 246 range_over(nullptr), body(body), else_(nullptr) {} 244 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(nullptr) {} 247 245 248 246 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond, 249 247 const Expr * inc, const Stmt * body, const Stmt * else_, const std::vector<Label> && labels = {} ) 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_) {} 248 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(else_) {} 256 249 257 250 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/Visitor.hpp
r57e43cd r348f8992 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;78 77 virtual const ast::Expr * visit( const ast::AlignofExpr * ) = 0; 79 78 virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * ) = 0; -
src/Common/CodeLocationTools.cpp
r57e43cd r348f8992 153 153 macro(ConstantExpr, Expr) \ 154 154 macro(SizeofExpr, Expr) \ 155 macro(CountExpr, Expr ) \156 155 macro(AlignofExpr, Expr) \ 157 156 macro(UntypedOffsetofExpr, Expr) \ -
src/ControlStruct/module.mk
r57e43cd r348f8992 27 27 ControlStruct/LabelGenerator.hpp \ 28 28 ControlStruct/MultiLevelExit.cpp \ 29 ControlStruct/MultiLevelExit.hpp \ 30 ControlStruct/TranslateEnumRange.cpp \ 31 ControlStruct/TranslateEnumRange.hpp 29 ControlStruct/MultiLevelExit.hpp 32 30 -
src/Parser/StatementNode.cpp
r57e43cd r348f8992 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 224 213 ast::Expr * astcond = nullptr; // maybe empty 225 214 astcond = maybeMoveBuild( forctl->condition ); -
src/Parser/StatementNode.hpp
r57e43cd r348f8992 63 63 struct ForCtrl { 64 64 ForCtrl( StatementNode * stmt, ExpressionNode * condition, ExpressionNode * 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 ) {} 65 init( stmt ), condition( condition ), change( change ) {} 68 66 69 67 StatementNode * init; 70 68 ExpressionNode * condition; 71 69 ExpressionNode * change; 72 ExpressionNode * range_over;73 70 }; 74 71 -
src/Parser/lex.ll
r57e43cd r348f8992 321 321 __signed__ { KEYWORD_RETURN(SIGNED); } // GCC 322 322 sizeof { KEYWORD_RETURN(SIZEOF); } 323 __count_e__ { KEYWORD_RETURN(COUNT); } // GCC324 323 static { KEYWORD_RETURN(STATIC); } 325 324 _Static_assert { KEYWORD_RETURN(STATICASSERT); } // C11 -
src/Parser/parser.yy
r57e43cd r348f8992 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 error292 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 } // if303 } else {304 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;305 } // if306 } // enumRangeCtrl307 308 286 static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) { 309 287 SemanticError( yylloc, "syntax error, adjacent identifiers \"%s\" and \"%s\" are not meaningful in an %s.\n" … … 390 368 %token DECIMAL32 DECIMAL64 DECIMAL128 // GCC 391 369 %token ZERO_T ONE_T // CFA 392 %token SIZEOF TYPEOF VA_LIST VA_ARG AUTO_TYPE COUNT// GCC370 %token SIZEOF TYPEOF VA_LIST VA_ARG AUTO_TYPE // GCC 393 371 %token OFFSETOF BASETYPEOF TYPEID // CFA 394 372 %token ENUM STRUCT UNION … … 990 968 // $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); 991 969 } 992 | COUNT '(' type ')'993 {994 // SemanticError( yylloc, "Count is currently unimplemented. "); $$ = nullptr;995 $$ = new ExpressionNode( new ast::CountExpr( yylloc, maybeMoveBuildType( $3 ) ) );996 }997 970 ; 998 971 … … 1626 1599 { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; } 1627 1600 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 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 1633 1607 { 1634 1608 if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { … … 1637 1611 SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr; 1638 1612 } 1613 ; 1614 1615 enum_key: 1616 TYPEDEFname 1617 | ENUM identifier_or_type_name 1639 1618 ; 1640 1619 -
src/ResolvExpr/CandidateFinder.cpp
r57e43cd r348f8992 696 696 void postvisit( const ast::UntypedInitExpr * initExpr ); 697 697 void postvisit( const ast::QualifiedNameExpr * qualifiedExpr ); 698 void postvisit( const ast::CountExpr * countExpr );699 698 700 699 const ast::Expr * makeEnumOffsetCast( const ast::EnumInstType * src, … … 1528 1527 addCandidate( *choice, new ast::SizeofExpr{ sizeofExpr->location, choice->expr } ); 1529 1528 } 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 );1539 1529 } 1540 1530 -
src/main.cpp
r57e43cd r348f8992 53 53 #include "ControlStruct/FixLabels.hpp" // for fixLabels 54 54 #include "ControlStruct/HoistControlDecls.hpp" // hoistControlDecls 55 #include "ControlStruct/TrasnlateEnumRange.hpp" // translateEnumRange56 55 #include "GenPoly/Box.hpp" // for box 57 56 #include "GenPoly/InstantiateGeneric.hpp" // for instantiateGeneric … … 324 323 PASS( "Hoist Struct", Validate::hoistStruct, transUnit ); 325 324 PASS( "Validate Generic Parameters", Validate::fillGenericParameters, transUnit ); 326 PASS( "Translate Enum Range Expression", ControlStruct::translateEnumRange, transUnit );327 325 PASS( "Translate Dimensions", Validate::translateDimensionParameters, transUnit ); 328 326 // Need to happen before fixing returns because implementEnumFunc has ReturnStmt
Note:
See TracChangeset
for help on using the changeset viewer.