Changeset 37218fc for src


Ignore:
Timestamp:
Apr 11, 2016, 11:51:07 AM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, 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:
37f0da8
Parents:
3aba311 (diff), e55ca05 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

Conflicts:

src/Parser/ParseNode.h

Location:
src
Files:
7 added
1 deleted
34 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r3aba311 r37218fc  
    455455
    456456        void CodeGenerator::visit( UntypedOffsetofExpr *offsetofExpr ) {
    457                 assert( false );
     457                assert( false && "UntypedOffsetofExpr should not reach code generation" );
    458458        }
    459459
     
    464464                output << ", " << mangleName( offsetofExpr->get_member() );
    465465                output << ")";
     466        }
     467
     468        void CodeGenerator::visit( OffsetPackExpr *offsetPackExpr ) {
     469                assert( false && "OffsetPackExpr should not reach code generation" );
    466470        }
    467471 
  • src/CodeGen/CodeGenerator.h

    r3aba311 r37218fc  
    6565                virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    6666                virtual void visit( OffsetofExpr *offsetofExpr );
     67                virtual void visit( OffsetPackExpr *offsetPackExpr );
    6768                virtual void visit( LogicalExpr *logicalExpr );
    6869                virtual void visit( ConditionalExpr *conditionalExpr );
  • src/GenPoly/Box.cc

    r3aba311 r37218fc  
    3030#include "FindFunction.h"
    3131#include "ScopedMap.h"
     32#include "ScopedSet.h"
    3233#include "ScrubTyVars.h"
    3334
     
    6263                FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars );
    6364
    64                 /// Key for a unique concrete type; generic base type paired with type parameter list
    65                 struct ConcreteType {
    66                         ConcreteType() : base(NULL), params() {}
    67 
    68                         ConcreteType(AggregateDecl *_base, const std::list< Type* >& _params) : base(_base), params() { cloneAll(_params, params); }
    69 
    70                         ConcreteType(const ConcreteType& that) : base(that.base), params() { cloneAll(that.params, params); }
     65                /// Abstracts type equality for a list of parameter types
     66                struct TypeList {
     67                        TypeList() : params() {}
     68                        TypeList( const std::list< Type* > &_params ) : params() { cloneAll(_params, params); }
     69                        TypeList( std::list< Type* > &&_params ) : params( _params ) {}
     70
     71                        TypeList( const TypeList &that ) : params() { cloneAll(that.params, params); }
     72                        TypeList( TypeList &&that ) : params( std::move( that.params ) ) {}
    7173
    7274                        /// Extracts types from a list of TypeExpr*
    73                         ConcreteType(AggregateDecl *_base, const std::list< TypeExpr* >& _params) : base(_base), params() {
     75                        TypeList( const std::list< TypeExpr* >& _params ) : params() {
    7476                                for ( std::list< TypeExpr* >::const_iterator param = _params.begin(); param != _params.end(); ++param ) {
    7577                                        params.push_back( (*param)->get_type()->clone() );
     
    7779                        }
    7880
    79                         ConcreteType& operator= (const ConcreteType& that) {
     81                        TypeList& operator= ( const TypeList &that ) {
    8082                                deleteAll( params );
     83
    8184                                params.clear();
    82 
    83                                 base = that.base;
    8485                                cloneAll( that.params, params );
    8586
     
    8788                        }
    8889
    89                         ~ConcreteType() { deleteAll( params ); }
    90 
    91                         bool operator== (const ConcreteType& that) const {
    92                                 if ( base != that.base ) return false;
     90                        TypeList& operator= ( TypeList &&that ) {
     91                                deleteAll( params );
     92
     93                                params = std::move( that.params );
     94
     95                                return *this;
     96                        }
     97
     98                        ~TypeList() { deleteAll( params ); }
     99
     100                        bool operator== ( const TypeList& that ) const {
     101                                if ( params.size() != that.params.size() ) return false;
    93102
    94103                                SymTab::Indexer dummy;
    95                                 if ( params.size() != that.params.size() ) return false;
    96104                                for ( std::list< Type* >::const_iterator it = params.begin(), jt = that.params.begin(); it != params.end(); ++it, ++jt ) {
    97105                                        if ( ! ResolvExpr::typesCompatible( *it, *jt, dummy ) ) return false;
     
    100108                        }
    101109
    102                         AggregateDecl *base;        ///< Base generic type
    103110                        std::list< Type* > params;  ///< Instantiation parameters
    104111                };
    105112
    106                 /// Maps a concrete type to the some value, accounting for scope
    107                 template< typename Value >
     113                /// Maps a key and a TypeList to the some value, accounting for scope
     114                template< typename Key, typename Value >
    108115                class InstantiationMap {
    109                         /// Information about a specific instantiation of a generic type
    110                         struct Instantiation {
    111                                 ConcreteType key;  ///< Instantiation parameters for this type
    112                                 Value *value;      ///< Value for this instantiation
    113 
    114                                 Instantiation() : key(), value(0) {}
    115                                 Instantiation(const ConcreteType &_key, Value *_value) : key(_key), value(_value) {}
    116                         };
    117                         /// Map of generic types to instantiations of them
    118                         typedef std::map< AggregateDecl*, std::vector< Instantiation > > Scope;
    119 
    120                         std::vector< Scope > scopes;  ///< list of scopes, from outermost to innermost
     116                        /// Wraps value for a specific (Key, TypeList) combination
     117                        typedef std::pair< TypeList, Value* > Instantiation;
     118                        /// List of TypeLists paired with their appropriate values
     119                        typedef std::vector< Instantiation > ValueList;
     120                        /// Underlying map type; maps keys to a linear list of corresponding TypeLists and values
     121                        typedef ScopedMap< Key*, ValueList > InnerMap;
     122
     123                        InnerMap instantiations;  ///< instantiations
    121124
    122125                public:
    123126                        /// Starts a new scope
    124                         void beginScope() {
    125                                 Scope scope;
    126                                 scopes.push_back(scope);
    127                         }
     127                        void beginScope() { instantiations.beginScope(); }
    128128
    129129                        /// Ends a scope
    130                         void endScope() {
    131                                 scopes.pop_back();
    132                         }
    133 
    134                         /// Default constructor initializes with one scope
    135                         InstantiationMap() { beginScope(); }
    136 
    137 //              private:
    138                         /// Gets the value for the concrete instantiation of this type, assuming it has already been instantiated in the current scope.
    139                         /// Returns NULL on none such.
    140                         Value *lookup( AggregateDecl *generic, const std::list< TypeExpr* >& params ) {
    141                                 ConcreteType key(generic, params);
    142                                 // scan scopes from innermost out
    143                                 for ( typename std::vector< Scope >::const_reverse_iterator scope = scopes.rbegin(); scope != scopes.rend(); ++scope ) {
    144                                         // skip scope if no instantiations of this generic type
    145                                         typename Scope::const_iterator insts = scope->find( generic );
    146                                         if ( insts == scope->end() ) continue;
    147                                         // look through instantiations for matches to concrete type
    148                                         for ( typename std::vector< Instantiation >::const_iterator inst = insts->second.begin(); inst != insts->second.end(); ++inst ) {
    149                                                 if ( inst->key == key ) return inst->value;
     130                        void endScope() { instantiations.endScope(); }
     131
     132                        /// Gets the value for the (key, typeList) pair, returns NULL on none such.
     133                        Value *lookup( Key *key, const std::list< TypeExpr* >& params ) const {
     134                                TypeList typeList( params );
     135                               
     136                                // scan scopes for matches to the key
     137                                for ( typename InnerMap::const_iterator insts = instantiations.find( key ); insts != instantiations.end(); insts = instantiations.findNext( insts, key ) ) {
     138                                        for ( typename ValueList::const_reverse_iterator inst = insts->second.rbegin(); inst != insts->second.rend(); ++inst ) {
     139                                                if ( inst->first == typeList ) return inst->second;
    150140                                        }
    151141                                }
    152                                 // no matching instantiation found
     142                                // no matching instantiations found
    153143                                return 0;
    154144                        }
    155                 public:
    156 //                      StructDecl* lookup( StructInstType *inst, const std::list< TypeExpr* > &typeSubs ) { return (StructDecl*)lookup( inst->get_baseStruct(), typeSubs ); }
    157 //                      UnionDecl* lookup( UnionInstType *inst, const std::list< TypeExpr* > &typeSubs ) { return (UnionDecl*)lookup( inst->get_baseUnion(), typeSubs ); }
    158 
    159 //              private:
    160                         /// Adds a value for a concrete type to the current scope
    161                         void insert( AggregateDecl *generic, const std::list< TypeExpr* > &params, Value *value ) {
    162                                 ConcreteType key(generic, params);
    163                                 scopes.back()[generic].push_back( Instantiation( key, value ) );
    164                         }
    165 //              public:
    166 //                      void insert( StructInstType *inst, const std::list< TypeExpr* > &typeSubs, StructDecl *decl ) { insert( inst->get_baseStruct(), typeSubs, decl ); }
    167 //                      void insert( UnionInstType *inst, const std::list< TypeExpr* > &typeSubs, UnionDecl *decl ) { insert( inst->get_baseUnion(), typeSubs, decl ); }
     145
     146                        /// Adds a value for a (key, typeList) pair to the current scope
     147                        void insert( Key *key, const std::list< TypeExpr* > &params, Value *value ) {
     148                                instantiations[ key ].push_back( Instantiation( TypeList( params ), value ) );
     149                        }
    168150                };
    169151
     
    197179                        virtual void doEndScope();
    198180                  private:
    199                         /// Makes a new temporary array holding the offsets of the fields of `type`, and returns a new variable expression referencing it
    200                         Expression *makeOffsetArray( StructInstType *type );
    201181                        /// Pass the extra type parameters from polymorphic generic arguments or return types into a function application
    202182                        void passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes );
     
    225205                        ObjectDecl *makeTemporary( Type *type );
    226206
    227                         std::map< std::string, DeclarationWithType *> assignOps;
    228                         ResolvExpr::TypeMap< DeclarationWithType > scopedAssignOps;
    229                         ScopedMap< std::string, DeclarationWithType* > adapters;
     207                        std::map< std::string, DeclarationWithType *> assignOps;     ///< Currently known type variable assignment operators
     208                        ResolvExpr::TypeMap< DeclarationWithType > scopedAssignOps;  ///< Currently known assignment operators
     209                        ScopedMap< std::string, DeclarationWithType* > adapters;     ///< Set of adapter functions in the current scope
     210                       
    230211                        DeclarationWithType *retval;
    231212                        bool useRetval;
     
    233214                };
    234215
    235                 /// Moves polymorphic returns in function types to pointer-type parameters, adds type size and assertion parameters to parameter lists as well
     216                /// * Moves polymorphic returns in function types to pointer-type parameters
     217                /// * adds type size and assertion parameters to parameter lists
    236218                class Pass2 : public PolyMutator {
    237219                  public:
     
    244226                        virtual Type *mutate( PointerType *pointerType );
    245227                        virtual Type *mutate( FunctionType *funcType );
     228                       
    246229                  private:
    247230                        void addAdapters( FunctionType *functionType );
     
    253236                class GenericInstantiator : public DeclMutator {
    254237                        /// Map of (generic type, parameter list) pairs to concrete type instantiations
    255                         InstantiationMap< AggregateDecl > instantiations;
     238                        InstantiationMap< AggregateDecl, AggregateDecl > instantiations;
    256239                        /// Namer for concrete types
    257240                        UniqueName typeNamer;
     
    278261                };
    279262
    280                 /// Replaces member expressions for polymorphic types with calculated add-field-offset-and-dereference;
    281                 /// also fixes offsetof expressions.
    282                 class MemberExprFixer : public PolyMutator {
    283                   public:
     263                /// Replaces member and size/align/offsetof expressions on polymorphic generic types with calculated expressions.
     264                /// * Replaces member expressions for polymorphic types with calculated add-field-offset-and-dereference
     265                /// * Calculates polymorphic offsetof expressions from offset array
     266                /// * Inserts dynamic calculation of polymorphic type layouts where needed
     267                class PolyGenericCalculator : public PolyMutator {
     268                public:
    284269                        template< typename DeclClass >
    285270                        DeclClass *handleDecl( DeclClass *decl, Type *type );
     
    292277                        virtual Type *mutate( FunctionType *funcType );
    293278                        virtual Expression *mutate( MemberExpr *memberExpr );
     279                        virtual Expression *mutate( SizeofExpr *sizeofExpr );
     280                        virtual Expression *mutate( AlignofExpr *alignofExpr );
    294281                        virtual Expression *mutate( OffsetofExpr *offsetofExpr );
     282                        virtual Expression *mutate( OffsetPackExpr *offsetPackExpr );
     283
     284                        virtual void doBeginScope();
     285                        virtual void doEndScope();
     286
     287                private:
     288                        /// Makes a new variable in the current scope with the given name, type & optional initializer
     289                        ObjectDecl *makeVar( const std::string &name, Type *type, Initializer *init = 0 );
     290                        /// returns true if the type has a dynamic layout; such a layout will be stored in appropriately-named local variables when the function returns
     291                        bool findGeneric( Type *ty );
     292                        /// adds type parameters to the layout call; will generate the appropriate parameters if needed
     293                        void addOtypeParamsToLayoutCall( UntypedExpr *layoutCall, const std::list< Type* > &otypeParams );
     294                       
     295                        ScopedSet< std::string > knownLayouts;          ///< Set of generic type layouts known in the current scope, indexed by sizeofName
     296                        ScopedSet< std::string > knownOffsets;          ///< Set of non-generic types for which the offset array exists in the current scope, indexed by offsetofName
    295297                };
    296298
     
    342344                Pass2 pass2;
    343345                GenericInstantiator instantiator;
    344                 MemberExprFixer memberFixer;
     346                PolyGenericCalculator polyCalculator;
    345347                Pass3 pass3;
    346348               
     
    348350                mutateTranslationUnit/*All*/( translationUnit, pass1 );
    349351                mutateTranslationUnit/*All*/( translationUnit, pass2 );
    350 //              instantiateGeneric( translationUnit );
    351352                instantiator.mutateDeclarationList( translationUnit );
    352                 mutateTranslationUnit/*All*/( translationUnit, memberFixer );
     353                mutateTranslationUnit/*All*/( translationUnit, polyCalculator );
    353354                mutateTranslationUnit/*All*/( translationUnit, pass3 );
    354355        }
     
    653654
    654655                DeclarationWithType *Pass1::mutate( FunctionDecl *functionDecl ) {
    655                         // if this is a polymorphic assignment function, put it in the map for this scope
     656                        // if this is a assignment function, put it in the map for this scope
    656657                        if ( Type *assignedType = isAssignment( functionDecl ) ) {
    657658                                if ( ! dynamic_cast< TypeInstType* >( assignedType ) ) {
     
    743744                }
    744745
    745                 Expression *Pass1::makeOffsetArray( StructInstType *ty ) {
    746                         std::list< Declaration* > &baseMembers = ty->get_baseStruct()->get_members();
    747 
    748                         // make a new temporary array
    749                         Type *offsetType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
    750                         std::stringstream lenGen;
    751                         lenGen << baseMembers.size();
    752                         ConstantExpr *lenExpr = new ConstantExpr( Constant( offsetType->clone(), lenGen.str() ) );
    753                         ObjectDecl *arrayTemp = makeTemporary( new ArrayType( Type::Qualifiers(), offsetType, lenExpr, false, false ) );
    754 
    755                         // build initializer list for temporary
    756                         std::list< Initializer* > inits;
    757                         for ( std::list< Declaration* >::const_iterator member = baseMembers.begin(); member != baseMembers.end(); ++member ) {
    758                                 DeclarationWithType *memberDecl;
    759                                 if ( DeclarationWithType *origMember = dynamic_cast< DeclarationWithType* >( *member ) ) {
    760                                         memberDecl = origMember->clone();
    761                                 } else {
    762                                         memberDecl = new ObjectDecl( (*member)->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, offsetType->clone(), 0 );
    763                                 }
    764                                 inits.push_back( new SingleInit( new OffsetofExpr( ty->clone(), memberDecl ) ) );
    765                         }
    766                         arrayTemp->set_init( new ListInit( inits ) );
    767 
    768                         // return variable pointing to temporary
    769                         return new VariableExpr( arrayTemp );
    770                 }
    771 
    772746                void Pass1::passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes ) {
    773747                        Type *polyBase = hasPolyBase( parmType, exprTyVars );
     
    782756                                if ( dynamic_cast< StructInstType* >( polyBase ) ) {
    783757                                        if ( StructInstType *argBaseStructType = dynamic_cast< StructInstType* >( argBaseType ) ) {
    784                                                 arg = appExpr->get_args().insert( arg, makeOffsetArray( argBaseStructType ) );
    785                                                 arg++;
     758                                                // zero-length arrays are forbidden by C, so don't pass offset for empty struct
     759                                                if ( ! argBaseStructType->get_baseStruct()->get_members().empty() ) {
     760                                                        arg = appExpr->get_args().insert( arg, new OffsetPackExpr( argBaseStructType->clone() ) );
     761                                                        arg++;
     762                                                }
    786763                                        } else {
    787764                                                throw SemanticError( "Cannot pass non-struct type for generic struct" );
     
    931908                                        return;
    932909                                } else if ( arg->get_results().front()->get_isLvalue() ) {
    933                                         // VariableExpr and MemberExpr are lvalues
    934                                         arg = new AddressExpr( arg );
     910                                        // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue)
     911                                        if ( CommaExpr *commaArg = dynamic_cast< CommaExpr* >( arg ) ) {
     912                                                commaArg->set_arg2( new AddressExpr( commaArg->get_arg2() ) );
     913                                        } else {
     914                                                arg = new AddressExpr( arg );
     915                                        }
    935916                                } else {
    936917                                        // use type computed in unification to declare boxed variables
     
    10271008                        } // for
    10281009                }
    1029 
    1030 
    10311010
    10321011                FunctionDecl *Pass1::makeAdapter( FunctionType *adaptee, FunctionType *realType, const std::string &mangleName, const TyVarMap &tyVars ) {
     
    14281407                                        std::list< TypeDecl* >::const_iterator forallIt = forallParams.begin();
    14291408                                        for ( ; tyIt != tyParams.end() && forallIt != forallParams.end(); ++tyIt, ++forallIt ) {
    1430                                                 if ( (*forallIt)->get_kind() != TypeDecl::Any ) continue; // skip types with no assign op (ftype/dtype)
    1431 
    1432                                                 std::list< DeclarationWithType* > &asserts = (*forallIt)->get_assertions();
    1433                                                 assert( ! asserts.empty() && "Type param needs assignment operator assertion" );
    1434                                                 DeclarationWithType *actualDecl = asserts.front();
    1435                                                 TypeInstType *actualType = isTypeInstAssignment( actualDecl );
    1436                                                 assert( actualType && "First assertion of type with assertions should be assignment operator" );
     1409                                                // Add appropriate mapping to assignment expression environment
    14371410                                                TypeExpr *formalTypeExpr = dynamic_cast< TypeExpr* >( *tyIt );
    14381411                                                assert( formalTypeExpr && "type parameters must be type expressions" );
    14391412                                                Type *formalType = formalTypeExpr->get_type();
    1440                                                 assignExpr->get_env()->add( actualType->get_name(), formalType );
    1441                                                
     1413                                                assignExpr->get_env()->add( (*forallIt)->get_name(), formalType );
     1414
     1415                                                // skip types with no assign op (ftype/dtype)
     1416                                                if ( (*forallIt)->get_kind() != TypeDecl::Any ) continue;
     1417
     1418                                                // find assignment operator for formal type
    14421419                                                DeclarationWithType *assertAssign = 0;
    14431420                                                if ( TypeInstType *formalTypeInstType = dynamic_cast< TypeInstType* >( formalType ) ) {
     
    14531430                                                        }
    14541431                                                }
    1455                                                
    1456 
     1432
     1433                                                // add inferred parameter for field assignment operator to assignment expression
     1434                                                std::list< DeclarationWithType* > &asserts = (*forallIt)->get_assertions();
     1435                                                assert( ! asserts.empty() && "Type param needs assignment operator assertion" );
     1436                                                DeclarationWithType *actualDecl = asserts.front();
    14571437                                                assignExpr->get_inferParams()[ actualDecl->get_uniqueId() ]
    14581438                                                        = ParamEntry( assertAssign->get_uniqueId(), assertAssign->get_type()->clone(), actualDecl->get_type()->clone(), wrapFunctionDecl( assertAssign ) );
     
    15871567                        ObjectDecl newPtr( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0,
    15881568                                           new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 );
    1589 //   ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 );
    15901569                        for ( std::list< TypeDecl *>::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) {
    15911570                                ObjectDecl *sizeParm, *alignParm;
     
    16311610                                        ++last;
    16321611
    1633                                         if ( dynamic_cast< StructInstType* >( polyBase ) ) {
    1634                                                 offsetParm = newPtr.clone();
    1635                                                 offsetParm->set_name( offsetofName( polyBase ) );
    1636                                                 last = funcType->get_parameters().insert( last, offsetParm );
    1637                                                 ++last;
     1612                                        if ( StructInstType *polyBaseStruct = dynamic_cast< StructInstType* >( polyBase ) ) {
     1613                                                // NOTE zero-length arrays are illegal in C, so empty structs have no offset array
     1614                                                if ( ! polyBaseStruct->get_baseStruct()->get_members().empty() ) {
     1615                                                        offsetParm = newPtr.clone();
     1616                                                        offsetParm->set_name( offsetofName( polyBase ) );
     1617                                                        last = funcType->get_parameters().insert( last, offsetParm );
     1618                                                        ++last;
     1619                                                }
    16381620                                        }
    16391621
     
    18441826
    18451827                template< typename DeclClass >
    1846                 DeclClass * MemberExprFixer::handleDecl( DeclClass *decl, Type *type ) {
     1828                DeclClass * PolyGenericCalculator::handleDecl( DeclClass *decl, Type *type ) {
    18471829                        TyVarMap oldtyVars = scopeTyVars;
    18481830                        makeTyVarMap( type, scopeTyVars );
     
    18541836                }
    18551837
    1856                 ObjectDecl * MemberExprFixer::mutate( ObjectDecl *objectDecl ) {
     1838                ObjectDecl * PolyGenericCalculator::mutate( ObjectDecl *objectDecl ) {
    18571839                        return handleDecl( objectDecl, objectDecl->get_type() );
    18581840                }
    18591841
    1860                 DeclarationWithType * MemberExprFixer::mutate( FunctionDecl *functionDecl ) {
     1842                DeclarationWithType * PolyGenericCalculator::mutate( FunctionDecl *functionDecl ) {
    18611843                        return handleDecl( functionDecl, functionDecl->get_functionType() );
    18621844                }
    18631845
    1864                 TypedefDecl * MemberExprFixer::mutate( TypedefDecl *typedefDecl ) {
     1846                TypedefDecl * PolyGenericCalculator::mutate( TypedefDecl *typedefDecl ) {
    18651847                        return handleDecl( typedefDecl, typedefDecl->get_base() );
    18661848                }
    18671849
    1868                 TypeDecl * MemberExprFixer::mutate( TypeDecl *typeDecl ) {
     1850                TypeDecl * PolyGenericCalculator::mutate( TypeDecl *typeDecl ) {
    18691851                        scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind();
    18701852                        return Mutator::mutate( typeDecl );
    18711853                }
    18721854
    1873                 Type * MemberExprFixer::mutate( PointerType *pointerType ) {
     1855                Type * PolyGenericCalculator::mutate( PointerType *pointerType ) {
    18741856                        TyVarMap oldtyVars = scopeTyVars;
    18751857                        makeTyVarMap( pointerType, scopeTyVars );
     
    18811863                }
    18821864
    1883                 Type * MemberExprFixer::mutate( FunctionType *functionType ) {
     1865                Type * PolyGenericCalculator::mutate( FunctionType *funcType ) {
    18841866                        TyVarMap oldtyVars = scopeTyVars;
    1885                         makeTyVarMap( functionType, scopeTyVars );
    1886 
    1887                         Type *ret = Mutator::mutate( functionType );
     1867                        makeTyVarMap( funcType, scopeTyVars );
     1868
     1869                        // make sure that any type information passed into the function is accounted for
     1870                        for ( std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin(); fnParm != funcType->get_parameters().end(); ++fnParm ) {
     1871                                // condition here duplicates that in Pass2::mutate( FunctionType* )
     1872                                Type *polyBase = hasPolyBase( (*fnParm)->get_type(), scopeTyVars );
     1873                                if ( polyBase && ! dynamic_cast< TypeInstType* >( polyBase ) ) {
     1874                                        knownLayouts.insert( sizeofName( polyBase ) );
     1875                                }
     1876                        }
     1877                       
     1878                        Type *ret = Mutator::mutate( funcType );
    18881879
    18891880                        scopeTyVars = oldtyVars;
     
    18911882                }
    18921883
    1893                 Statement *MemberExprFixer::mutate( DeclStmt *declStmt ) {
     1884                Statement *PolyGenericCalculator::mutate( DeclStmt *declStmt ) {
    18941885                        if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) {
    1895                                 if ( isPolyType( objectDecl->get_type(), scopeTyVars ) ) {
     1886                                if ( findGeneric( objectDecl->get_type() ) ) {
    18961887                                        // change initialization of a polymorphic value object
    18971888                                        // to allocate storage with alloca
     
    19451936                }
    19461937               
    1947                 Expression *MemberExprFixer::mutate( MemberExpr *memberExpr ) {
     1938                Expression *PolyGenericCalculator::mutate( MemberExpr *memberExpr ) {
    19481939                        // mutate, exiting early if no longer MemberExpr
    19491940                        Expression *expr = Mutator::mutate( memberExpr );
     
    19621953                        Type *objectType = hasPolyBase( objectDecl->get_type(), scopeTyVars, &tyDepth );
    19631954                        if ( ! objectType ) return memberExpr;
     1955                        findGeneric( objectType ); // ensure layout for this type is available
    19641956
    19651957                        Expression *newMemberExpr = 0;
     
    19931985                }
    19941986
    1995                 Expression *MemberExprFixer::mutate( OffsetofExpr *offsetofExpr ) {
     1987                ObjectDecl *PolyGenericCalculator::makeVar( const std::string &name, Type *type, Initializer *init ) {
     1988                        ObjectDecl *newObj = new ObjectDecl( name, DeclarationNode::NoStorageClass, LinkageSpec::C, 0, type, init );
     1989                        stmtsToAdd.push_back( new DeclStmt( noLabels, newObj ) );
     1990                        return newObj;
     1991                }
     1992
     1993                void PolyGenericCalculator::addOtypeParamsToLayoutCall( UntypedExpr *layoutCall, const std::list< Type* > &otypeParams ) {
     1994                        for ( std::list< Type* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) {
     1995                                if ( findGeneric( *param ) ) {
     1996                                        // push size/align vars for a generic parameter back
     1997                                        layoutCall->get_args().push_back( new NameExpr( sizeofName( *param ) ) );
     1998                                        layoutCall->get_args().push_back( new NameExpr( alignofName( *param ) ) );
     1999                                } else {
     2000                                        layoutCall->get_args().push_back( new SizeofExpr( (*param)->clone() ) );
     2001                                        layoutCall->get_args().push_back( new AlignofExpr( (*param)->clone() ) );
     2002                                }
     2003                        }
     2004                }
     2005
     2006                /// returns true if any of the otype parameters have a dynamic layout and puts all otype parameters in the output list
     2007                bool findGenericParams( std::list< TypeDecl* > &baseParams, std::list< Expression* > &typeParams, std::list< Type* > &out ) {
     2008                        bool hasDynamicLayout = false;
     2009
     2010                        std::list< TypeDecl* >::const_iterator baseParam = baseParams.begin();
     2011                        std::list< Expression* >::const_iterator typeParam = typeParams.begin();
     2012                        for ( ; baseParam != baseParams.end() && typeParam != typeParams.end(); ++baseParam, ++typeParam ) {
     2013                                // skip non-otype parameters
     2014                                if ( (*baseParam)->get_kind() != TypeDecl::Any ) continue;
     2015                                TypeExpr *typeExpr = dynamic_cast< TypeExpr* >( *typeParam );
     2016                                assert( typeExpr && "all otype parameters should be type expressions" );
     2017
     2018                                Type *type = typeExpr->get_type();
     2019                                out.push_back( type );
     2020                                if ( isPolyType( type ) ) hasDynamicLayout = true;
     2021                        }
     2022                        assert( baseParam == baseParams.end() && typeParam == typeParams.end() );
     2023
     2024                        return hasDynamicLayout;
     2025                }
     2026
     2027                bool PolyGenericCalculator::findGeneric( Type *ty ) {
     2028                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( ty ) ) {
     2029                                // duplicate logic from isPolyType()
     2030                                if ( env ) {
     2031                                        if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
     2032                                                return findGeneric( newType );
     2033                                        } // if
     2034                                } // if
     2035                                if ( scopeTyVars.find( typeInst->get_name() ) != scopeTyVars.end() ) {
     2036                                        // NOTE assumes here that getting put in the scopeTyVars included having the layout variables set
     2037                                        return true;
     2038                                }
     2039                                return false;
     2040                        } else if ( StructInstType *structTy = dynamic_cast< StructInstType* >( ty ) ) {
     2041                                // check if this type already has a layout generated for it
     2042                                std::string sizeName = sizeofName( ty );
     2043                                if ( knownLayouts.find( sizeName ) != knownLayouts.end() ) return true;
     2044
     2045                                // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized
     2046                                std::list< Type* > otypeParams;
     2047                                if ( ! findGenericParams( *structTy->get_baseParameters(), structTy->get_parameters(), otypeParams ) ) return false;
     2048
     2049                                // insert local variables for layout and generate call to layout function
     2050                                knownLayouts.insert( sizeName );  // done early so as not to interfere with the later addition of parameters to the layout call
     2051                                Type *layoutType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
     2052
     2053                                int n_members = structTy->get_baseStruct()->get_members().size();
     2054                                if ( n_members == 0 ) {
     2055                                        // all empty structs have the same layout - size 1, align 1
     2056                                        makeVar( sizeName, layoutType, new SingleInit( new ConstantExpr( Constant::from( (unsigned long)1 ) ) ) );
     2057                                        makeVar( alignofName( ty ), layoutType->clone(), new SingleInit( new ConstantExpr( Constant::from( (unsigned long)1 ) ) ) );
     2058                                        // NOTE zero-length arrays are forbidden in C, so empty structs have no offsetof array
     2059                                } else {
     2060                                        ObjectDecl *sizeVar = makeVar( sizeName, layoutType );
     2061                                        ObjectDecl *alignVar = makeVar( alignofName( ty ), layoutType->clone() );
     2062                                        ObjectDecl *offsetVar = makeVar( offsetofName( ty ), new ArrayType( Type::Qualifiers(), layoutType->clone(), new ConstantExpr( Constant::from( n_members ) ), false, false ) );
     2063
     2064                                        // generate call to layout function
     2065                                        UntypedExpr *layoutCall = new UntypedExpr( new NameExpr( "__layoutof_" + structTy->get_baseStruct()->get_name() ) );
     2066                                        layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( sizeVar ) ) );
     2067                                        layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( alignVar ) ) );
     2068                                        layoutCall->get_args().push_back( new VariableExpr( offsetVar ) );
     2069                                        addOtypeParamsToLayoutCall( layoutCall, otypeParams );
     2070
     2071                                        stmtsToAdd.push_back( new ExprStmt( noLabels, layoutCall ) );
     2072                                }
     2073
     2074                                return true;
     2075                        } else if ( UnionInstType *unionTy = dynamic_cast< UnionInstType* >( ty ) ) {
     2076                                // check if this type already has a layout generated for it
     2077                                std::string sizeName = sizeofName( ty );
     2078                                if ( knownLayouts.find( sizeName ) != knownLayouts.end() ) return true;
     2079
     2080                                // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized
     2081                                std::list< Type* > otypeParams;
     2082                                if ( ! findGenericParams( *unionTy->get_baseParameters(), unionTy->get_parameters(), otypeParams ) ) return false;
     2083
     2084                                // insert local variables for layout and generate call to layout function
     2085                                knownLayouts.insert( sizeName );  // done early so as not to interfere with the later addition of parameters to the layout call
     2086                                Type *layoutType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
     2087
     2088                                ObjectDecl *sizeVar = makeVar( sizeName, layoutType );
     2089                                ObjectDecl *alignVar = makeVar( alignofName( ty ), layoutType->clone() );
     2090
     2091                                // generate call to layout function
     2092                                UntypedExpr *layoutCall = new UntypedExpr( new NameExpr( "__layoutof_" + unionTy->get_baseUnion()->get_name() ) );
     2093                                layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( sizeVar ) ) );
     2094                                layoutCall->get_args().push_back( new AddressExpr( new VariableExpr( alignVar ) ) );
     2095                                addOtypeParamsToLayoutCall( layoutCall, otypeParams );
     2096
     2097                                stmtsToAdd.push_back( new ExprStmt( noLabels, layoutCall ) );
     2098
     2099                                return true;
     2100                        }
     2101
     2102                        return false;
     2103                }
     2104
     2105                Expression *PolyGenericCalculator::mutate( SizeofExpr *sizeofExpr ) {
     2106                        Type *ty = sizeofExpr->get_type();
     2107                        if ( findGeneric( ty ) ) {
     2108                                Expression *ret = new NameExpr( sizeofName( ty ) );
     2109                                delete sizeofExpr;
     2110                                return ret;
     2111                        }
     2112                        return sizeofExpr;
     2113                }
     2114
     2115                Expression *PolyGenericCalculator::mutate( AlignofExpr *alignofExpr ) {
     2116                        Type *ty = alignofExpr->get_type();
     2117                        if ( findGeneric( ty ) ) {
     2118                                Expression *ret = new NameExpr( alignofName( ty ) );
     2119                                delete alignofExpr;
     2120                                return ret;
     2121                        }
     2122                        return alignofExpr;
     2123                }
     2124
     2125                Expression *PolyGenericCalculator::mutate( OffsetofExpr *offsetofExpr ) {
    19962126                        // mutate, exiting early if no longer OffsetofExpr
    19972127                        Expression *expr = Mutator::mutate( offsetofExpr );
     
    20002130
    20012131                        // only mutate expressions for polymorphic structs/unions
    2002                         Type *ty = isPolyType( offsetofExpr->get_type(), scopeTyVars );
    2003                         if ( ! ty ) return offsetofExpr;
    2004 
     2132                        Type *ty = offsetofExpr->get_type();
     2133                        if ( ! findGeneric( ty ) ) return offsetofExpr;
     2134                       
    20052135                        if ( StructInstType *structType = dynamic_cast< StructInstType* >( ty ) ) {
    20062136                                // replace offsetof expression by index into offset array
     
    20182148                }
    20192149
     2150                Expression *PolyGenericCalculator::mutate( OffsetPackExpr *offsetPackExpr ) {
     2151                        StructInstType *ty = offsetPackExpr->get_type();
     2152
     2153                        Expression *ret = 0;
     2154                        if ( findGeneric( ty ) ) {
     2155                                // pull offset back from generated type information
     2156                                ret = new NameExpr( offsetofName( ty ) );
     2157                        } else {
     2158                                std::string offsetName = offsetofName( ty );
     2159                                if ( knownOffsets.find( offsetName ) != knownOffsets.end() ) {
     2160                                        // use the already-generated offsets for this type
     2161                                        ret = new NameExpr( offsetName );
     2162                                } else {
     2163                                        knownOffsets.insert( offsetName );
     2164
     2165                                        std::list< Declaration* > &baseMembers = ty->get_baseStruct()->get_members();
     2166                                        Type *offsetType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
     2167
     2168                                        // build initializer list for offset array
     2169                                        std::list< Initializer* > inits;
     2170                                        for ( std::list< Declaration* >::const_iterator member = baseMembers.begin(); member != baseMembers.end(); ++member ) {
     2171                                                DeclarationWithType *memberDecl;
     2172                                                if ( DeclarationWithType *origMember = dynamic_cast< DeclarationWithType* >( *member ) ) {
     2173                                                        memberDecl = origMember->clone();
     2174                                                } else {
     2175                                                        memberDecl = new ObjectDecl( (*member)->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, offsetType->clone(), 0 );
     2176                                                }
     2177                                                inits.push_back( new SingleInit( new OffsetofExpr( ty->clone(), memberDecl ) ) );
     2178                                        }
     2179
     2180                                        // build the offset array and replace the pack with a reference to it
     2181                                        ObjectDecl *offsetArray = makeVar( offsetName, new ArrayType( Type::Qualifiers(), offsetType, new ConstantExpr( Constant::from( baseMembers.size() ) ), false, false ),
     2182                                                        new ListInit( inits ) );
     2183                                        ret = new VariableExpr( offsetArray );
     2184                                }
     2185                        }
     2186
     2187                        delete offsetPackExpr;
     2188                        return ret;
     2189                }
     2190
     2191                void PolyGenericCalculator::doBeginScope() {
     2192                        knownLayouts.beginScope();
     2193                        knownOffsets.beginScope();
     2194                }
     2195
     2196                void PolyGenericCalculator::doEndScope() {
     2197                        knownLayouts.endScope();
     2198                        knownOffsets.beginScope();
     2199                }
     2200
    20202201////////////////////////////////////////// Pass3 ////////////////////////////////////////////////////
    20212202
  • src/GenPoly/ScopedMap.h

    r3aba311 r37218fc  
    1717#define _SCOPEDMAP_H
    1818
     19#include <cassert>
    1920#include <iterator>
    2021#include <map>
     
    164165                void endScope() {
    165166                        scopes.pop_back();
     167                        assert( ! scopes.empty() );
    166168                }
    167169
     
    188190                        return end();
    189191                }
    190                 const_iterator find( const Key &key ) const { return const_iterator( find( key ) ); }
     192                const_iterator find( const Key &key ) const {
     193                                return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->find( key ) );
     194                }
    191195               
    192196                /// Finds the given key in the outermost scope inside the given scope where it occurs
     
    200204                        return end();
    201205                }
    202                 const_iterator findNext( const_iterator &it, const Key &key ) const { return const_iterator( findNext( it, key ) ); }
     206                const_iterator findNext( const_iterator &it, const Key &key ) const {
     207                                return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->findNext( it, key ) );
     208                }
    203209
    204210                /// Inserts the given key-value pair into the outermost scope
     
    208214                }
    209215                std::pair< iterator, bool > insert( const Key &key, const Value &value ) { return insert( std::make_pair( key, value ) ); }
    210                
     216
     217                Value& operator[] ( const Key &key ) {
     218                        iterator slot = find( key );
     219                        if ( slot != end() ) return slot->second;
     220                        return insert( key, Value() ).first->second;
     221                }
    211222        };
    212223} // namespace GenPoly
  • src/InitTweak/InitModel.h

    r3aba311 r37218fc  
    7575                        void visit( UntypedOffsetofExpr * ) { throw 0; }
    7676                        void visit( OffsetofExpr * ) { throw 0; }
     77                        void visit( OffsetPackExpr * ) { throw 0; }
    7778                        void visit( AttrExpr * ) { throw 0; }
    7879                        void visit( LogicalExpr * ) { throw 0; }
  • src/Parser/ExpressionNode.cc

    r3aba311 r37218fc  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Mar 13 12:34:38 2016
    13 // Update Count     : 272
     12// Last Modified On : Fri Apr  8 15:43:05 2016
     13// Update Count     : 296
    1414//
    1515
     
    2222
    2323#include "ParseNode.h"
     24#include "TypeData.h"
    2425#include "SynTree/Constant.h"
    2526#include "SynTree/Expression.h"
     27#include "SynTree/Declaration.h"
    2628#include "Common/UnimplementedError.h"
    2729#include "parseutility.h"
     
    872874}
    873875
     876
     877CompoundLiteralNode::CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids ) : type( type ), kids( kids ) {}
     878CompoundLiteralNode::CompoundLiteralNode( const CompoundLiteralNode &other ) : ExpressionNode( other ), type( other.type ), kids( other.kids ) {}
     879
     880CompoundLiteralNode::~CompoundLiteralNode() {
     881        delete kids;
     882        delete type;
     883}
     884
     885CompoundLiteralNode *CompoundLiteralNode::clone() const {
     886        return new CompoundLiteralNode( *this );
     887}
     888
     889void CompoundLiteralNode::print( std::ostream &os, int indent ) const {
     890        os << string( indent,' ' ) << "CompoundLiteralNode:" << endl;
     891
     892        os << string( indent + 2, ' ' ) << "type:" << endl;
     893        if ( type != 0 )
     894                type->print( os, indent + 4 );
     895
     896        os << string( indent + 2, ' ' ) << "initialization:" << endl;
     897        if ( kids != 0 )
     898                kids->printList( os, indent + 4 );
     899}
     900
     901void CompoundLiteralNode::printOneLine( std::ostream &os, int indent ) const {
     902        os << "( ";
     903        if ( type ) type->print( os );
     904        os << ", ";
     905        if ( kids ) kids->printOneLine( os );
     906        os << ") ";
     907}
     908
     909Expression *CompoundLiteralNode::build() const {
     910        Declaration * newDecl = type->build();                          // compound literal type
     911        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
     912                return new CompoundLiteralExpr( newDeclWithType->get_type(), kids->build() );
     913        // these types do not have associated type information
     914        } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl )  ) {
     915                return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), kids->build() );
     916        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl )  ) {
     917                return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), kids->build() );
     918        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl )  ) {
     919                return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), kids->build() );
     920        } else {
     921                assert( false );
     922        } // if
     923}
     924
     925
    874926ExpressionNode *flattenCommas( ExpressionNode *list ) {
    875927        if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( list ) ) {
  • src/Parser/ParseNode.h

    r3aba311 r37218fc  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Mon Apr 04 17:04:22 2016
    13 // Update Count     : 190
     12// Last Modified On : Mon Apr 11 11:50:52 2016
     13// Update Count     : 205
    1414//
    1515
     
    538538};
    539539
     540class CompoundLiteralNode : public ExpressionNode {
     541  public:
     542        CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids );
     543        CompoundLiteralNode( const CompoundLiteralNode &type );
     544        ~CompoundLiteralNode();
     545
     546        virtual CompoundLiteralNode *clone() const;
     547
     548        DeclarationNode *get_type() const { return type; }
     549        CompoundLiteralNode *set_type( DeclarationNode *t ) { type = t; return this; }
     550
     551        InitializerNode *get_initializer() const { return kids; }
     552        CompoundLiteralNode *set_initializer( InitializerNode *k ) { kids = k; return this; }
     553
     554        void print( std::ostream &, int indent = 0 ) const;
     555        void printOneLine( std::ostream &, int indent = 0 ) const;
     556
     557        virtual Expression *build() const;
     558  private:
     559        DeclarationNode *type;
     560        InitializerNode *kids;
     561};
     562
    540563template< typename SynTreeType, typename NodeType >
    541564void buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) {
  • src/Parser/parser.cc

    r3aba311 r37218fc  
    51805180/* Line 1806 of yacc.c  */
    51815181#line 374 "parser.yy"
    5182     { (yyval.en) = 0; }
     5182    { (yyval.en) = new CompoundLiteralNode( (yyvsp[(2) - (7)].decl), new InitializerNode( (yyvsp[(5) - (7)].in), true ) ); }
    51835183    break;
    51845184
  • src/Parser/parser.yy

    r3aba311 r37218fc  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 24 16:16:16 2016
    13 // Update Count     : 1498
     12// Last Modified On : Fri Apr  8 16:21:55 2016
     13// Update Count     : 1508
    1414//
    1515
     
    372372                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::DecrPost ), $1 ); }
    373373        | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99
    374                 { $$ = 0; }
     374                { $$ = new CompoundLiteralNode( $2, new InitializerNode( $5, true ) ); }
    375375        | postfix_expression '{' argument_expression_list '}' // CFA
    376376                {
  • src/ResolvExpr/AlternativeFinder.cc

    r3aba311 r37218fc  
    848848        }
    849849
     850        void AlternativeFinder::visit( OffsetPackExpr *offsetPackExpr ) {
     851                alternatives.push_back( Alternative( offsetPackExpr->clone(), env, Cost::zero ) );
     852        }
     853
    850854        void AlternativeFinder::resolveAttr( DeclarationWithType *funcDecl, FunctionType *function, Type *argType, const TypeEnvironment &env ) {
    851855                // assume no polymorphism
  • src/ResolvExpr/AlternativeFinder.h

    r3aba311 r37218fc  
    5959                virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    6060                virtual void visit( OffsetofExpr *offsetofExpr );
     61                virtual void visit( OffsetPackExpr *offsetPackExpr );
    6162                virtual void visit( AttrExpr *attrExpr );
    6263                virtual void visit( LogicalExpr *logicalExpr );
  • src/SymTab/AddVisit.h

    r3aba311 r37218fc  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 16:14:32 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Jul 14 12:26:17 2015
    13 // Update Count     : 4
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Apr  7 14:42:21 2016
     13// Update Count     : 5
    1414//
    1515
     
    2727
    2828        template< typename Visitor >
    29         inline void addVisitStatement( Statement *stmt, Visitor &visitor ) {
    30                 maybeAccept( stmt, visitor );
    31 ///   if ( ! declsToAdd.empty() ) {
    32 ///     CompoundStmt *compound = new CompoundStmt( noLabels );
    33 ///     compound->get_kids().push_back( stmt );
    34 ///     addDecls( declsToAdd, compound->get_kids(), compound->get_kids().end() );
    35 ///   }
    36         }
    37 
    38         template< typename Visitor >
    3929        inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) {
    4030                addVisitStatementList( compoundStmt->get_kids(), visitor );
    41         }
    42 
    43         template< typename Visitor >
    44         inline void addVisit(IfStmt *ifStmt, Visitor &visitor) {
    45                 addVisitStatement( ifStmt->get_thenPart(), visitor );
    46                 addVisitStatement( ifStmt->get_elsePart(), visitor );
    47                 maybeAccept( ifStmt->get_condition(), visitor );
    48         }
    49 
    50         template< typename Visitor >
    51         inline void addVisit(WhileStmt *whileStmt, Visitor &visitor) {
    52                 addVisitStatement( whileStmt->get_body(), visitor );
    53                 maybeAccept( whileStmt->get_condition(), visitor );
    54         }
    55 
    56         template< typename Visitor >
    57         inline void addVisit(ForStmt *forStmt, Visitor &visitor) {
    58                 addVisitStatement( forStmt->get_body(), visitor );
    59                 acceptAll( forStmt->get_initialization(), visitor );
    60                 maybeAccept( forStmt->get_condition(), visitor );
    61                 maybeAccept( forStmt->get_increment(), visitor );
    6231        }
    6332
     
    7443        }
    7544
    76         template< typename Visitor >
    77         inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) {
    78                 addVisitStatementList( caseStmt->get_statements(), visitor );
    79                 maybeAccept( caseStmt->get_condition(), visitor );
    80         }
    81 
    82         template< typename Visitor >
    83         inline void addVisit(CatchStmt *cathStmt, Visitor &visitor) {
    84                 addVisitStatement( cathStmt->get_body(), visitor );
    85                 maybeAccept( cathStmt->get_decl(), visitor );
    86         }
     45        // template< typename Visitor >
     46        // inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) {
     47        //      addVisitStatementList( caseStmt->get_statements(), visitor );
     48        //      maybeAccept( caseStmt->get_condition(), visitor );
     49        // }
    8750} // namespace SymTab
    8851
  • src/SymTab/Indexer.cc

    r3aba311 r37218fc  
    344344                maybeAccept( offsetofExpr->get_type(), *this );
    345345                maybeAccept( offsetofExpr->get_member(), *this );
     346        }
     347
     348        void Indexer::visit( OffsetPackExpr *offsetPackExpr ) {
     349                acceptAllNewScope( offsetPackExpr->get_results(), *this );
     350                maybeAccept( offsetPackExpr->get_type(), *this );
    346351        }
    347352
  • src/SymTab/Indexer.h

    r3aba311 r37218fc  
    5959                virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    6060                virtual void visit( OffsetofExpr *offsetofExpr );
     61                virtual void visit( OffsetPackExpr *offsetPackExpr );
    6162                virtual void visit( AttrExpr *attrExpr );
    6263                virtual void visit( LogicalExpr *logicalExpr );
  • src/SymTab/Validate.cc

    r3aba311 r37218fc  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:31:39 2016
    13 // Update Count     : 226
     12// Last Modified On : Thu Apr  7 16:45:30 2016
     13// Update Count     : 243
    1414//
    1515
     
    4040#include <list>
    4141#include <iterator>
     42#include "Common/utility.h"
     43#include "Common/UniqueName.h"
    4244#include "Validate.h"
    4345#include "SynTree/Visitor.h"
    4446#include "SynTree/Mutator.h"
    4547#include "SynTree/Type.h"
     48#include "SynTree/Expression.h"
    4649#include "SynTree/Statement.h"
    4750#include "SynTree/TypeSubstitution.h"
     
    4952#include "FixFunction.h"
    5053// #include "ImplementationType.h"
    51 #include "Common/utility.h"
    52 #include "Common/UniqueName.h"
     54#include "GenPoly/DeclMutator.h"
    5355#include "AddVisit.h"
    5456#include "MakeLibCfa.h"
     
    7072
    7173                virtual void visit( CompoundStmt *compoundStmt );
    72                 virtual void visit( IfStmt *ifStmt );
    73                 virtual void visit( WhileStmt *whileStmt );
    74                 virtual void visit( ForStmt *forStmt );
    7574                virtual void visit( SwitchStmt *switchStmt );
    7675                virtual void visit( ChooseStmt *chooseStmt );
    77                 virtual void visit( CaseStmt *caseStmt );
    78                 virtual void visit( CatchStmt *catchStmt );
     76                // virtual void visit( CaseStmt *caseStmt );
    7977          private:
    8078                HoistStruct();
     
    144142
    145143                virtual void visit( CompoundStmt *compoundStmt );
    146                 virtual void visit( IfStmt *ifStmt );
    147                 virtual void visit( WhileStmt *whileStmt );
    148                 virtual void visit( ForStmt *forStmt );
    149144                virtual void visit( SwitchStmt *switchStmt );
    150145                virtual void visit( ChooseStmt *chooseStmt );
    151                 virtual void visit( CaseStmt *caseStmt );
    152                 virtual void visit( CatchStmt *catchStmt );
     146                // virtual void visit( CaseStmt *caseStmt );
    153147
    154148                AutogenerateRoutines() : functionNesting( 0 ) {}
     
    166160                /// and return something if the return type is non-void.
    167161                static void checkFunctionReturns( std::list< Declaration * > & translationUnit );
    168 
    169162          private:
    170163                virtual void visit( FunctionDecl * functionDecl );
     
    202195        };
    203196
     197        class CompoundLiteral : public GenPoly::DeclMutator {
     198                DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass;
     199
     200                virtual DeclarationWithType * mutate( ObjectDecl *objectDecl );
     201                virtual Expression *mutate( CompoundLiteralExpr *compLitExpr );
     202        };
     203
    204204        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    205205                Pass1 pass1;
    206206                Pass2 pass2( doDebug, 0 );
    207207                Pass3 pass3( 0 );
     208                CompoundLiteral compoundliteral;
     209
    208210                EliminateTypedef::eliminateTypedef( translationUnit );
    209211                HoistStruct::hoistStruct( translationUnit );
     
    211213                acceptAll( translationUnit, pass2 );
    212214                ReturnChecker::checkFunctionReturns( translationUnit );
     215                mutateAll( translationUnit, compoundliteral );
    213216                AutogenerateRoutines::autogenerateRoutines( translationUnit );
    214217                acceptAll( translationUnit, pass3 );
     
    292295        }
    293296
    294         void HoistStruct::visit( IfStmt *ifStmt ) {
    295                 addVisit( ifStmt, *this );
    296         }
    297 
    298         void HoistStruct::visit( WhileStmt *whileStmt ) {
    299                 addVisit( whileStmt, *this );
    300         }
    301 
    302         void HoistStruct::visit( ForStmt *forStmt ) {
    303                 addVisit( forStmt, *this );
    304         }
    305 
    306297        void HoistStruct::visit( SwitchStmt *switchStmt ) {
    307298                addVisit( switchStmt, *this );
     
    312303        }
    313304
    314         void HoistStruct::visit( CaseStmt *caseStmt ) {
    315                 addVisit( caseStmt, *this );
    316         }
    317 
    318         void HoistStruct::visit( CatchStmt *cathStmt ) {
    319                 addVisit( cathStmt, *this );
    320         }
     305        // void HoistStruct::visit( CaseStmt *caseStmt ) {
     306        //      addVisit( caseStmt, *this );
     307        // }
    321308
    322309        void Pass1::visit( EnumDecl *enumDecl ) {
     
    874861        }
    875862
    876         void AutogenerateRoutines::visit( IfStmt *ifStmt ) {
    877                 visitStatement( ifStmt );
    878         }
    879 
    880         void AutogenerateRoutines::visit( WhileStmt *whileStmt ) {
    881                 visitStatement( whileStmt );
    882         }
    883 
    884         void AutogenerateRoutines::visit( ForStmt *forStmt ) {
    885                 visitStatement( forStmt );
    886         }
    887 
    888863        void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) {
    889864                visitStatement( switchStmt );
     
    894869        }
    895870
    896         void AutogenerateRoutines::visit( CaseStmt *caseStmt ) {
    897                 visitStatement( caseStmt );
    898         }
    899 
    900         void AutogenerateRoutines::visit( CatchStmt *cathStmt ) {
    901                 visitStatement( cathStmt );
    902         }
     871        // void AutogenerateRoutines::visit( CaseStmt *caseStmt ) {
     872        //      visitStatement( caseStmt );
     873        // }
    903874
    904875        void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) {
     
    10801051        }
    10811052
     1053        DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {
     1054                storageclass = objectDecl->get_storageClass();
     1055                DeclarationWithType * temp = Mutator::mutate( objectDecl );
     1056                storageclass = DeclarationNode::NoStorageClass;
     1057                return temp;
     1058        }
     1059
     1060        Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) {
     1061                // transform [storage_class] ... (struct S){ 3, ... };
     1062                // into [storage_class] struct S temp =  { 3, ... };
     1063                static UniqueName indexName( "_compLit" );
     1064
     1065                ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageclass, LinkageSpec::C, 0, compLitExpr->get_type(), compLitExpr->get_initializer() );
     1066                compLitExpr->set_type( 0 );
     1067                compLitExpr->set_initializer( 0 );
     1068                delete compLitExpr;
     1069                DeclarationWithType * newtempvar = mutate( tempvar );
     1070                addDeclaration( newtempvar );                                   // add modified temporary to current block
     1071                return new VariableExpr( newtempvar );
     1072        }
    10821073} // namespace SymTab
    10831074
  • src/SynTree/Expression.cc

    r3aba311 r37218fc  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Dec 09 14:10:29 2015
    13 // Update Count     : 34
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Apr  8 17:16:23 2016
     13// Update Count     : 40
    1414//
    1515
     
    2222
    2323#include "Type.h"
     24#include "Initializer.h"
    2425#include "Expression.h"
    2526#include "Declaration.h"
     
    211212
    212213        os << " of ";
     214
     215        if ( type ) {
     216                type->print(os, indent + 2);
     217        } else {
     218                os << "<NULL>";
     219        }
     220
     221        os << std::endl;
     222        Expression::print( os, indent );
     223}
     224
     225OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
     226        add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
     227}
     228
     229OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
     230
     231OffsetPackExpr::~OffsetPackExpr() { delete type; }
     232
     233void OffsetPackExpr::print( std::ostream &os, int indent ) const {
     234        os << std::string( indent, ' ' ) << "Offset pack expression on ";
    213235
    214236        if ( type ) {
     
    443465
    444466
     467CompoundLiteralExpr::CompoundLiteralExpr( Type * type, Initializer * initializer ) : type( type ), initializer( initializer ) {
     468        add_result( type->clone() );
     469}
     470
     471CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), type( maybeClone( other.type ) ), initializer( maybeClone( other.initializer ) ) {}
     472
     473CompoundLiteralExpr::~CompoundLiteralExpr() {
     474        delete initializer;
     475        delete type;
     476}
     477
     478void CompoundLiteralExpr::print( std::ostream &os, int indent ) const {
     479        os << "Compound Literal Expression: " << std::endl;
     480        if ( type ) type->print( os, indent + 2 );
     481        if ( initializer ) initializer->print( os, indent + 2 );
     482}
     483
    445484
    446485std::ostream & operator<<( std::ostream & out, Expression * expr ) {
  • src/SynTree/Expression.h

    r3aba311 r37218fc  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Dec 09 14:10:21 2015
    13 // Update Count     : 19
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Apr  8 17:18:06 2016
     13// Update Count     : 21
    1414//
    1515
     
    362362};
    363363
     364/// Expression representing a pack of field-offsets for a generic type
     365class OffsetPackExpr : public Expression {
     366public:
     367        OffsetPackExpr( StructInstType *type_, Expression *aname_ = 0 );
     368        OffsetPackExpr( const OffsetPackExpr &other );
     369        virtual ~OffsetPackExpr();
     370
     371        StructInstType *get_type() const { return type; }
     372        void set_type( StructInstType *newValue ) { type = newValue; }
     373
     374        virtual OffsetPackExpr *clone() const { return new OffsetPackExpr( *this ); }
     375        virtual void accept( Visitor &v ) { v.visit( this ); }
     376        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     377
     378        virtual void print( std::ostream &os, int indent = 0 ) const;
     379
     380private:
     381        StructInstType *type;
     382};
     383
    364384/// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
    365385class AttrExpr : public Expression {
     
    557577};
    558578
     579/// CompoundLiteralExpr represents a C99 'compound literal'
     580class CompoundLiteralExpr : public Expression {
     581  public:
     582        CompoundLiteralExpr( Type * type, Initializer * initializer );
     583        CompoundLiteralExpr( const CompoundLiteralExpr &other );
     584        ~CompoundLiteralExpr();
     585
     586        Type * get_type() const { return type; }
     587        void set_type( Type * t ) { type = t; }
     588
     589        Initializer * get_initializer() const { return initializer; }
     590        void set_initializer( Initializer * i ) { initializer = i; }
     591
     592        virtual CompoundLiteralExpr *clone() const { return new CompoundLiteralExpr( *this ); }
     593        virtual void accept( Visitor &v ) { v.visit( this ); }
     594        virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
     595        virtual void print( std::ostream &os, int indent = 0 ) const;
     596  private:
     597        Type * type;
     598        Initializer * initializer;
     599};
     600
    559601std::ostream & operator<<( std::ostream & out, Expression * expr );
    560602
  • src/SynTree/Mutator.cc

    r3aba311 r37218fc  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:28:20 2016
    13 // Update Count     : 12
     12// Last Modified On : Fri Apr  1 18:05:16 2016
     13// Update Count     : 16
    1414//
    1515
     
    274274}
    275275
     276Expression *Mutator::mutate( OffsetPackExpr *offsetPackExpr ) {
     277        mutateAll( offsetPackExpr->get_results(), *this );
     278        offsetPackExpr->set_type( maybeMutate( offsetPackExpr->get_type(), *this ) );
     279        return offsetPackExpr;
     280}
     281
    276282Expression *Mutator::mutate( AttrExpr *attrExpr ) {
    277283        mutateAll( attrExpr->get_results(), *this );
     
    334340        mutateAll( valofExpr->get_results(), *this );
    335341        return valofExpr;
     342}
     343
     344Expression *Mutator::mutate( CompoundLiteralExpr *compLitExpr ) {
     345        mutateAll( compLitExpr->get_results(), *this );
     346        compLitExpr->set_type( maybeMutate( compLitExpr->get_type(), *this ) );
     347        compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) );
     348        return compLitExpr;
    336349}
    337350
  • src/SynTree/Mutator.h

    r3aba311 r37218fc  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:33:11 2016
    13 // Update Count     : 9
     12// Last Modified On : Fri Apr  1 17:26:56 2016
     13// Update Count     : 10
    1414//
    1515#include <cassert>
     
    6767        virtual Expression* mutate( UntypedOffsetofExpr *offsetofExpr );
    6868        virtual Expression* mutate( OffsetofExpr *offsetofExpr );
     69        virtual Expression* mutate( OffsetPackExpr *offsetPackExpr );
    6970        virtual Expression* mutate( AttrExpr *attrExpr );
    7071        virtual Expression* mutate( LogicalExpr *logicalExpr );
     
    7677        virtual Expression* mutate( AsmExpr *asmExpr );
    7778        virtual Expression* mutate( UntypedValofExpr *valofExpr );
     79        virtual Expression* mutate( CompoundLiteralExpr *compLitExpr );
    7880
    7981        virtual Type* mutate( VoidType *basicType );
  • src/SynTree/SynTree.h

    r3aba311 r37218fc  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:29:00 2016
    13 // Update Count     : 4
     12// Last Modified On : Fri Apr  1 16:47:44 2016
     13// Update Count     : 5
    1414//
    1515
     
    7272class UntypedOffsetofExpr;
    7373class OffsetofExpr;
     74class OffsetPackExpr;
    7475class AttrExpr;
    7576class LogicalExpr;
     
    8182class AsmExpr;
    8283class UntypedValofExpr;
     84class CompoundLiteralExpr;
    8385
    8486class Type;
  • src/SynTree/Visitor.cc

    r3aba311 r37218fc  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:29:23 2016
    13 // Update Count     : 16
     12// Last Modified On : Fri Apr  1 18:05:13 2016
     13// Update Count     : 18
    1414//
    1515
     
    230230}
    231231
     232void Visitor::visit( OffsetPackExpr *offsetPackExpr ) {
     233        acceptAll( offsetPackExpr->get_results(), *this );
     234        maybeAccept( offsetPackExpr->get_type(), *this );
     235}
     236
    232237void Visitor::visit( AttrExpr *attrExpr ) {
    233238        acceptAll( attrExpr->get_results(), *this );
     
    282287        acceptAll( valofExpr->get_results(), *this );
    283288        maybeAccept( valofExpr->get_body(), *this );
     289}
     290
     291void Visitor::visit( CompoundLiteralExpr *compLitExpr ) {
     292        acceptAll( compLitExpr->get_results(), *this );
     293        maybeAccept( compLitExpr->get_type(), *this );
     294        maybeAccept( compLitExpr->get_initializer(), *this );
    284295}
    285296
  • src/SynTree/Visitor.h

    r3aba311 r37218fc  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:33:35 2016
    13 // Update Count     : 6
     12// Last Modified On : Fri Apr  1 17:26:55 2016
     13// Update Count     : 7
    1414//
    1515
     
    6767        virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    6868        virtual void visit( OffsetofExpr *offsetofExpr );
     69        virtual void visit( OffsetPackExpr *offsetPackExpr );
    6970        virtual void visit( AttrExpr *attrExpr );
    7071        virtual void visit( LogicalExpr *logicalExpr );
     
    7677        virtual void visit( AsmExpr *asmExpr );
    7778        virtual void visit( UntypedValofExpr *valofExpr );
     79        virtual void visit( CompoundLiteralExpr *compLitExpr );
    7880
    7981        virtual void visit( VoidType *basicType );
  • src/Tuples/FlattenTuple.cc

    r3aba311 r37218fc  
    4949        void FlattenTuple::CollectArgs::visit( UntypedOffsetofExpr *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    5050        void FlattenTuple::CollectArgs::visit( OffsetofExpr        *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     51        void FlattenTuple::CollectArgs::visit( OffsetPackExpr      *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    5152        void FlattenTuple::CollectArgs::visit( AttrExpr            *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    5253        void FlattenTuple::CollectArgs::visit( LogicalExpr         *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
  • src/Tuples/FlattenTuple.h

    r3aba311 r37218fc  
    4545                        virtual void visit( UntypedOffsetofExpr * );
    4646                        virtual void visit( OffsetofExpr * );
     47                        virtual void visit( OffsetPackExpr * );
    4748                        virtual void visit( AttrExpr * );
    4849                        virtual void visit( LogicalExpr * );
  • src/driver/cfa.cc

    r3aba311 r37218fc  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan 28 18:24:06 2016
    13 // Update Count     : 127
     12// Last Modified On : Wed Apr  6 14:04:22 2016
     13// Update Count     : 132
    1414//
    1515
     
    165165                                nargs += 1;
    166166                        } else if ( prefix( arg, "-std=" ) ) {
    167                                 std_flag = true;                                                // std=XX provided
     167                                std_flag = true;                                                // -std=XX provided
    168168                                args[nargs] = argv[i];                                  // pass the argument along
    169169                                nargs += 1;
     
    307307                nargs += 1;
    308308                if ( ! std_flag ) {                                                             // default c99, if none specified
    309                         args[nargs] = "-std=c99";
     309                        args[nargs] = "-std=gnu99";
    310310                        nargs += 1;
    311311                } // if
  • src/libcfa/Makefile.am

    r3aba311 r37218fc  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Wed Mar  2 22:59:23 2016
    14 ## Update Count     : 119
     13## Last Modified On : Wed Apr  6 21:10:44 2016
     14## Update Count     : 123
    1515###############################################################################
    1616
     
    6060        ${CC} ${CFLAGS} -c -o $@ $<
    6161
    62 libs = stdlib iostream fstream iterator
     62libs = limits stdlib iostream fstream iterator rational
    6363libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c}
    6464
    65 cheaders = #  expat
    66 cfaheaders = limits
     65cheaders = # expat
     66cfaheaders = # limits
    6767include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders}
    6868
  • src/libcfa/Makefile.in

    r3aba311 r37218fc  
    8383libcfa_a_AR = $(AR) $(ARFLAGS)
    8484libcfa_a_LIBADD =
    85 am__objects_1 = stdlib.$(OBJEXT) iostream.$(OBJEXT) fstream.$(OBJEXT) \
    86         iterator.$(OBJEXT)
     85am__objects_1 = limits.$(OBJEXT) stdlib.$(OBJEXT) iostream.$(OBJEXT) \
     86        fstream.$(OBJEXT) iterator.$(OBJEXT) rational.$(OBJEXT)
    8787am_libcfa_a_OBJECTS = libcfa-prelude.$(OBJEXT) $(am__objects_1)
    8888libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS)
     
    213213MAINTAINERCLEANFILES = ${addprefix ${libdir}/,${cfalib_DATA}} \
    214214        ${addprefix ${libdir}/,${lib_LIBRARIES}} ${includedir}/*
    215 libs = stdlib iostream fstream iterator
     215libs = limits stdlib iostream fstream iterator rational
    216216libcfa_a_SOURCES = libcfa-prelude.c ${libs:=.c}
    217 cheaders = #  expat
    218 cfaheaders = limits
     217cheaders = # expat
     218cfaheaders = # limits
    219219include_HEADERS = ${cheaders:=.h} ${libs} ${cfaheaders}
    220220all: all-am
     
    297297@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iterator.Po@am__quote@
    298298@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcfa-prelude.Po@am__quote@
     299@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/limits.Po@am__quote@
     300@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rational.Po@am__quote@
    299301@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdlib.Po@am__quote@
    300302
  • src/libcfa/fstream

    r3aba311 r37218fc  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 15:08:14 2016
    13 // Update Count     : 78
     12// Last Modified On : Tue Apr  5 22:37:12 2016
     13// Update Count     : 82
    1414//
    1515
     
    2020
    2121enum { separateSize = 16 };
    22 struct ofstream { void *file; int separate; char separator[separateSize]; };
     22struct ofstream {
     23        void *file;
     24        _Bool sepDefault;
     25        _Bool sepOnOff;
     26        char separator[separateSize];
     27}; // ofstream
    2328
    2429_Bool sepPrt( ofstream * );
    2530void sepOn( ofstream * );
    2631void sepOff( ofstream * );
     32void sepReset( ofstream * );
     33void sepReset( ofstream *, _Bool );
    2734void sepSet( ofstream *, const char * );
    2835const char * sepGet( ofstream * );
    29 void sepDisable( ofstream * );
    30 void sepEnable( ofstream * );
     36_Bool sepDisable( ofstream * );
     37_Bool sepEnable( ofstream * );
    3138int fail( ofstream * );
    3239int flush( ofstream * );
     
    3946
    4047// implement context istream
    41 struct ifstream { void *file; };
     48struct ifstream {
     49        void *file;
     50}; // ifstream
    4251
    4352int fail( ifstream * is );
  • src/libcfa/fstream.c

    r3aba311 r37218fc  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Feb 29 18:41:10 2016
    13 // Update Count     : 162
     12// Last Modified On : Wed Apr  6 17:55:27 2016
     13// Update Count     : 176
    1414//
    1515
     
    2525}
    2626
    27 #define IO_MSG "I/O error "
     27#define IO_MSG "I/O error: "
    2828
    29 _Bool sepPrt( ofstream * os ) { return os->separate == 1; }
    30 void sepOn( ofstream * os ) { if ( os->separate != 2 ) os->separate = 1; }
    31 void sepOff( ofstream * os ) { if ( os->separate != 2 ) os->separate = 0; }
     29_Bool sepPrt( ofstream * os ) { return os->sepOnOff; }
     30void sepOn( ofstream * os ) { os->sepOnOff = 1; }
     31void sepOff( ofstream * os ) { os->sepOnOff = 0; }
     32void sepReset( ofstream * os ) { os->sepOnOff = os->sepDefault; }
     33void sepReset( ofstream * os, _Bool reset ) { os->sepDefault = reset; os->sepOnOff = os->sepDefault; }
    3234void sepSet( ofstream * os, const char * s ) {
    3335        strncpy( &(os->separator[0]), s, separateSize - 1 );
     
    3537} // sepSet
    3638const char * sepGet( ofstream * os ) { return &(os->separator[0]); }
    37 void sepDisable( ofstream *os ) { os->separate = 2; }
    38 void sepEnable( ofstream *os ) { os->separate = 0; }
     39_Bool sepDisable( ofstream *os ) {
     40        _Bool temp = os->sepDefault;
     41        os->sepDefault = 0;
     42        sepReset( os );
     43        return temp;
     44} // sepDisable
     45_Bool sepEnable( ofstream *os ) {
     46        _Bool temp = os->sepDefault;
     47        os->sepDefault = 1;
     48        sepReset( os );
     49        return temp;
     50} // sepEnable
    3951
    4052int fail( ofstream * os ) {
     
    4961        FILE *file = fopen( name, mode );
    5062        if ( file == 0 ) {                                                                      // do not change unless successful
    51                 perror( IO_MSG "open output" );
     63                fprintf( stderr, IO_MSG "open output file \"%s\", ", name );
     64                perror( 0 );
    5265                exit( EXIT_FAILURE );
    5366        } // if
     
    94107
    95108
    96 static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 0, { ' ', '\0' } };
     109static ofstream soutFile = { (FILE *)(&_IO_2_1_stdout_), 1, 0, { ' ', '\0' } };
    97110ofstream *sout = &soutFile;
    98 static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 0, { ' ', '\0' } };
     111static ofstream serrFile = { (FILE *)(&_IO_2_1_stderr_), 1, 0, { ' ', '\0' } };
    99112ofstream *serr = &serrFile;
    100113
     
    114127        FILE *t = fopen( name, mode );
    115128        if ( t == 0 ) {                                                                         // do not change unless successful
    116                 perror( IO_MSG "open input" );
     129                fprintf( stderr, IO_MSG "open input file \"%s\", ", name );
     130                perror( 0 );
    117131                exit( EXIT_FAILURE );
    118132        } // if
     
    175189// Local Variables: //
    176190// tab-width: 4 //
    177 // compile-command: "cfa fstream.c" //
    178191// End: //
  • src/libcfa/iostream

    r3aba311 r37218fc  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 18:05:27 2016
    13 // Update Count     : 85
     12// Last Modified On : Tue Apr  5 22:32:37 2016
     13// Update Count     : 90
    1414//
    1515
     
    2323        void sepOn( ostype * );
    2424        void sepOff( ostype * );
     25        void sepReset( ostype * );
     26        void sepReset( ostype *, _Bool );
    2527        void sepSet( ostype *, const char * );
    2628        const char * sepGet( ostype * );
    27         void sepDisable( ostype * );
    28         void sepEnable( ostype * );
     29        _Bool sepDisable( ostype * );
     30        _Bool sepEnable( ostype * );
    2931        int fail( ostype * );
    3032        int flush( ostype * );
     
    6769forall( dtype ostype | ostream( ostype ) ) ostype * sepOn( ostype * );
    6870forall( dtype ostype | ostream( ostype ) ) ostype * sepOff( ostype * );
     71forall( dtype ostype | ostream( ostype ) ) ostype * sepDisable( ostype * );
     72forall( dtype ostype | ostream( ostype ) ) ostype * sepEnable( ostype * );
    6973
    7074// writes the range [begin, end) to the given stream
     
    110114forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, long double _Complex * );
    111115
    112 struct _Istream_str1 { char * s; };
    113 _Istream_str1 str( char * );
    114 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_str1 );
     116struct _Istream_cstrUC { char * s; };
     117_Istream_cstrUC cstr( char * );
     118forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrUC );
    115119
    116 struct _Istream_str2 { char * s; int size; };
    117 _Istream_str2 str( char *, int size );
    118 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_str2 );
     120struct _Istream_cstrC { char * s; int size; };
     121_Istream_cstrC cstr( char *, int size );
     122forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, _Istream_cstrC );
    119123
    120124#endif // __IOSTREAM_H__
  • src/libcfa/iostream.c

    r3aba311 r37218fc  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar  7 13:51:23 2016
    13 // Update Count     : 227
     12// Last Modified On : Wed Apr  6 16:13:29 2016
     13// Update Count     : 278
    1414//
    1515
     
    2727ostype * ?|?( ostype *os, char c ) {
    2828        prtfmt( os, "%c", c );
     29        sepOff( os );
    2930        return os;
    3031} // ?|?
     
    3233forall( dtype ostype | ostream( ostype ) )
    3334ostype * ?|?( ostype *os, short int si ) {
    34         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     35        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     36        sepReset( os );
    3537        prtfmt( os, "%hd", si );
    3638        return os;
     
    3941forall( dtype ostype | ostream( ostype ) )
    4042ostype * ?|?( ostype *os, unsigned short int usi ) {
    41         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     43        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     44        sepReset( os );
    4245        prtfmt( os, "%hu", usi );
    4346        return os;
     
    4649forall( dtype ostype | ostream( ostype ) )
    4750ostype * ?|?( ostype *os, int i ) {
    48         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     51        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     52        sepReset( os );
    4953        prtfmt( os, "%d", i );
    5054        return os;
     
    5357forall( dtype ostype | ostream( ostype ) )
    5458ostype * ?|?( ostype *os, unsigned int ui ) {
    55         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     59        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     60        sepReset( os );
    5661        prtfmt( os, "%u", ui );
    5762        return os;
     
    6065forall( dtype ostype | ostream( ostype ) )
    6166ostype * ?|?( ostype *os, long int li ) {
    62         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     67        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     68        sepReset( os );
    6369        prtfmt( os, "%ld", li );
    6470        return os;
     
    6773forall( dtype ostype | ostream( ostype ) )
    6874ostype * ?|?( ostype *os, unsigned long int uli ) {
    69         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     75        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     76        sepReset( os );
    7077        prtfmt( os, "%lu", uli );
    7178        return os;
     
    7481forall( dtype ostype | ostream( ostype ) )
    7582ostype * ?|?( ostype *os, long long int lli ) {
    76         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     83        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     84        sepReset( os );
    7785        prtfmt( os, "%lld", lli );
    7886        return os;
     
    8189forall( dtype ostype | ostream( ostype ) )
    8290ostype * ?|?( ostype *os, unsigned long long int ulli ) {
    83         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     91        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     92        sepReset( os );
    8493        prtfmt( os, "%llu", ulli );
    8594        return os;
     
    8897forall( dtype ostype | ostream( ostype ) )
    8998ostype * ?|?( ostype *os, float f ) {
    90         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     99        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     100        sepReset( os );
    91101        prtfmt( os, "%g", f );
    92102        return os;
     
    95105forall( dtype ostype | ostream( ostype ) )
    96106ostype * ?|?( ostype *os, double d ) {
    97         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     107        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     108        sepReset( os );
    98109        prtfmt( os, "%.*lg", DBL_DIG, d );
    99110        return os;
     
    102113forall( dtype ostype | ostream( ostype ) )
    103114ostype * ?|?( ostype *os, long double ld ) {
    104         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     115        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     116        sepReset( os );
    105117        prtfmt( os, "%.*Lg", LDBL_DIG, ld );
    106118        return os;
     
    110122ostype * ?|?( ostype *os, float _Complex fc ) {
    111123        os | crealf( fc );
    112         if ( cimagf( fc ) >= 0 ) os | '+';
    113         os | "" | cimagf( fc ) | 'i';
     124        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     125        if ( cimagf( fc ) >= 0 ) os | '+';                                      // negative value prints '-'
     126        os | cimagf( fc ) | 'i';
     127        sepReset( os, temp );                                                           // reset separator
    114128        return os;
    115129} // ?|?
     
    118132ostype * ?|?( ostype *os, double _Complex dc ) {
    119133        os | creal( dc );
    120         if ( cimag( dc ) >= 0 ) os | '+';
    121         os | "" | cimag( dc ) | 'i';
     134        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     135        if ( cimag( dc ) >= 0 ) os | '+';                                       // negative value prints '-'
     136        os | cimag( dc ) | 'i';
     137        sepReset( os, temp );                                                           // reset separator
    122138        return os;
    123139} // ?|?
     
    126142ostype * ?|?( ostype *os, long double _Complex ldc ) {
    127143        os | creall( ldc );
    128         if ( cimagl( ldc ) >= 0 ) os | '+';
    129         os | "" | cimagl( ldc ) | 'i';
     144        _Bool temp = sepDisable( os );                                          // disable separators within complex value
     145        if ( cimagl( ldc ) >= 0 ) os | '+';                                     // negative value prints '-'
     146        os | cimagl( ldc ) | 'i';
     147        sepReset( os, temp );                                                           // reset separator
    130148        return os;
    131149} // ?|?
     
    134152ostype * ?|?( ostype *os, const char *cp ) {
    135153        enum { Open = 1, Close, OpenClose };
    136         static const char mask[256] = {
     154        static const unsigned char mask[256] = {
    137155                // opening delimiters
    138156                ['('] : Open, ['['] : Open, ['{'] : Open,
    139                 ['$'] : Open, [L'£'] : Open, [L'¥'] : Open, [L'¢'] : Open, [L'¿'] : Open, [L'«'] : Open,
     157                ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,
    140158                // closing delimiters
    141159                [','] : Close, ['.'] : Close, [':'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
    142160                [')'] : Close, [']'] : Close, ['}'] : Close,
    143                 ['%'] : Close, [L'»'] : Close,
     161                ['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
    144162                // opening-closing delimiters
    145163                ['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose,
     164                ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace
    146165        }; // mask
    147166
     
    149168        // null string => no separator
    150169  if ( len == 0 ) { sepOff( os ); return os; }
    151         // first character NOT spacing or closing punctuation => add left separator
    152         if ( sepPrt( os ) && isspace( cp[0] ) == 0 && mask[ cp[0] ] != Close && mask[ cp[0] ] != OpenClose ) {
     170        // first character IS NOT spacing or closing punctuation => add left separator
     171        unsigned char ch = cp[0];                                                       // must make unsigned
     172        if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
    153173                prtfmt( os, "%s", sepGet( os ) );
    154174        } // if
    155175        // last character IS spacing or opening punctuation => turn off separator for next item
    156176        unsigned int posn = len - 1;
    157         if ( isspace( cp[posn] ) || mask[ cp[posn] ] == Open || mask[ cp[posn] ] == OpenClose ) {
     177        ch = cp[posn];                                                                          // must make unsigned
     178        if ( mask[ ch ] == Open || mask[ ch ] == OpenClose ) {
    158179                sepOff( os );
    159180        } else {
     
    165186forall( dtype ostype | ostream( ostype ) )
    166187ostype * ?|?( ostype *os, const void *p ) {
    167         if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) ); else sepOn( os );
     188        if ( sepPrt( os ) ) prtfmt( os, "%s", sepGet( os ) );
     189        sepReset( os );
    168190        prtfmt( os, "%p", p );
    169191        return os;
     
    196218} // sepOff
    197219
     220forall( dtype ostype | ostream( ostype ) )
     221ostype * sepEnable( ostype * os ) {
     222        sepEnable( os );
     223        return os;
     224} // sepEnable
     225
     226forall( dtype ostype | ostream( ostype ) )
     227ostype * sepDisable( ostype * os ) {
     228        sepDisable( os );
     229        return os;
     230} // sepDisable
     231
    198232//---------------------------------------
    199233
     
    310344} // ?|?
    311345
    312 _Istream_str1 str( char * s ) { _Istream_str1 s = { s }; return s; }
    313 forall( dtype istype | istream( istype ) )
    314 istype * ?|?( istype * is, _Istream_str1 str ) {
    315         scanfmt( is, "%s", str.s );
    316         return is;
    317 } // str
    318 
    319 _Istream_str2 str( char * s, int size ) { _Istream_str2 s = { s, size }; return s; }
    320 forall( dtype istype | istream( istype ) )
    321 istype * ?|?( istype * is, _Istream_str2 str ) {
     346_Istream_cstrUC cstr( char * s ) { _Istream_cstrUC s = { s }; return s; }
     347forall( dtype istype | istream( istype ) )
     348istype * ?|?( istype * is, _Istream_cstrUC cstr ) {
     349        scanfmt( is, "%s", cstr.s );
     350        return is;
     351} // cstr
     352
     353_Istream_cstrC cstr( char * s, int size ) { _Istream_cstrC s = { s, size }; return s; }
     354forall( dtype istype | istream( istype ) )
     355istype * ?|?( istype * is, _Istream_cstrC cstr ) {
    322356        char buf[16];
    323         sprintf( buf, "%%%ds", str.size );
    324         scanfmt( is, buf, str.s );
    325         return is;
    326 } // str
     357        sprintf( buf, "%%%ds", cstr.size );
     358        scanfmt( is, buf, cstr.s );
     359        return is;
     360} // cstr
    327361
    328362// Local Variables: //
  • src/libcfa/limits

    r3aba311 r37218fc  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// limits --
     8//
     9// Author           : Peter A. Buhr
     10// Created On       : Wed Apr  6 18:06:52 2016
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Apr  6 21:08:16 2016
     13// Update Count     : 6
     14//
     15
    116// Integral Constants
    217
    3 const short int MIN = -32768;
    4 const int MIN = -2147483648;
    5 const long int MIN = -9223372036854775807L - 1L;
    6 const long long int MIN = -9223372036854775807LL - 1LL;
     18extern const short int MIN;
     19extern const int MIN;
     20extern const long int MIN;
     21extern const long long int MIN;
    722
    8 const short int MAX = 32767;
    9 const unsigned short int MAX = 65535;
    10 const int MAX = 2147483647;
    11 const unsigned int MAX = 4294967295_U;
    12 const long int MAX = 9223372036854775807_L;
    13 const unsigned long int MAX = 4294967295_U;
    14 const long long int MAX = 9223372036854775807_LL;
    15 const unsigned long long int MAX = 18446744073709551615_ULL;
     23extern const short int MAX;
     24extern const unsigned short int MAX;
     25extern const int MAX;
     26extern const unsigned int MAX;
     27extern const long int MAX;
     28extern const unsigned long int MAX;
     29extern const long long int MAX;
     30extern const unsigned long long int MAX;
    1631
    1732// Floating-Point Constants
    1833
    19 const float PI = 3.141592_F;                            // pi
    20 const float PI_2 = 1.570796_F;                          // pi / 2
    21 const float PI_4 = 0.7853981_F;                         // pi / 4
    22 const float _1_PI = 0.3183098_F;                        // 1 / pi
    23 const float _2_PI = 0.6366197_F;                        // 2 / pi
    24 const float _2_SQRT_PI = 1.128379_F;                    // 2 / sqrt(pi)
     34extern const float PI;                                                                  // pi
     35extern const float PI_2;                                                                // pi / 2
     36extern const float PI_4;                                                                // pi / 4
     37extern const float _1_PI;                                                               // 1 / pi
     38extern const float _2_PI;                                                               // 2 / pi
     39extern const float _2_SQRT_PI;                                                  // 2 / sqrt(pi)
    2540
    26 const double PI = 3.14159265358979323846_D;             // pi
    27 const double PI_2 = 1.57079632679489661923_D;           // pi / 2
    28 const double PI_4 = 0.78539816339744830962_D;           // pi / 4
    29 const double _1_PI = 0.31830988618379067154_D;          // 1 / pi
    30 const double _2_PI = 0.63661977236758134308_D;          // 2 / pi
    31 const double _2_SQRT_PI = 1.12837916709551257390_D;     // 2 / sqrt(pi)
     41extern const double PI;                                                                 // pi
     42extern const double PI_2;                                                               // pi / 2
     43extern const double PI_4;                                                               // pi / 4
     44extern const double _1_PI;                                                              // 1 / pi
     45extern const double _2_PI;                                                              // 2 / pi
     46extern const double _2_SQRT_PI;                                                 // 2 / sqrt(pi)
    3247
    33 const long double PI = 3.1415926535897932384626433832795029_DL; // pi
    34 const long double PI_2 = 1.5707963267948966192313216916397514_DL; // pi / 2
    35 const long double PI_4 = 0.7853981633974483096156608458198757_DL; // pi / 4
    36 const long double _1_PI = 0.3183098861837906715377675267450287_DL; // 1 / pi
    37 const long double _2_PI = 0.6366197723675813430755350534900574_DL; // 2 / pi
    38 const long double _2_SQRT_PI = 1.1283791670955125738961589031215452_DL; // 2 / sqrt(pi)
     48extern const long double PI;                                                    // pi
     49extern const long double PI_2;                                                  // pi / 2
     50extern const long double PI_4;                                                  // pi / 4
     51extern const long double _1_PI;                                                 // 1 / pi
     52extern const long double _2_PI;                                                 // 2 / pi
     53extern const long double _2_SQRT_PI;                                    // 2 / sqrt(pi)
    3954
    40 const _Complex PI = 3.14159265358979323846_D+0.0_iD;    // pi
    41 const _Complex PI_2 = 1.57079632679489661923_D+0.0_iD;  // pi / 2
    42 const _Complex PI_4 = 0.78539816339744830962_D+0.0_iD;  // pi / 4
    43 const _Complex _1_PI = 0.31830988618379067154_D+0.0_iD; // 1 / pi
    44 const _Complex _2_PI = 0.63661977236758134308_D+0.0_iD; // 2 / pi
    45 const _Complex _2_SQRT_PI = 1.12837916709551257390_D+0.0_iD; // 2 / sqrt(pi)
     55extern const _Complex PI;                                                               // pi
     56extern const _Complex PI_2;                                                             // pi / 2
     57extern const _Complex PI_4;                                                             // pi / 4
     58extern const _Complex _1_PI;                                                    // 1 / pi
     59extern const _Complex _2_PI;                                                    // 2 / pi
     60extern const _Complex _2_SQRT_PI;                                               // 2 / sqrt(pi)
    4661
    47 const long _Complex PI = 3.1415926535897932384626433832795029_L+0.0iL; // pi
    48 const long _Complex PI_2 = 1.5707963267948966192313216916397514_L+0.0iL; // pi / 2
    49 const long _Complex PI_4 = 0.7853981633974483096156608458198757_L+0.0iL; // pi / 4
    50 const long _Complex _1_PI = 0.3183098861837906715377675267450287_L+0.0iL; // 1 / pi
    51 const long _Complex _2_PI = 0.6366197723675813430755350534900574_L+0.0iL; // 2 / pi
    52 const long _Complex _2_SQRT_PI = 1.1283791670955125738961589031215452_L+0.0iL; // 2 / sqrt(pi)
     62extern const long _Complex PI;                                                  // pi
     63extern const long _Complex PI_2;                                                // pi / 2
     64extern const long _Complex PI_4;                                                // pi / 4
     65extern const long _Complex _1_PI;                                               // 1 / pi
     66extern const long _Complex _2_PI;                                               // 2 / pi
     67extern const long _Complex _2_SQRT_PI;                                  // 2 / sqrt(pi)
    5368
    54 const float E = 2.718281;                               // e
    55 const float LOG2_E = 1.442695;                          // log_2(e)
    56 const float LOG10_E = 0.4342944;                        // log_10(e)
    57 const float LN_2 = 0.6931471;                           // log_e(2)
    58 const float LN_10 = 2.302585;                           // log_e(10)
    59 const float SQRT_2 = 1.414213;                          // sqrt(2)
    60 const float _1_SQRT_2 = 0.7071067;                      // 1 / sqrt(2)
     69extern const float E;                                                                   // e
     70extern const float LOG2_E;                                                              // log_2(e)
     71extern const float LOG10_E;                                                             // log_10(e)
     72extern const float LN_2;                                                                // log_e(2)
     73extern const float LN_10;                                                               // log_e(10)
     74extern const float SQRT_2;                                                              // sqrt(2)
     75extern const float _1_SQRT_2;                                                   // 1 / sqrt(2)
    6176
    62 const double E = 2.7182818284590452354_D;               // e
    63 const double LOG2_E = 1.4426950408889634074_D;          // log_2(e)
    64 const double LOG10_E = 0.43429448190325182765_D;        // log_10(e)
    65 const double LN_2 = 0.69314718055994530942_D;           // log_e(2)
    66 const double LN_10 = 2.30258509299404568402_D;          // log_e(10)
    67 const double SQRT_2 = 1.41421356237309504880_D;         // sqrt(2)
    68 const double _1_SQRT_2 = 0.70710678118654752440_D;      // 1 / sqrt(2)
     77extern const double E;                                                                  // e
     78extern const double LOG2_E;                                                             // log_2(e)
     79extern const double LOG10_E;                                                    // log_10(e)
     80extern const double LN_2;                                                               // log_e(2)
     81extern const double LN_10;                                                              // log_e(10)
     82extern const double SQRT_2;                                                             // sqrt(2)
     83extern const double _1_SQRT_2;                                                  // 1 / sqrt(2)
    6984
    70 const long double E = 2.7182818284590452353602874713526625_DL; // e
    71 const long double LOG2_E = 1.4426950408889634073599246810018921_DL; // log_2(e)
    72 const long double LOG10_E = 0.4342944819032518276511289189166051_DL; // log_10(e)
    73 const long double LN_2 = 0.6931471805599453094172321214581766_DL; // log_e(2)
    74 const long double LN_10 = 2.3025850929940456840179914546843642_DL; // log_e(10)
    75 const long double SQRT_2 = 1.4142135623730950488016887242096981_DL; // sqrt(2)
    76 const long double _1_SQRT_2 = 0.7071067811865475244008443621048490_DL; // 1/sqrt(2)
     85extern const long double E;                                                             // e
     86extern const long double LOG2_E;                                                // log_2(e)
     87extern const long double LOG10_E;                                               // log_10(e)
     88extern const long double LN_2;                                                  // log_e(2)
     89extern const long double LN_10;                                                 // log_e(10)
     90extern const long double SQRT_2;                                                // sqrt(2)
     91extern const long double _1_SQRT_2;                                             // 1/sqrt(2)
    7792
    78 const _Complex E = 2.7182818284590452354_D+0.0_iD;      // e
    79 const _Complex LOG2_E = 1.4426950408889634074_D+0.0_iD; // log_2(e)
    80 const _Complex LOG10_E = 0.43429448190325182765_D+0.0_iD; // log_10(e)
    81 const _Complex LN_2 = 0.69314718055994530942_D+0.0_iD;  // log_e(2)
    82 const _Complex LN_10 = 2.30258509299404568402_D+0.0_iD; // log_e(10)
    83 const _Complex SQRT_2 = 1.41421356237309504880_D+0.0_iD;        // sqrt(2)
    84 const _Complex _1_SQRT_2 = 0.70710678118654752440_D+0.0_iD; // 1 / sqrt(2)
     93extern const _Complex E;                                                                // e
     94extern const _Complex LOG2_E;                                                   // log_2(e)
     95extern const _Complex LOG10_E;                                                  // log_10(e)
     96extern const _Complex LN_2;                                                             // log_e(2)
     97extern const _Complex LN_10;                                                    // log_e(10)
     98extern const _Complex SQRT_2;                                                   // sqrt(2)
     99extern const _Complex _1_SQRT_2;                                                // 1 / sqrt(2)
    85100
    86 const long _Complex E = 2.7182818284590452353602874713526625_L+0.0_iL; // e
    87 const long _Complex LOG2_E = 1.4426950408889634073599246810018921_L+0.0_iL; // log_2(e)
    88 const long _Complex LOG10_E = 0.4342944819032518276511289189166051_L+0.0_iL; // log_10(e)
    89 const long _Complex LN_2 = 0.6931471805599453094172321214581766_L+0.0_iL; // log_e(2)
    90 const long _Complex LN_10 = 2.3025850929940456840179914546843642_L+0.0_iL; // log_e(10)
    91 const long _Complex SQRT_2 = 1.4142135623730950488016887242096981_L+0.0_iL; // sqrt(2)
    92 const long _Complex _1_SQRT_2 = 0.7071067811865475244008443621048490_L+0.0_iL; // 1 / sqrt(2)
     101extern const long _Complex E;                                                   // e
     102extern const long _Complex LOG2_E;                                              // log_2(e)
     103extern const long _Complex LOG10_E;                                             // log_10(e)
     104extern const long _Complex LN_2;                                                // log_e(2)
     105extern const long _Complex LN_10;                                               // log_e(10)
     106extern const long _Complex SQRT_2;                                              // sqrt(2)
     107extern const long _Complex _1_SQRT_2;                                   // 1 / sqrt(2)
     108
     109// Local Variables: //
     110// mode: c //
     111// tab-width: 4 //
     112// End: //
  • src/libcfa/stdlib

    r3aba311 r37218fc  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 22 22:34:24 2016
    13 // Update Count     : 69
     12// Last Modified On : Fri Apr  1 22:26:14 2016
     13// Update Count     : 73
    1414//
    1515
     
    1818extern "C" {
    1919#include <stddef.h>                                                                             // size_t
     20#include <math.h>                                                                               // floor
    2021} // extern "C"
    2122
     
    8081char abs( char );
    8182extern "C" {
    82 int abs( int );         // use default C routine for int
    83 } // extern
     83int abs( int );                         // use default C routine for int
     84} // extern "C"
    8485long int abs( long int );
    8586long long int abs( long long int );
     
    9091double _Complex abs( double _Complex );
    9192long double _Complex abs( long double _Complex );
     93
     94//---------------------------------------
     95
     96float floor( float );
     97extern "C" {
     98double floor( double );         // use C routine for double
     99} // extern "C"
     100long double floor( long double );
     101
     102float ceil( float );
     103extern "C" {
     104double ceil( double );          // use C routine for double
     105} // extern "C"
     106long double ceil( long double );
    92107
    93108//---------------------------------------
  • src/libcfa/stdlib.c

    r3aba311 r37218fc  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 23 13:26:42 2016
    13 // Update Count     : 146
     12// Last Modified On : Wed Mar 30 10:48:41 2016
     13// Update Count     : 149
    1414//
    1515
     
    243243//---------------------------------------
    244244
     245float floor( float v ) { return floorf( v ); }
     246long double floor( long double v ) { return floorl( v ); }
     247
     248float ceil( float v ) { return ceilf( v ); }
     249long double ceil( long double v ) { return ceill( v ); }
     250
     251//---------------------------------------
     252
    245253void rand48seed( long int s ) { srand48( s ); }
    246254char rand48() { return mrand48(); }
Note: See TracChangeset for help on using the changeset viewer.