Changeset 47534159
- Timestamp:
- Dec 4, 2015, 2:55:22 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 000b914, 63db3d76
- Parents:
- f8b961b
- Location:
- src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rf8b961b r47534159 442 442 output << ")"; 443 443 } 444 445 void CodeGenerator::visit( AlignofExpr *sizeofExpr ) { 446 // use GCC extension to avoid bumping std to C11 447 output << "__alignof__("; 448 if ( sizeofExpr->get_isType() ) { 449 output << genType( sizeofExpr->get_type(), "" ); 450 } else { 451 sizeofExpr->get_expr()->accept( *this ); 452 } // if 453 output << ")"; 454 } 444 455 445 456 void CodeGenerator::visit( LogicalExpr *logicalExpr ) { -
src/CodeGen/CodeGenerator.h
rf8b961b r47534159 60 60 virtual void visit( ConstantExpr *constantExpr ); 61 61 virtual void visit( SizeofExpr *sizeofExpr ); 62 virtual void visit( AlignofExpr *alignofExpr ); 62 63 virtual void visit( LogicalExpr *logicalExpr ); 63 64 virtual void visit( ConditionalExpr *conditionalExpr ); -
src/InitTweak/InitModel.h
rf8b961b r47534159 72 72 void visit( ConstantExpr * ); 73 73 void visit( SizeofExpr * ) { throw 0; } 74 void visit( AlignofExpr * ) { throw 0; } 74 75 void visit( AttrExpr * ) { throw 0; } 75 76 void visit( LogicalExpr * ) { throw 0; } -
src/Parser/ExpressionNode.cc
rf8b961b r47534159 586 586 } 587 587 case OperatorNode::AlignOf: 588 { 589 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) { 590 return new AlignofExpr( arg->get_decl()->buildType()); 591 } else { 592 return new AlignofExpr( args.front()); 593 } // if 594 } 588 595 case OperatorNode::SizeOf: 589 596 { 590 /// bool isSizeOf = ( op->get_type() == OperatorNode::SizeOf );591 592 597 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) { 593 598 return new SizeofExpr( arg->get_decl()->buildType()); -
src/ResolvExpr/AlternativeFinder.cc
rf8b961b r47534159 792 792 } 793 793 794 void AlternativeFinder::visit( AlignofExpr *alignofExpr ) { 795 if ( alignofExpr->get_isType() ) { 796 alternatives.push_back( Alternative( alignofExpr->clone(), env, Cost::zero ) ); 797 } else { 798 // find all alternatives for the argument to sizeof 799 AlternativeFinder finder( indexer, env ); 800 finder.find( alignofExpr->get_expr() ); 801 // find the lowest cost alternative among the alternatives, otherwise ambiguous 802 AltList winners; 803 findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) ); 804 if ( winners.size() != 1 ) { 805 throw SemanticError( "Ambiguous expression in alignof operand: ", alignofExpr->get_expr() ); 806 } // if 807 // return the lowest cost alternative for the argument 808 Alternative &choice = winners.front(); 809 alternatives.push_back( Alternative( new AlignofExpr( choice.expr->clone() ), choice.env, Cost::zero ) ); 810 } // if 811 } 812 794 813 void AlternativeFinder::resolveAttr( DeclarationWithType *funcDecl, FunctionType *function, Type *argType, const TypeEnvironment &env ) { 795 814 // assume no polymorphism -
src/ResolvExpr/AlternativeFinder.h
rf8b961b r47534159 56 56 virtual void visit( ConstantExpr *constantExpr ); 57 57 virtual void visit( SizeofExpr *sizeofExpr ); 58 virtual void visit( AlignofExpr *sizeofExpr ); 58 59 virtual void visit( AttrExpr *attrExpr ); 59 60 virtual void visit( LogicalExpr *logicalExpr ); -
src/SymTab/Indexer.cc
rf8b961b r47534159 215 215 } else { 216 216 maybeAccept( sizeofExpr->get_expr(), *this ); 217 } 218 } 219 220 void Indexer::visit( AlignofExpr *alignofExpr ) { 221 acceptAllNewScope( alignofExpr->get_results(), *this ); 222 if ( alignofExpr->get_isType() ) { 223 maybeAccept( alignofExpr->get_type(), *this ); 224 } else { 225 maybeAccept( alignofExpr->get_expr(), *this ); 217 226 } 218 227 } -
src/SymTab/Indexer.h
rf8b961b r47534159 54 54 virtual void visit( ConstantExpr *constantExpr ); 55 55 virtual void visit( SizeofExpr *sizeofExpr ); 56 virtual void visit( AlignofExpr *alignofExpr ); 56 57 virtual void visit( AttrExpr *attrExpr ); 57 58 virtual void visit( LogicalExpr *logicalExpr ); -
src/SynTree/Expression.cc
rf8b961b r47534159 122 122 void SizeofExpr::print( std::ostream &os, int indent) const { 123 123 os << std::string( indent, ' ' ) << "Sizeof Expression on: "; 124 125 if (isType) 126 type->print(os, indent + 2); 127 else 128 expr->print(os, indent + 2); 129 130 os << std::endl; 131 Expression::print( os, indent ); 132 } 133 134 AlignofExpr::AlignofExpr( Expression *expr_, Expression *_aname ) : 135 Expression( _aname ), expr(expr_), type(0), isType(false) { 136 add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) ); 137 } 138 139 AlignofExpr::AlignofExpr( Type *type_, Expression *_aname ) : 140 Expression( _aname ), expr(0), type(type_), isType(true) { 141 add_result( new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ) ); 142 } 143 144 AlignofExpr::AlignofExpr( const AlignofExpr &other ) : 145 Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 146 } 147 148 AlignofExpr::~AlignofExpr() { 149 delete expr; 150 delete type; 151 } 152 153 void AlignofExpr::print( std::ostream &os, int indent) const { 154 os << std::string( indent, ' ' ) << "Alignof Expression on: "; 124 155 125 156 if (isType) -
src/SynTree/Expression.h
rf8b961b r47534159 23 23 #include "Constant.h" 24 24 25 /// Expression is the root type for all expressions 25 26 class Expression { 26 27 public: … … 47 48 }; 48 49 49 // ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration, 50 // but subject to decay-to-pointer and type parameter renaming 51 50 /// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration, 51 /// but subject to decay-to-pointer and type parameter renaming 52 52 struct ParamEntry { 53 53 ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {} … … 65 65 typedef std::map< UniqueId, ParamEntry > InferredParams; 66 66 67 // ApplicationExpr represents the application of a function to a set of parameters. This is the 68 // result of running an UntypedExpr through the expression analyzer. 69 67 /// ApplicationExpr represents the application of a function to a set of parameters. This is the 68 /// result of running an UntypedExpr through the expression analyzer. 70 69 class ApplicationExpr : public Expression { 71 70 public: … … 89 88 }; 90 89 91 // UntypedExpr represents the application of a function to a set of parameters, but where the 92 // particular overload for the function name has not yet been determined. Most operators are 93 // converted into functional form automatically, to permit operator overloading. 94 90 /// UntypedExpr represents the application of a function to a set of parameters, but where the 91 /// particular overload for the function name has not yet been determined. Most operators are 92 /// converted into functional form automatically, to permit operator overloading. 95 93 class UntypedExpr : public Expression { 96 94 public: … … 118 116 }; 119 117 120 // this classcontains a name whose meaning is still not determined118 /// NameExpr contains a name whose meaning is still not determined 121 119 class NameExpr : public Expression { 122 120 public: … … 139 137 // function-call format. 140 138 141 // AddressExpr represents a address-of expression, e.g. &e139 /// AddressExpr represents a address-of expression, e.g. &e 142 140 class AddressExpr : public Expression { 143 141 public: … … 174 172 }; 175 173 176 // CastExpr represents a type cast expression, e.g. (int)e174 /// CastExpr represents a type cast expression, e.g. (int)e 177 175 class CastExpr : public Expression { 178 176 public: … … 193 191 }; 194 192 195 // UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer193 /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer 196 194 class UntypedMemberExpr : public Expression { 197 195 public: … … 214 212 }; 215 213 216 // MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer214 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer 217 215 class MemberExpr : public Expression { 218 216 public: … … 235 233 }; 236 234 237 // VariableExpr represents an expression that simply refers to the value of a named variable235 /// VariableExpr represents an expression that simply refers to the value of a named variable 238 236 class VariableExpr : public Expression { 239 237 public: … … 253 251 }; 254 252 255 // ConstantExpr represents an expression that simply refers to the value of a constant253 /// ConstantExpr represents an expression that simply refers to the value of a constant 256 254 class ConstantExpr : public Expression { 257 255 public: … … 271 269 }; 272 270 273 // SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)271 /// SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4) 274 272 class SizeofExpr : public Expression { 275 273 public: … … 296 294 }; 297 295 298 // AttrExpr represents an @attribute expression (like sizeof, but user-defined) 296 /// AlignofExpr represents an alignof expression 297 class AlignofExpr : public Expression { 298 public: 299 AlignofExpr( Expression *expr, Expression *_aname = 0 ); 300 AlignofExpr( const AlignofExpr &other ); 301 AlignofExpr( Type *type, Expression *_aname = 0 ); 302 virtual ~AlignofExpr(); 303 304 Expression *get_expr() const { return expr; } 305 void set_expr( Expression *newValue ) { expr = newValue; } 306 Type *get_type() const { return type; } 307 void set_type( Type *newValue ) { type = newValue; } 308 bool get_isType() const { return isType; } 309 void set_isType( bool newValue ) { isType = newValue; } 310 311 virtual AlignofExpr *clone() const { return new AlignofExpr( *this ); } 312 virtual void accept( Visitor &v ) { v.visit( this ); } 313 virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); } 314 virtual void print( std::ostream &os, int indent = 0 ) const; 315 private: 316 Expression *expr; 317 Type *type; 318 bool isType; 319 }; 320 321 /// AttrExpr represents an @attribute expression (like sizeof, but user-defined) 299 322 class AttrExpr : public Expression { 300 323 public: … … 324 347 }; 325 348 326 // LogicalExpr represents a short-circuit boolean expression (&& or ||)349 /// LogicalExpr represents a short-circuit boolean expression (&& or ||) 327 350 class LogicalExpr : public Expression { 328 351 public: … … 347 370 }; 348 371 349 // ConditionalExpr represents the three-argument conditional ( p ? a : b )372 /// ConditionalExpr represents the three-argument conditional ( p ? a : b ) 350 373 class ConditionalExpr : public Expression { 351 374 public: … … 371 394 }; 372 395 373 // CommaExpr represents the sequence operator ( a, b )396 /// CommaExpr represents the sequence operator ( a, b ) 374 397 class CommaExpr : public Expression { 375 398 public: … … 392 415 }; 393 416 394 // TupleExpr represents a tuple expression ( [a, b, c] )417 /// TupleExpr represents a tuple expression ( [a, b, c] ) 395 418 class TupleExpr : public Expression { 396 419 public: … … 410 433 }; 411 434 412 // SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on435 /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on 413 436 class SolvedTupleExpr : public Expression { 414 437 public: … … 428 451 }; 429 452 430 // TypeExpr represents a type used in an expression (e.g. as a type generator parameter)453 /// TypeExpr represents a type used in an expression (e.g. as a type generator parameter) 431 454 class TypeExpr : public Expression { 432 455 public: … … 446 469 }; 447 470 448 // AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)471 /// AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result) 449 472 class AsmExpr : public Expression { 450 473 public: … … 472 495 }; 473 496 474 // ValofExpr represents a GCC 'lambda expression'497 /// ValofExpr represents a GCC 'lambda expression' 475 498 class UntypedValofExpr : public Expression { 476 499 public: -
src/SynTree/Mutator.cc
rf8b961b r47534159 251 251 } 252 252 253 Expression *Mutator::mutate( AlignofExpr *alignofExpr ) { 254 mutateAll( alignofExpr->get_results(), *this ); 255 if ( alignofExpr->get_isType() ) { 256 alignofExpr->set_type( maybeMutate( alignofExpr->get_type(), *this ) ); 257 } else { 258 alignofExpr->set_expr( maybeMutate( alignofExpr->get_expr(), *this ) ); 259 } 260 return alignofExpr; 261 } 262 253 263 Expression *Mutator::mutate( AttrExpr *attrExpr ) { 254 264 mutateAll( attrExpr->get_results(), *this ); -
src/SynTree/Mutator.h
rf8b961b r47534159 64 64 virtual Expression* mutate( ConstantExpr *constantExpr ); 65 65 virtual Expression* mutate( SizeofExpr *sizeofExpr ); 66 virtual Expression* mutate( AlignofExpr *alignofExpr ); 66 67 virtual Expression* mutate( AttrExpr *attrExpr ); 67 68 virtual Expression* mutate( LogicalExpr *logicalExpr ); -
src/SynTree/SynTree.h
rf8b961b r47534159 69 69 class ConstantExpr; 70 70 class SizeofExpr; 71 class AlignofExpr; 71 72 class AttrExpr; 72 73 class LogicalExpr; -
src/SynTree/Visitor.cc
rf8b961b r47534159 210 210 } 211 211 212 void Visitor::visit( AlignofExpr *alignofExpr ) { 213 acceptAll( alignofExpr->get_results(), *this ); 214 if ( alignofExpr->get_isType() ) { 215 maybeAccept( alignofExpr->get_type(), *this ); 216 } else { 217 maybeAccept( alignofExpr->get_expr(), *this ); 218 } 219 } 220 212 221 void Visitor::visit( AttrExpr *attrExpr ) { 213 222 acceptAll( attrExpr->get_results(), *this ); -
src/SynTree/Visitor.h
rf8b961b r47534159 64 64 virtual void visit( ConstantExpr *constantExpr ); 65 65 virtual void visit( SizeofExpr *sizeofExpr ); 66 virtual void visit( AlignofExpr *alignofExpr ); 66 67 virtual void visit( AttrExpr *attrExpr ); 67 68 virtual void visit( LogicalExpr *logicalExpr ); -
src/Tuples/FlattenTuple.cc
rf8b961b r47534159 46 46 void FlattenTuple::CollectArgs::visit( ConstantExpr *expr ) { currentArgs.insert( currentArgs.end(), expr ); } 47 47 void FlattenTuple::CollectArgs::visit( SizeofExpr *expr ) { currentArgs.insert( currentArgs.end(), expr ); } 48 void FlattenTuple::CollectArgs::visit( AlignofExpr *expr ) { currentArgs.insert( currentArgs.end(), expr ); } 48 49 void FlattenTuple::CollectArgs::visit( AttrExpr *expr ) { currentArgs.insert( currentArgs.end(), expr ); } 49 50 void FlattenTuple::CollectArgs::visit( LogicalExpr *expr ) { currentArgs.insert( currentArgs.end(), expr ); } -
src/Tuples/FlattenTuple.h
rf8b961b r47534159 42 42 virtual void visit( ConstantExpr * ); 43 43 virtual void visit( SizeofExpr * ); 44 virtual void visit( AlignofExpr * ); 44 45 virtual void visit( AttrExpr * ); 45 46 virtual void visit( LogicalExpr * );
Note: See TracChangeset
for help on using the changeset viewer.