Changeset 8633f060
- Timestamp:
- Apr 19, 2018, 6:11:14 PM (6 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:
- 88f15ae
- Parents:
- c28afead (diff), b03eed6 (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. - Location:
- src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rc28afead r8633f060 596 596 output << ")"; 597 597 } // if 598 castExpr->get_arg()->accept( *visitor ); 598 castExpr->arg->accept( *visitor ); 599 output << ")"; 600 } 601 602 void CodeGenerator::postvisit( KeywordCastExpr * castExpr ) { 603 assertf( ! genC, "KeywordCast should not reach code generation." ); 604 extension( castExpr ); 605 output << "((" << castExpr->targetString() << " &)"; 606 castExpr->arg->accept( *visitor ); 599 607 output << ")"; 600 608 } -
src/CodeGen/CodeGenerator.h
rc28afead r8633f060 69 69 void postvisit( LabelAddressExpr *addressExpr ); 70 70 void postvisit( CastExpr *castExpr ); 71 void postvisit( KeywordCastExpr * castExpr ); 71 72 void postvisit( VirtualCastExpr *castExpr ); 72 73 void postvisit( UntypedMemberExpr *memberExpr ); -
src/CodeGen/GenType.cc
rc28afead r8633f060 48 48 void postvisit( ZeroType * zeroType ); 49 49 void postvisit( OneType * oneType ); 50 void postvisit( TraitInstType * inst ); 51 void postvisit( TypeofType * typeof ); 50 52 51 53 private: … … 289 291 } 290 292 293 void GenType::postvisit( TraitInstType * inst ) { 294 assertf( ! genC, "Trait types should not reach code generation." ); 295 typeString = inst->name + " " + typeString; 296 handleQualifiers( inst ); 297 } 298 299 void GenType::postvisit( TypeofType * typeof ) { 300 std::ostringstream os; 301 PassVisitor<CodeGenerator> cg( os, pretty, genC, lineMarks ); 302 os << "typeof("; 303 typeof->expr->accept( cg ); 304 os << ") " << typeString; 305 typeString = os.str(); 306 handleQualifiers( typeof ); 307 } 308 291 309 void GenType::handleQualifiers( Type * type ) { 292 310 if ( type->get_const() ) { -
src/Common/PassVisitor.h
rc28afead r8633f060 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
rc28afead r8633f060 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
rc28afead r8633f060 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/GenPoly/Box.cc
rc28afead r8633f060 184 184 /// change the type of generic aggregate members to char[] 185 185 void mutateMembers( AggregateDecl * aggrDecl ); 186 /// returns the calculated sizeof expression for ty, or nullptr for use C sizeof() 187 Expression* genSizeof( Type* ty ); 186 188 187 189 /// Enters a new scope for type-variables, adding the type variables from ty … … 382 384 unsigned long n_members = 0; 383 385 bool firstMember = true; 384 for ( std::list< Declaration* >::const_iterator member = structDecl->get_members().begin(); member != structDecl->get_members().end(); ++member) {385 DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member );386 for ( Declaration* member : structDecl->get_members() ) { 387 DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( member ); 386 388 assert( dwt ); 387 389 Type *memberType = dwt->get_type(); … … 1747 1749 } 1748 1750 1751 Expression * PolyGenericCalculator::genSizeof( Type* ty ) { 1752 if ( ArrayType * aty = dynamic_cast<ArrayType *>(ty) ) { 1753 // generate calculated size for possibly generic array 1754 Expression * sizeofBase = genSizeof( aty->get_base() ); 1755 if ( ! sizeofBase ) return nullptr; 1756 Expression * dim = aty->get_dimension(); 1757 aty->set_dimension( nullptr ); 1758 return makeOp( "?*?", sizeofBase, dim ); 1759 } else if ( findGeneric( ty ) ) { 1760 // generate calculated size for generic type 1761 return new NameExpr( sizeofName( mangleType( ty ) ) ); 1762 } else return nullptr; 1763 } 1764 1749 1765 Expression *PolyGenericCalculator::postmutate( SizeofExpr *sizeofExpr ) { 1750 Type *ty = sizeofExpr->get_isType() ? sizeofExpr->get_type() : sizeofExpr->get_expr()->get_result(); 1751 if ( findGeneric( ty ) ) { 1752 Expression *ret = new NameExpr( sizeofName( mangleType( ty ) ) ); 1766 Type *ty = sizeofExpr->get_isType() ? 1767 sizeofExpr->get_type() : sizeofExpr->get_expr()->get_result(); 1768 1769 Expression * gen = genSizeof( ty ); 1770 if ( gen ) { 1753 1771 delete sizeofExpr; 1754 return ret; 1755 } 1756 return sizeofExpr; 1772 return gen; 1773 } else return sizeofExpr; 1757 1774 } 1758 1775 -
src/Parser/ExpressionNode.cc
rc28afead r8633f060 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
rc28afead r8633f060 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
rc28afead r8633f060 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
rc28afead r8633f060 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
rc28afead r8633f060 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
rc28afead r8633f060 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
rc28afead r8633f060 69 69 class LabelAddressExpr; 70 70 class CastExpr; 71 class KeywordCastExpr; 71 72 class VirtualCastExpr; 72 73 class MemberExpr; -
src/SynTree/Visitor.h
rc28afead r8633f060 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.