Changes in / [000b914:e58be8e]


Ignore:
Location:
src
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r000b914 re58be8e  
    442442                output << ")";
    443443        }
    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         }
    455444 
    456445        void CodeGenerator::visit( LogicalExpr *logicalExpr ) {
  • src/CodeGen/CodeGenerator.h

    r000b914 re58be8e  
    6060                virtual void visit( ConstantExpr *constantExpr );
    6161                virtual void visit( SizeofExpr *sizeofExpr );
    62                 virtual void visit( AlignofExpr *alignofExpr );
    6362                virtual void visit( LogicalExpr *logicalExpr );
    6463                virtual void visit( ConditionalExpr *conditionalExpr );
  • src/GenPoly/Box.cc

    r000b914 re58be8e  
    5050                FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars );
    5151
    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 call
    5352                class Pass1 : public PolyMutator {
    5453                  public:
     
    8988                };
    9089
    91                 /// Moves polymorphic returns in function types to pointer-type parameters, adds type size and assertion parameters to parameter lists as well
    9290                class Pass2 : public PolyMutator {
    9391                  public:
     
    107105                };
    108106
    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 variable
    110107                class Pass3 : public PolyMutator {
    111108                  public:
     
    10121009                        std::list< DeclarationWithType *> inferredParams;
    10131010                        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 );
    10151012                        for ( std::list< TypeDecl *>::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) {
    10161013                                ObjectDecl *thisParm;
     
    10241021                                // move all assertions into parameter list
    10251022                                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 );
    10271024                                        inferredParams.push_back( *assert );
    10281025                                }
     
    10661063
    10671064                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 );
    10751072
    10761073                        scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
  • src/GenPoly/FindFunction.h

    r000b914 re58be8e  
    2323        typedef bool (*FindFunctionPredicate)( FunctionType*, const TyVarMap& );
    2424
    25         /// recursively walk `type`, placing all functions that match `predicate` under `tyVars` into `functions`
    2625        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)
    2826        void findAndReplaceFunction( Type *&type, std::list< FunctionType* > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate );
    2927} // namespace GenPoly
  • src/GenPoly/GenPoly.cc

    r000b914 re58be8e  
    2121
    2222namespace GenPoly {
    23         /// A function needs an adapter if it returns a polymorphic value or if any of its
    24         /// parameters have polymorphic type
     23        // A function needs an adapter if it returns a polymorphic value or if any of its
     24        // parameters have polymorphic type
    2525        bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) {
    2626                if ( ! adaptee->get_returnVals().empty() && isPolyVal( adaptee->get_returnVals().front()->get_type(), tyVars ) ) {
  • src/GenPoly/Lvalue.cc

    r000b914 re58be8e  
    3535                const std::list<Label> noLabels;
    3636
    37                 /// Replace uses of lvalue returns with appropriate pointers
    3837                class Pass1 : public Mutator {
    3938                  public:
     
    4746                };
    4847
    49                 /// Replace declarations of lvalue returns with appropriate pointers
    5048                class Pass2 : public Visitor {
    5149                  public:
  • src/GenPoly/ScrubTyVars.h

    r000b914 re58be8e  
    2626          public:
    2727                ScrubTyVars( bool doAll, const TyVarMap &tyVars ): doAll( doAll ), tyVars( tyVars ) {}
    28 
    29                 /// Like scrub( SynTreeClass* ), but only applies to type variables in `tyVars`
     28 
    3029                template< typename SynTreeClass >
    3130                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 variable
    3331                template< typename SynTreeClass >
    3432                static SynTreeClass *scrub( SynTreeClass *target );
  • src/InitTweak/InitModel.h

    r000b914 re58be8e  
    7272                        void visit( ConstantExpr * );
    7373                        void visit( SizeofExpr * ) { throw 0; }
    74                         void visit( AlignofExpr * ) { throw 0; }
    7574                        void visit( AttrExpr * ) { throw 0; }
    7675                        void visit( LogicalExpr * ) { throw 0; }
  • src/Parser/ExpressionNode.cc

    r000b914 re58be8e  
    586586                }
    587587          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                 }
    595588          case OperatorNode::SizeOf:
    596589                {
     590///     bool isSizeOf = ( op->get_type() == OperatorNode::SizeOf );
     591
    597592                        if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) {
    598593                                return new SizeofExpr( arg->get_decl()->buildType());
  • src/ResolvExpr/AlternativeFinder.cc

    r000b914 re58be8e  
    792792        }
    793793
    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 
    813794        void AlternativeFinder::resolveAttr( DeclarationWithType *funcDecl, FunctionType *function, Type *argType, const TypeEnvironment &env ) {
    814795                // assume no polymorphism
  • src/ResolvExpr/AlternativeFinder.h

    r000b914 re58be8e  
    5656                virtual void visit( ConstantExpr *constantExpr );
    5757                virtual void visit( SizeofExpr *sizeofExpr );
    58                 virtual void visit( AlignofExpr *sizeofExpr );
    5958                virtual void visit( AttrExpr *attrExpr );
    6059                virtual void visit( LogicalExpr *logicalExpr );
  • src/SymTab/Indexer.cc

    r000b914 re58be8e  
    215215                } else {
    216216                        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 );
    226217                }
    227218        }
  • src/SymTab/Indexer.h

    r000b914 re58be8e  
    5454                virtual void visit( ConstantExpr *constantExpr );
    5555                virtual void visit( SizeofExpr *sizeofExpr );
    56                 virtual void visit( AlignofExpr *alignofExpr );
    5756                virtual void visit( AttrExpr *attrExpr );
    5857                virtual void visit( LogicalExpr *logicalExpr );
  • src/SynTree/Expression.cc

    r000b914 re58be8e  
    122122void SizeofExpr::print( std::ostream &os, int indent) const {
    123123        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: ";
    155124
    156125        if (isType)
  • src/SynTree/Expression.h

    r000b914 re58be8e  
    2323#include "Constant.h"
    2424
    25 /// Expression is the root type for all expressions
    2625class Expression {
    2726  public:
     
    4847};
    4948
    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
    5252struct ParamEntry {
    5353        ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {}
     
    6565typedef std::map< UniqueId, ParamEntry > InferredParams;
    6666
    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
    6970class ApplicationExpr : public Expression {
    7071  public:
     
    8889};
    8990
    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
    9395class UntypedExpr : public Expression {
    9496  public:
     
    116118};
    117119
    118 /// NameExpr contains a name whose meaning is still not determined
     120// this class contains a name whose meaning is still not determined
    119121class NameExpr : public Expression {
    120122  public:
     
    137139// function-call format.
    138140
    139 /// AddressExpr represents a address-of expression, e.g. &e
     141// AddressExpr represents a address-of expression, e.g. &e
    140142class AddressExpr : public Expression {
    141143  public:
     
    172174};
    173175
    174 /// CastExpr represents a type cast expression, e.g. (int)e
     176// CastExpr represents a type cast expression, e.g. (int)e
    175177class CastExpr : public Expression {
    176178  public:
     
    191193};
    192194
    193 /// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
     195// UntypedMemberExpr represents a member selection operation, e.g. q.p before processing by the expression analyzer
    194196class UntypedMemberExpr : public Expression {
    195197  public:
     
    212214};
    213215
    214 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
     216// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer
    215217class MemberExpr : public Expression {
    216218  public:
     
    233235};
    234236
    235 /// VariableExpr represents an expression that simply refers to the value of a named variable
     237// VariableExpr represents an expression that simply refers to the value of a named variable
    236238class VariableExpr : public Expression {
    237239  public:
     
    251253};
    252254
    253 /// ConstantExpr represents an expression that simply refers to the value of a constant
     255// ConstantExpr represents an expression that simply refers to the value of a constant
    254256class ConstantExpr : public Expression {
    255257  public:
     
    269271};
    270272
    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)
    272274class SizeofExpr : public Expression {
    273275  public:
     
    294296};
    295297
    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)
    322299class AttrExpr : public Expression {
    323300  public:
     
    347324};
    348325
    349 /// LogicalExpr represents a short-circuit boolean expression (&& or ||)
     326// LogicalExpr represents a short-circuit boolean expression (&& or ||)
    350327class LogicalExpr : public Expression {
    351328  public:
     
    370347};
    371348
    372 /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
     349// ConditionalExpr represents the three-argument conditional ( p ? a : b )
    373350class ConditionalExpr : public Expression {
    374351  public:
     
    394371};
    395372
    396 /// CommaExpr represents the sequence operator ( a, b )
     373// CommaExpr represents the sequence operator ( a, b )
    397374class CommaExpr : public Expression {
    398375  public:
     
    415392};
    416393
    417 /// TupleExpr represents a tuple expression ( [a, b, c] )
     394// TupleExpr represents a tuple expression ( [a, b, c] )
    418395class TupleExpr : public Expression {
    419396  public:
     
    433410};
    434411
    435 /// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
     412// SolvedTupleExpr represents a TupleExpr whose components have been type-resolved. It is effectively a shell for the code generator to work on
    436413class SolvedTupleExpr : public Expression {
    437414  public:
     
    451428};
    452429
    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)
    454431class TypeExpr : public Expression {
    455432  public:
     
    469446};
    470447
    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)
    472449class AsmExpr : public Expression {
    473450  public:
     
    495472};
    496473
    497 /// ValofExpr represents a GCC 'lambda expression'
     474// ValofExpr represents a GCC 'lambda expression'
    498475class UntypedValofExpr : public Expression {
    499476  public:
  • src/SynTree/Mutator.cc

    r000b914 re58be8e  
    251251}
    252252
    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 
    263253Expression *Mutator::mutate( AttrExpr *attrExpr ) {
    264254        mutateAll( attrExpr->get_results(), *this );
  • src/SynTree/Mutator.h

    r000b914 re58be8e  
    6464        virtual Expression* mutate( ConstantExpr *constantExpr );
    6565        virtual Expression* mutate( SizeofExpr *sizeofExpr );
    66         virtual Expression* mutate( AlignofExpr *alignofExpr );
    6766        virtual Expression* mutate( AttrExpr *attrExpr );
    6867        virtual Expression* mutate( LogicalExpr *logicalExpr );
  • src/SynTree/SynTree.h

    r000b914 re58be8e  
    6969class ConstantExpr;
    7070class SizeofExpr;
    71 class AlignofExpr;
    7271class AttrExpr;
    7372class LogicalExpr;
  • src/SynTree/Visitor.cc

    r000b914 re58be8e  
    210210}
    211211
    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 
    221212void Visitor::visit( AttrExpr *attrExpr ) {
    222213        acceptAll( attrExpr->get_results(), *this );
  • src/SynTree/Visitor.h

    r000b914 re58be8e  
    6464        virtual void visit( ConstantExpr *constantExpr );
    6565        virtual void visit( SizeofExpr *sizeofExpr );
    66         virtual void visit( AlignofExpr *alignofExpr );
    6766        virtual void visit( AttrExpr *attrExpr );
    6867        virtual void visit( LogicalExpr *logicalExpr );
  • src/Tuples/FlattenTuple.cc

    r000b914 re58be8e  
    4646        void FlattenTuple::CollectArgs::visit( ConstantExpr      *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    4747        void FlattenTuple::CollectArgs::visit( SizeofExpr        *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    48         void FlattenTuple::CollectArgs::visit( AlignofExpr       *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    4948        void FlattenTuple::CollectArgs::visit( AttrExpr          *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    5049        void FlattenTuple::CollectArgs::visit( LogicalExpr       *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
  • src/Tuples/FlattenTuple.h

    r000b914 re58be8e  
    4242                        virtual void visit( ConstantExpr * );
    4343                        virtual void visit( SizeofExpr * );
    44                         virtual void visit( AlignofExpr * );
    4544                        virtual void visit( AttrExpr * );
    4645                        virtual void visit( LogicalExpr * );
Note: See TracChangeset for help on using the changeset viewer.