Changeset 9a705dc8
- Timestamp:
- Apr 19, 2018, 5:18:46 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- da9d79b
- Parents:
- 60ba456
- Location:
- src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.h
r60ba456 r9a705dc8 92 92 virtual void visit( NameExpr * nameExpr ) override final; 93 93 virtual void visit( CastExpr * castExpr ) override final; 94 virtual void visit( KeywordCastExpr * castExpr ) override final; 94 95 virtual void visit( VirtualCastExpr * castExpr ) override final; 95 96 virtual void visit( AddressExpr * addressExpr ) override final; … … 187 188 virtual Expression * mutate( UntypedExpr * untypedExpr ) override final; 188 189 virtual Expression * mutate( NameExpr * nameExpr ) override final; 189 virtual Expression * mutate( AddressExpr * castExpr ) override final;190 virtual Expression * mutate( AddressExpr * addrExpr ) override final; 190 191 virtual Expression * mutate( LabelAddressExpr * labAddressExpr ) override final; 191 192 virtual Expression * mutate( CastExpr * castExpr ) override final; 193 virtual Expression * mutate( KeywordCastExpr * castExpr ) override final; 192 194 virtual Expression * mutate( VirtualCastExpr * castExpr ) override final; 193 195 virtual Expression * mutate( UntypedMemberExpr * memberExpr ) override final; -
src/Common/PassVisitor.impl.h
r60ba456 r9a705dc8 1259 1259 1260 1260 //-------------------------------------------------------------------------- 1261 // KeywordCastExpr 1262 template< typename pass_type > 1263 void PassVisitor< pass_type >::visit( KeywordCastExpr * node ) { 1264 VISIT_START( node ); 1265 1266 indexerScopedAccept( node->result, *this ); 1267 maybeAccept_impl ( node->arg , *this ); 1268 1269 VISIT_END( node ); 1270 } 1271 1272 template< typename pass_type > 1273 Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) { 1274 MUTATE_START( node ); 1275 1276 indexerScopedMutate( node->env , *this ); 1277 indexerScopedMutate( node->result, *this ); 1278 maybeMutate_impl ( node->arg , *this ); 1279 1280 MUTATE_END( Expression, node ); 1281 } 1282 1283 //-------------------------------------------------------------------------- 1261 1284 // VirtualCastExpr 1262 1285 template< typename pass_type > -
src/Concurrency/Keywords.cc
r60ba456 r9a705dc8 53 53 public: 54 54 55 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main ) :56 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ) {}55 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, KeywordCastExpr::Target cast_target ) : 56 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ), cast_target( cast_target ) {} 57 57 58 58 virtual ~ConcurrentSueKeyword() {} 59 59 60 void postvisit( StructDecl * decl );60 Declaration * postmutate( StructDecl * decl ); 61 61 62 62 void handle( StructDecl * ); … … 66 66 67 67 virtual bool is_target( StructDecl * decl ) = 0; 68 69 Expression * postmutate( KeywordCastExpr * cast ); 68 70 69 71 private: … … 73 75 const std::string context_error; 74 76 bool needs_main; 77 KeywordCastExpr::Target cast_target; 75 78 76 79 StructDecl* type_decl = nullptr; … … 95 98 "get_thread", 96 99 "thread keyword requires threads to be in scope, add #include <thread>", 97 true 100 true, 101 KeywordCastExpr::Thread 98 102 ) 99 103 {} … … 105 109 static void implement( std::list< Declaration * > & translationUnit ) { 106 110 PassVisitor< ThreadKeyword > impl; 107 acceptAll( translationUnit, impl );111 mutateAll( translationUnit, impl ); 108 112 } 109 113 }; … … 126 130 "get_coroutine", 127 131 "coroutine keyword requires coroutines to be in scope, add #include <coroutine>", 128 true 132 true, 133 KeywordCastExpr::Coroutine 129 134 ) 130 135 {} … … 136 141 static void implement( std::list< Declaration * > & translationUnit ) { 137 142 PassVisitor< CoroutineKeyword > impl; 138 acceptAll( translationUnit, impl );143 mutateAll( translationUnit, impl ); 139 144 } 140 145 }; … … 157 162 "get_monitor", 158 163 "monitor keyword requires monitors to be in scope, add #include <monitor>", 159 false 164 false, 165 KeywordCastExpr::Monitor 160 166 ) 161 167 {} … … 167 173 static void implement( std::list< Declaration * > & translationUnit ) { 168 174 PassVisitor< MonitorKeyword > impl; 169 acceptAll( translationUnit, impl );175 mutateAll( translationUnit, impl ); 170 176 } 171 177 }; … … 267 273 } 268 274 269 void ConcurrentSueKeyword::postvisit(StructDecl * decl) {275 Declaration * ConcurrentSueKeyword::postmutate(StructDecl * decl) { 270 276 if( decl->name == type_name && decl->body ) { 271 277 assert( !type_decl ); … … 275 281 handle( decl ); 276 282 } 277 } 283 return decl; 284 } 285 286 Expression * ConcurrentSueKeyword::postmutate( KeywordCastExpr * cast ) { 287 if ( cast_target == cast->target ) { 288 // convert (thread &)t to (thread_desc &)*get_thread(t), etc. 289 if( !type_decl ) SemanticError( cast, context_error ); 290 Expression * arg = cast->arg; 291 cast->arg = nullptr; 292 delete cast; 293 return new CastExpr( 294 UntypedExpr::createDeref( 295 new UntypedExpr( new NameExpr( getter_name ), { arg } ) 296 ), 297 new ReferenceType( 298 noQualifiers, 299 new StructInstType( noQualifiers, type_decl ) ) 300 ); 301 } 302 return cast; 303 } 304 278 305 279 306 void ConcurrentSueKeyword::handle( StructDecl * decl ) { -
src/Parser/ExpressionNode.cc
r60ba456 r9a705dc8 414 414 } // build_cast 415 415 416 Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node ) { 417 return new KeywordCastExpr( maybeMoveBuild< Expression >(expr_node), target ); 418 } 419 416 420 Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) { 417 421 return new VirtualCastExpr( maybeMoveBuild< Expression >( expr_node ), maybeMoveBuildType( decl_node ) ); -
src/Parser/ParseNode.h
r60ba456 r9a705dc8 179 179 180 180 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); 181 Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node ); 181 182 Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); 182 183 Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ); -
src/Parser/parser.yy
r60ba456 r9a705dc8 688 688 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 689 689 | '(' COROUTINE '&' ')' cast_expression // CFA 690 { SemanticError( yylloc, "coroutine cast is currently unimplemented." ); $$ = nullptr; }690 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } 691 691 | '(' THREAD '&' ')' cast_expression // CFA 692 { SemanticError( yylloc, "monitor cast is currently unimplemented." ); $$ = nullptr; }692 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Thread, $5 ) ); } 693 693 | '(' MONITOR '&' ')' cast_expression // CFA 694 { SemanticError( yylloc, "thread cast is currently unimplemented." ); $$ = nullptr; }694 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Monitor, $5 ) ); } 695 695 // VIRTUAL cannot be opt because of look ahead issues 696 696 | '(' VIRTUAL ')' cast_expression // CFA -
src/SynTree/Expression.cc
r60ba456 r9a705dc8 299 299 } 300 300 301 KeywordCastExpr::KeywordCastExpr( Expression *arg, Target target ) : Expression(), arg(arg), target( target ) { 302 } 303 304 KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) { 305 } 306 307 KeywordCastExpr::~KeywordCastExpr() { 308 delete arg; 309 } 310 311 const std::string & KeywordCastExpr::targetString() const { 312 static const std::string targetStrs[] = { 313 "coroutine", "thread", "monitor" 314 }; 315 static_assert( 316 (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS), 317 "Each KeywordCastExpr::Target should have a corresponding string representation" 318 ); 319 return targetStrs[(unsigned long)target]; 320 } 321 322 void KeywordCastExpr::print( std::ostream &os, Indenter indent ) const { 323 os << "Keyword Cast of:" << std::endl << indent+1; 324 arg->print(os, indent+1); 325 os << std::endl << indent << "... to: "; 326 os << targetString(); 327 Expression::print( os, indent ); 328 } 329 301 330 VirtualCastExpr::VirtualCastExpr( Expression *arg_, Type *toType ) : Expression(), arg(arg_) { 302 331 set_result(toType); -
src/SynTree/Expression.h
r60ba456 r9a705dc8 192 192 CastExpr( Expression * arg, bool isGenerated = true ); 193 193 CastExpr( Expression * arg, Type * toType, bool isGenerated = true ); 194 CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor 194 195 CastExpr( const CastExpr & other ); 195 196 virtual ~CastExpr(); … … 199 200 200 201 virtual CastExpr * clone() const { return new CastExpr( * this ); } 202 virtual void accept( Visitor & v ) { v.visit( this ); } 203 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 204 virtual void print( std::ostream & os, Indenter indent = {} ) const; 205 }; 206 207 /// KeywordCastExpr represents a cast to 'keyword types', e.g. (thread &)t 208 class KeywordCastExpr : public Expression { 209 public: 210 Expression * arg; 211 enum Target { 212 Coroutine, Thread, Monitor, NUMBER_OF_TARGETS 213 } target; 214 215 KeywordCastExpr( Expression * arg, Target target ); 216 KeywordCastExpr( const KeywordCastExpr & other ); 217 virtual ~KeywordCastExpr(); 218 219 const std::string & targetString() const; 220 221 virtual KeywordCastExpr * clone() const { return new KeywordCastExpr( * this ); } 201 222 virtual void accept( Visitor & v ) { v.visit( this ); } 202 223 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } -
src/SynTree/Mutator.h
r60ba456 r9a705dc8 59 59 virtual Expression * mutate( UntypedExpr * untypedExpr ) = 0; 60 60 virtual Expression * mutate( NameExpr * nameExpr ) = 0; 61 virtual Expression * mutate( AddressExpr * castExpr ) = 0;61 virtual Expression * mutate( AddressExpr * addrExpr ) = 0; 62 62 virtual Expression * mutate( LabelAddressExpr * labAddressExpr ) = 0; 63 63 virtual Expression * mutate( CastExpr * castExpr ) = 0; 64 virtual Expression * mutate( KeywordCastExpr * castExpr ) = 0; 64 65 virtual Expression * mutate( VirtualCastExpr * castExpr ) = 0; 65 66 virtual Expression * mutate( UntypedMemberExpr * memberExpr ) = 0; -
src/SynTree/SynTree.h
r60ba456 r9a705dc8 69 69 class LabelAddressExpr; 70 70 class CastExpr; 71 class KeywordCastExpr; 71 72 class VirtualCastExpr; 72 73 class MemberExpr; -
src/SynTree/Visitor.h
r60ba456 r9a705dc8 62 62 virtual void visit( NameExpr * nameExpr ) = 0; 63 63 virtual void visit( CastExpr * castExpr ) = 0; 64 virtual void visit( KeywordCastExpr * castExpr ) = 0; 64 65 virtual void visit( VirtualCastExpr * castExpr ) = 0; 65 66 virtual void visit( AddressExpr * addressExpr ) = 0;
Note: See TracChangeset
for help on using the changeset viewer.