Changeset 5809461
- Timestamp:
- Sep 1, 2017, 6:59:48 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, resolv-new, with_gc
- Children:
- b0dfbc4
- Parents:
- bc3127d
- Location:
- src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rbc3127d r5809461 546 546 extension( addressExpr ); 547 547 output << "(&"; 548 // this hack makes sure that we don't convert "constant_zero" to "0" if we're taking its address 549 if ( VariableExpr * variableExpr = dynamic_cast< VariableExpr* >( addressExpr->get_arg() ) ) { 550 output << mangleName( variableExpr->get_var() ); 551 } else { 552 addressExpr->get_arg()->accept( *this ); 553 } // if 548 addressExpr->arg->accept( *this ); 554 549 output << ")"; 550 } 551 552 void CodeGenerator::visit( LabelAddressExpr *addressExpr ) { 553 extension( addressExpr ); 554 output << "(&&" << addressExpr->arg << ")"; 555 555 } 556 556 -
src/CodeGen/CodeGenerator.h
rbc3127d r5809461 59 59 virtual void visit( NameExpr *nameExpr ); 60 60 virtual void visit( AddressExpr *addressExpr ); 61 virtual void visit( LabelAddressExpr *addressExpr ); 61 62 virtual void visit( CastExpr *castExpr ); 62 63 virtual void visit( VirtualCastExpr *castExpr ); -
src/CodeGen/OperatorTable.cc
rbc3127d r5809461 66 66 { "?^=?", "^=", "_operator_bitxorassign", OT_INFIXASSIGN }, 67 67 { "?|=?", "|=", "_operator_bitorassign", OT_INFIXASSIGN }, 68 { "&&", "&&", "&&", OT_LABELADDRESS }69 68 }; 70 69 -
src/InitTweak/FixInit.cc
rbc3127d r5809461 127 127 128 128 // don't go into other functions 129 virtual void visit( __attribute__((unused)) FunctionDecl *decl) override {}129 virtual void visit( FunctionDecl * ) override {} 130 130 131 131 protected: … … 913 913 // of the error. See C++ Reference 6.6 Jump Statements for details. 914 914 void InsertDtors::handleGoto( BranchStmt * stmt ) { 915 assert( stmt->get_target() != "" && "BranchStmt missing a label" ); 915 // can't do anything for computed goto 916 if ( stmt->computedTarget ) return; 917 918 assertf( stmt->get_target() != "", "BranchStmt missing a label: %s", toString( stmt ).c_str() ); 916 919 // S_L = lvars = set of objects in scope at label definition 917 920 // S_G = curVars = set of objects in scope at goto statement -
src/InitTweak/InitTweak.cc
rbc3127d r5809461 497 497 using Visitor::visit; 498 498 499 virtual void visit( __attribute((unused)) ApplicationExpr *applicationExpr ) { isConstExpr = false; } 500 virtual void visit( __attribute((unused)) UntypedExpr *untypedExpr ) { isConstExpr = false; } 501 virtual void visit( NameExpr *nameExpr ) { 502 // xxx - temporary hack, because 0 and 1 really should be constexprs, even though they technically aren't in Cforall today 503 if ( nameExpr->get_name() != "0" && nameExpr->get_name() != "1" ) isConstExpr = false; 504 } 499 virtual void visit( ApplicationExpr * ) { isConstExpr = false; } 500 virtual void visit( UntypedExpr * ) { isConstExpr = false; } 501 virtual void visit( NameExpr * ) { isConstExpr = false; } 505 502 // virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 506 503 virtual void visit( AddressExpr *addressExpr ) { … … 509 506 if ( ! dynamic_cast< NameExpr * >( arg) && ! dynamic_cast< VariableExpr * >( arg ) && ! dynamic_cast< MemberExpr * >( arg ) && ! dynamic_cast< UntypedMemberExpr * >( arg ) ) isConstExpr = false; 510 507 } 511 virtual void visit( __attribute((unused)) LabelAddressExpr *labAddressExpr ) { isConstExpr = false; } 512 virtual void visit( __attribute((unused)) UntypedMemberExpr *memberExpr ) { isConstExpr = false; } 513 virtual void visit( __attribute((unused)) MemberExpr *memberExpr ) { isConstExpr = false; } 514 virtual void visit( __attribute((unused)) VariableExpr *variableExpr ) { isConstExpr = false; } 508 virtual void visit( UntypedMemberExpr * ) { isConstExpr = false; } 509 virtual void visit( MemberExpr * ) { isConstExpr = false; } 510 virtual void visit( VariableExpr * ) { isConstExpr = false; } 515 511 // these might be okay? 516 512 // virtual void visit( SizeofExpr *sizeofExpr ); … … 523 519 // virtual void visit( LogicalExpr *logicalExpr ); 524 520 // virtual void visit( ConditionalExpr *conditionalExpr ); 525 virtual void visit( __attribute((unused)) TypeExpr *typeExpr) { isConstExpr = false; }526 virtual void visit( __attribute((unused)) AsmExpr *asmExpr) { isConstExpr = false; }527 virtual void visit( __attribute((unused)) UntypedValofExpr *valofExpr) { isConstExpr = false; }528 virtual void visit( __attribute((unused)) CompoundLiteralExpr *compLitExpr) { isConstExpr = false; }529 virtual void visit( __attribute((unused)) UntypedTupleExpr *tupleExpr) { isConstExpr = false; }530 virtual void visit( __attribute((unused)) TupleExpr *tupleExpr) { isConstExpr = false; }531 virtual void visit( __attribute((unused)) TupleAssignExpr *tupleExpr) { isConstExpr = false; }521 virtual void visit( TypeExpr * ) { isConstExpr = false; } 522 virtual void visit( AsmExpr * ) { isConstExpr = false; } 523 virtual void visit( UntypedValofExpr * ) { isConstExpr = false; } 524 virtual void visit( CompoundLiteralExpr * ) { isConstExpr = false; } 525 virtual void visit( UntypedTupleExpr * ) { isConstExpr = false; } 526 virtual void visit( TupleExpr * ) { isConstExpr = false; } 527 virtual void visit( TupleAssignExpr * ) { isConstExpr = false; } 532 528 533 529 bool isConstExpr; -
src/Parser/ExpressionNode.cc
rbc3127d r5809461 230 230 // ret = new UntypedExpr( new NameExpr( units, ret ) ); 231 231 // } // if 232 232 233 233 delete &str; // created by lex 234 234 return ret; … … 282 282 } // build_varref 283 283 284 284 // TODO: get rid of this and OperKinds and reuse code from OperatorTable 285 285 static const char * OperName[] = { // must harmonize with OperKinds 286 286 // diadic … … 290 290 "?[?]", "...", 291 291 // monadic 292 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&"292 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", 293 293 }; // OperName 294 294 -
src/Parser/ParseNode.h
rbc3127d r5809461 154 154 Index, Range, 155 155 // monadic 156 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress,156 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, 157 157 Ctor, Dtor, 158 158 }; // OperKinds -
src/Parser/parser.yy
rbc3127d r5809461 536 536 $$ = new ExpressionNode( build_unary_val( $1, $2 ) ); 537 537 break; 538 case OperKinds::And: 539 $$ = new ExpressionNode( new AddressExpr( build_addressOf( $2 ) ) ); 540 break; 538 541 default: 539 542 assert( false ); … … 562 565 | ATTR_IDENTIFIER '(' type ')' 563 566 { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); } 564 // | ANDAND IDENTIFIER // GCC, address of label565 // { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2 ) ); }566 567 ; 567 568 -
src/ResolvExpr/AlternativeFinder.cc
rbc3127d r5809461 698 698 699 699 void AlternativeFinder::visit( UntypedExpr *untypedExpr ) { 700 {701 std::string fname = InitTweak::getFunctionName( untypedExpr );702 if ( fname == "&&" ) {703 VoidType v = Type::Qualifiers(); // resolve to type void *704 PointerType pt( Type::Qualifiers(), v.clone() );705 UntypedExpr *vexpr = untypedExpr->clone();706 vexpr->set_result( pt.clone() );707 alternatives.push_back( Alternative( vexpr, env, Cost::zero) );708 return;709 }710 }711 712 700 AlternativeFinder funcFinder( indexer, env ); 713 701 funcFinder.findWithAdjustment( untypedExpr->get_function() ); … … 856 844 } // if 857 845 } // for 846 } 847 848 void AlternativeFinder::visit( LabelAddressExpr * expr ) { 849 alternatives.push_back( Alternative( expr->clone(), env, Cost::zero) ); 858 850 } 859 851 -
src/ResolvExpr/AlternativeFinder.h
rbc3127d r5809461 54 54 virtual void visit( UntypedExpr *untypedExpr ); 55 55 virtual void visit( AddressExpr *addressExpr ); 56 virtual void visit( LabelAddressExpr *labelExpr ); 56 57 virtual void visit( CastExpr *castExpr ); 57 58 virtual void visit( VirtualCastExpr *castExpr ); -
src/SymTab/Indexer.cc
rbc3127d r5809461 398 398 void Indexer::visit( LabelAddressExpr *labAddressExpr ) { 399 399 acceptNewScope( labAddressExpr->get_result(), *this ); 400 maybeAccept( labAddressExpr->get_arg(), *this );401 400 } 402 401 -
src/SymTab/Validate.cc
rbc3127d r5809461 244 244 }; 245 245 246 struct LabelAddressFixer final : public WithGuards { 247 std::set< Label > labels; 248 249 void premutate( FunctionDecl * funcDecl ); 250 Expression * postmutate( AddressExpr * addrExpr ); 251 }; 246 252 247 253 FunctionDecl * dereferenceOperator = nullptr; … … 257 263 PassVisitor<ValidateGenericParameters> genericParams; 258 264 PassVisitor<FindSpecialDeclarations> finder; 265 PassVisitor<LabelAddressFixer> labelAddrFixer; 259 266 260 267 EliminateTypedef::eliminateTypedef( translationUnit ); … … 274 281 ArrayLength::computeLength( translationUnit ); 275 282 acceptAll( translationUnit, finder ); 283 mutateAll( translationUnit, labelAddrFixer ); 276 284 } 277 285 … … 977 985 } 978 986 987 struct LabelFinder { 988 std::set< Label > & labels; 989 LabelFinder( std::set< Label > & labels ) : labels( labels ) {} 990 void previsit( Statement * stmt ) { 991 for ( Label & l : stmt->labels ) { 992 labels.insert( l ); 993 } 994 } 995 }; 996 997 void LabelAddressFixer::premutate( FunctionDecl * funcDecl ) { 998 GuardValue( labels ); 999 PassVisitor<LabelFinder> finder( labels ); 1000 funcDecl->accept( finder ); 1001 } 1002 1003 Expression * LabelAddressFixer::postmutate( AddressExpr * addrExpr ) { 1004 // convert &&label into label address 1005 if ( AddressExpr * inner = dynamic_cast< AddressExpr * >( addrExpr->arg ) ) { 1006 if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( inner->arg ) ) { 1007 if ( labels.count( nameExpr->name ) ) { 1008 Label name = nameExpr->name; 1009 delete addrExpr; 1010 return new LabelAddressExpr( name ); 1011 } 1012 } 1013 } 1014 return addrExpr; 1015 } 1016 979 1017 void FindSpecialDeclarations::previsit( FunctionDecl * funcDecl ) { 980 1018 if ( ! dereferenceOperator ) { -
src/SynTree/AddressExpr.cc
rbc3127d r5809461 70 70 } 71 71 72 LabelAddressExpr::LabelAddressExpr( const Label &arg ) : arg( arg ) { 73 // label address always has type void * 74 result = new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ); 75 } 76 LabelAddressExpr::LabelAddressExpr( const LabelAddressExpr & other ) : Expression( other ), arg( other.arg ) {} 77 LabelAddressExpr::~LabelAddressExpr() {} 78 79 void LabelAddressExpr::print( std::ostream & os, int indent ) const { 80 os << "Address of label:" << std::endl << std::string( indent+2, ' ' ) << arg; 81 } 82 72 83 // Local Variables: // 73 84 // tab-width: 4 // -
src/SynTree/Expression.h
rbc3127d r5809461 24 24 #include "Constant.h" // for Constant 25 25 #include "Initializer.h" // for Designation (ptr only), Initializer 26 #include "Label.h" // for Label 26 27 #include "Mutator.h" // for Mutator 27 28 #include "SynTree.h" // for UniqueId … … 173 174 }; 174 175 175 // xxx - this doesn't appear to actually be hooked in anywhere. We should use this instead of the "&&"" UntypedExpr hack 176 // GCC &&label 177 // https://gcc.gnu.org/onlinedocs/gcc-3.4.2/gcc/Labels-as-Values.html 176 178 class LabelAddressExpr : public Expression { 177 179 public: 178 Expression *arg;179 180 LabelAddressExpr( Expression *arg );180 Label arg; 181 182 LabelAddressExpr( const Label &arg ); 181 183 LabelAddressExpr( const LabelAddressExpr & other ); 182 184 virtual ~LabelAddressExpr(); 183 184 Expression * get_arg() const { return arg; }185 void set_arg(Expression * newValue ) { arg = newValue; }186 185 187 186 virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); } -
src/SynTree/Mutator.cc
rbc3127d r5809461 246 246 labelAddressExpr->set_env( maybeMutate( labelAddressExpr->get_env(), *this ) ); 247 247 labelAddressExpr->set_result( maybeMutate( labelAddressExpr->get_result(), *this ) ); 248 labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );249 248 return labelAddressExpr; 250 249 } -
src/SynTree/Visitor.cc
rbc3127d r5809461 205 205 void Visitor::visit( LabelAddressExpr *labAddressExpr ) { 206 206 maybeAccept( labAddressExpr->get_result(), *this ); 207 maybeAccept( labAddressExpr->get_arg(), *this );208 207 } 209 208 -
src/tests/dtor-early-exit.c
rbc3127d r5809461 220 220 } 221 221 222 // TODO: implement __label__ and uncomment these lines 223 void computedGoto() { 224 // __label__ bar; 225 void *ptr; 226 ptr = &&foo; 227 goto *ptr; 228 assert(false); 229 foo: ; 230 // void f() { 231 // ptr = &&bar; 232 // goto *ptr; 233 // assert(false); 234 // } 235 // f(); 236 // assert(false); 237 // bar: ; 238 } 239 222 240 int main() { 223 241 sepDisable(sout); … … 229 247 sout | endl; 230 248 h(); 249 250 computedGoto(); 231 251 } 232 252
Note: See TracChangeset
for help on using the changeset viewer.