Changes in / [000b914:e58be8e]
- Location:
- src
- Files:
-
- 22 edited
-
CodeGen/CodeGenerator.cc (modified) (1 diff)
-
CodeGen/CodeGenerator.h (modified) (1 diff)
-
GenPoly/Box.cc (modified) (6 diffs)
-
GenPoly/FindFunction.h (modified) (1 diff)
-
GenPoly/GenPoly.cc (modified) (1 diff)
-
GenPoly/Lvalue.cc (modified) (2 diffs)
-
GenPoly/ScrubTyVars.h (modified) (1 diff)
-
InitTweak/InitModel.h (modified) (1 diff)
-
Parser/ExpressionNode.cc (modified) (1 diff)
-
ResolvExpr/AlternativeFinder.cc (modified) (1 diff)
-
ResolvExpr/AlternativeFinder.h (modified) (1 diff)
-
SymTab/Indexer.cc (modified) (1 diff)
-
SymTab/Indexer.h (modified) (1 diff)
-
SynTree/Expression.cc (modified) (1 diff)
-
SynTree/Expression.h (modified) (21 diffs)
-
SynTree/Mutator.cc (modified) (1 diff)
-
SynTree/Mutator.h (modified) (1 diff)
-
SynTree/SynTree.h (modified) (1 diff)
-
SynTree/Visitor.cc (modified) (1 diff)
-
SynTree/Visitor.h (modified) (1 diff)
-
Tuples/FlattenTuple.cc (modified) (1 diff)
-
Tuples/FlattenTuple.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r000b914 re58be8e 442 442 output << ")"; 443 443 } 444 445 void CodeGenerator::visit( AlignofExpr *sizeofExpr ) {446 // use GCC extension to avoid bumping std to C11447 output << "__alignof__(";448 if ( sizeofExpr->get_isType() ) {449 output << genType( sizeofExpr->get_type(), "" );450 } else {451 sizeofExpr->get_expr()->accept( *this );452 } // if453 output << ")";454 }455 444 456 445 void CodeGenerator::visit( LogicalExpr *logicalExpr ) { -
src/CodeGen/CodeGenerator.h
r000b914 re58be8e 60 60 virtual void visit( ConstantExpr *constantExpr ); 61 61 virtual void visit( SizeofExpr *sizeofExpr ); 62 virtual void visit( AlignofExpr *alignofExpr );63 62 virtual void visit( LogicalExpr *logicalExpr ); 64 63 virtual void visit( ConditionalExpr *conditionalExpr ); -
src/GenPoly/Box.cc
r000b914 re58be8e 50 50 FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars ); 51 51 52 /// Replaces polymorphic return types with out-parameters, replaces calls to polymorphic functions with adapter calls as needed, and adds appropriate type variables to the function call53 52 class Pass1 : public PolyMutator { 54 53 public: … … 89 88 }; 90 89 91 /// Moves polymorphic returns in function types to pointer-type parameters, adds type size and assertion parameters to parameter lists as well92 90 class Pass2 : public PolyMutator { 93 91 public: … … 107 105 }; 108 106 109 /// Replaces initialization of polymorphic values with alloca, declaration of dtype/ftype with appropriate void expression, and sizeof expressions of polymorphic types with the proper variable110 107 class Pass3 : public PolyMutator { 111 108 public: … … 1012 1009 std::list< DeclarationWithType *> inferredParams; 1013 1010 ObjectDecl *newObj = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 ); 1014 // ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 );1011 /// ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 ); 1015 1012 for ( std::list< TypeDecl *>::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) { 1016 1013 ObjectDecl *thisParm; … … 1024 1021 // move all assertions into parameter list 1025 1022 for ( std::list< DeclarationWithType *>::iterator assert = (*tyParm)->get_assertions().begin(); assert != (*tyParm)->get_assertions().end(); ++assert ) { 1026 // *assert = (*assert)->acceptMutator( *this );1023 /// *assert = (*assert)->acceptMutator( *this ); 1027 1024 inferredParams.push_back( *assert ); 1028 1025 } … … 1066 1063 1067 1064 TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) { 1068 // Initializer *init = 0;1069 // std::list< Expression *> designators;1070 // scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();1071 // if ( typeDecl->get_base() ) {1072 // init = new SimpleInit( new SizeofExpr( handleDecl( typeDecl, typeDecl->get_base() ) ), designators );1073 // }1074 // return new ObjectDecl( typeDecl->get_name(), Declaration::Extern, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ), init );1065 /// Initializer *init = 0; 1066 /// std::list< Expression *> designators; 1067 /// scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind(); 1068 /// if ( typeDecl->get_base() ) { 1069 /// init = new SimpleInit( new SizeofExpr( handleDecl( typeDecl, typeDecl->get_base() ) ), designators ); 1070 /// } 1071 /// return new ObjectDecl( typeDecl->get_name(), Declaration::Extern, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ), init ); 1075 1072 1076 1073 scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind(); -
src/GenPoly/FindFunction.h
r000b914 re58be8e 23 23 typedef bool (*FindFunctionPredicate)( FunctionType*, const TyVarMap& ); 24 24 25 /// recursively walk `type`, placing all functions that match `predicate` under `tyVars` into `functions`26 25 void findFunction( Type *type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ); 27 /// like `findFunction`, but also replaces the function type with void ()(void)28 26 void findAndReplaceFunction( Type *&type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ); 29 27 } // namespace GenPoly -
src/GenPoly/GenPoly.cc
r000b914 re58be8e 21 21 22 22 namespace GenPoly { 23 // /A function needs an adapter if it returns a polymorphic value or if any of its24 // /parameters have polymorphic type23 // A function needs an adapter if it returns a polymorphic value or if any of its 24 // parameters have polymorphic type 25 25 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 26 26 if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) { -
src/GenPoly/Lvalue.cc
r000b914 re58be8e 35 35 const std::list<Label> noLabels; 36 36 37 /// Replace uses of lvalue returns with appropriate pointers38 37 class Pass1 : public Mutator { 39 38 public: … … 47 46 }; 48 47 49 /// Replace declarations of lvalue returns with appropriate pointers50 48 class Pass2 : public Visitor { 51 49 public: -
src/GenPoly/ScrubTyVars.h
r000b914 re58be8e 26 26 public: 27 27 ScrubTyVars( bool doAll, const TyVarMap &tyVars ): doAll( doAll ), tyVars( tyVars ) {} 28 29 /// Like scrub( SynTreeClass* ), but only applies to type variables in `tyVars` 28 30 29 template< typename SynTreeClass > 31 30 static SynTreeClass *scrub( SynTreeClass *target, const TyVarMap &tyVars ); 32 /// Replaces dtypes and ftypes with the appropriate void type, and sizeof expressions of polymorphic types with the proper variable33 31 template< typename SynTreeClass > 34 32 static SynTreeClass *scrub( SynTreeClass *target ); -
src/InitTweak/InitModel.h
r000b914 re58be8e 72 72 void visit( ConstantExpr * ); 73 73 void visit( SizeofExpr * ) { throw 0; } 74 void visit( AlignofExpr * ) { throw 0; }75 74 void visit( AttrExpr * ) { throw 0; } 76 75 void visit( LogicalExpr * ) { throw 0; } -
src/Parser/ExpressionNode.cc
r000b914 re58be8e 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 } // if594 }595 588 case OperatorNode::SizeOf: 596 589 { 590 /// bool isSizeOf = ( op->get_type() == OperatorNode::SizeOf ); 591 597 592 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) { 598 593 return new SizeofExpr( arg->get_decl()->buildType()); -
src/ResolvExpr/AlternativeFinder.cc
r000b914 re58be8e 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 sizeof799 AlternativeFinder finder( indexer, env );800 finder.find( alignofExpr->get_expr() );801 // find the lowest cost alternative among the alternatives, otherwise ambiguous802 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 } // if807 // return the lowest cost alternative for the argument808 Alternative &choice = winners.front();809 alternatives.push_back( Alternative( new AlignofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );810 } // if811 }812 813 794 void AlternativeFinder::resolveAttr( DeclarationWithType *funcDecl, FunctionType *function, Type *argType, const TypeEnvironment &env ) { 814 795 // assume no polymorphism -
src/ResolvExpr/AlternativeFinder.h
r000b914 re58be8e 56 56 virtual void visit( ConstantExpr *constantExpr ); 57 57 virtual void visit( SizeofExpr *sizeofExpr ); 58 virtual void visit( AlignofExpr *sizeofExpr );59 58 virtual void visit( AttrExpr *attrExpr ); 60 59 virtual void visit( LogicalExpr *logicalExpr ); -
src/SymTab/Indexer.cc
r000b914 re58be8e 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 );226 217 } 227 218 } -
src/SymTab/Indexer.h
r000b914 re58be8e 54 54 virtual void visit( ConstantExpr *constantExpr ); 55 55 virtual void visit( SizeofExpr *sizeofExpr ); 56 virtual void visit( AlignofExpr *alignofExpr );57 56 virtual void visit( AttrExpr *attrExpr ); 58 57 virtual void visit( LogicalExpr *logicalExpr ); -
src/SynTree/Expression.cc
r000b914 re58be8e 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 else128 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: ";155 124 156 125 if (isType) -
src/SynTree/Expression.h
r000b914 re58be8e 23 23 #include "Constant.h" 24 24 25 /// Expression is the root type for all expressions26 25 class Expression { 27 26 public: … … 48 47 }; 49 48 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 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 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. 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 69 70 class ApplicationExpr : public Expression { 70 71 public: … … 88 89 }; 89 90 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. 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 93 95 class UntypedExpr : public Expression { 94 96 public: … … 116 118 }; 117 119 118 // / NameExprcontains a name whose meaning is still not determined120 // this class contains a name whose meaning is still not determined 119 121 class NameExpr : public Expression { 120 122 public: … … 137 139 // function-call format. 138 140 139 // /AddressExpr represents a address-of expression, e.g. &e141 // AddressExpr represents a address-of expression, e.g. &e 140 142 class AddressExpr : public Expression { 141 143 public: … … 172 174 }; 173 175 174 // /CastExpr represents a type cast expression, e.g. (int)e176 // CastExpr represents a type cast expression, e.g. (int)e 175 177 class CastExpr : public Expression { 176 178 public: … … 191 193 }; 192 194 193 // /UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer195 // UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer 194 196 class UntypedMemberExpr : public Expression { 195 197 public: … … 212 214 }; 213 215 214 // /MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer216 // MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer 215 217 class MemberExpr : public Expression { 216 218 public: … … 233 235 }; 234 236 235 // /VariableExpr represents an expression that simply refers to the value of a named variable237 // VariableExpr represents an expression that simply refers to the value of a named variable 236 238 class VariableExpr : public Expression { 237 239 public: … … 251 253 }; 252 254 253 // /ConstantExpr represents an expression that simply refers to the value of a constant255 // ConstantExpr represents an expression that simply refers to the value of a constant 254 256 class ConstantExpr : public Expression { 255 257 public: … … 269 271 }; 270 272 271 // /SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4)273 // SizeofExpr represents a sizeof expression (could be sizeof(int) or sizeof 3+4) 272 274 class SizeofExpr : public Expression { 273 275 public: … … 294 296 }; 295 297 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) 298 // AttrExpr represents an @attribute expression (like sizeof, but user-defined) 322 299 class AttrExpr : public Expression { 323 300 public: … … 347 324 }; 348 325 349 // /LogicalExpr represents a short-circuit boolean expression (&& or ||)326 // LogicalExpr represents a short-circuit boolean expression (&& or ||) 350 327 class LogicalExpr : public Expression { 351 328 public: … … 370 347 }; 371 348 372 // /ConditionalExpr represents the three-argument conditional ( p ? a : b )349 // ConditionalExpr represents the three-argument conditional ( p ? a : b ) 373 350 class ConditionalExpr : public Expression { 374 351 public: … … 394 371 }; 395 372 396 // /CommaExpr represents the sequence operator ( a, b )373 // CommaExpr represents the sequence operator ( a, b ) 397 374 class CommaExpr : public Expression { 398 375 public: … … 415 392 }; 416 393 417 // /TupleExpr represents a tuple expression ( [a, b, c] )394 // TupleExpr represents a tuple expression ( [a, b, c] ) 418 395 class TupleExpr : public Expression { 419 396 public: … … 433 410 }; 434 411 435 // /SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on412 // SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on 436 413 class SolvedTupleExpr : public Expression { 437 414 public: … … 451 428 }; 452 429 453 // /TypeExpr represents a type used in an expression (e.g. as a type generator parameter)430 // TypeExpr represents a type used in an expression (e.g. as a type generator parameter) 454 431 class TypeExpr : public Expression { 455 432 public: … … 469 446 }; 470 447 471 // /AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result)448 // AsmExpr represents a GCC 'asm constraint operand' used in an asm statement: [output] "=f" (result) 472 449 class AsmExpr : public Expression { 473 450 public: … … 495 472 }; 496 473 497 // /ValofExpr represents a GCC 'lambda expression'474 // ValofExpr represents a GCC 'lambda expression' 498 475 class UntypedValofExpr : public Expression { 499 476 public: -
src/SynTree/Mutator.cc
r000b914 re58be8e 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 263 253 Expression *Mutator::mutate( AttrExpr *attrExpr ) { 264 254 mutateAll( attrExpr->get_results(), *this ); -
src/SynTree/Mutator.h
r000b914 re58be8e 64 64 virtual Expression* mutate( ConstantExpr *constantExpr ); 65 65 virtual Expression* mutate( SizeofExpr *sizeofExpr ); 66 virtual Expression* mutate( AlignofExpr *alignofExpr );67 66 virtual Expression* mutate( AttrExpr *attrExpr ); 68 67 virtual Expression* mutate( LogicalExpr *logicalExpr ); -
src/SynTree/SynTree.h
r000b914 re58be8e 69 69 class ConstantExpr; 70 70 class SizeofExpr; 71 class AlignofExpr;72 71 class AttrExpr; 73 72 class LogicalExpr; -
src/SynTree/Visitor.cc
r000b914 re58be8e 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 221 212 void Visitor::visit( AttrExpr *attrExpr ) { 222 213 acceptAll( attrExpr->get_results(), *this ); -
src/SynTree/Visitor.h
r000b914 re58be8e 64 64 virtual void visit( ConstantExpr *constantExpr ); 65 65 virtual void visit( SizeofExpr *sizeofExpr ); 66 virtual void visit( AlignofExpr *alignofExpr );67 66 virtual void visit( AttrExpr *attrExpr ); 68 67 virtual void visit( LogicalExpr *logicalExpr ); -
src/Tuples/FlattenTuple.cc
r000b914 re58be8e 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 ); }49 48 void FlattenTuple::CollectArgs::visit( AttrExpr *expr ) { currentArgs.insert( currentArgs.end(), expr ); } 50 49 void FlattenTuple::CollectArgs::visit( LogicalExpr *expr ) { currentArgs.insert( currentArgs.end(), expr ); } -
src/Tuples/FlattenTuple.h
r000b914 re58be8e 42 42 virtual void visit( ConstantExpr * ); 43 43 virtual void visit( SizeofExpr * ); 44 virtual void visit( AlignofExpr * );45 44 virtual void visit( AttrExpr * ); 46 45 virtual void visit( LogicalExpr * );
Note:
See TracChangeset
for help on using the changeset viewer.