Changeset 17cd4eb for translator/SynTree


Ignore:
Timestamp:
Jan 7, 2015, 6:04:42 PM (11 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
0b8cd722
Parents:
d9a0e76
Message:

fixed restrict, fixed parameter copy, introduced name table for types, changed variable after to string

Location:
translator/SynTree
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • translator/SynTree/BasicType.cc

    rd9a0e76 r17cd4eb  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: BasicType.cc,v 1.10 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
    7 
    81#include <cassert>
    92
     
    114
    125
    13 BasicType::BasicType( const Type::Qualifiers &tq, Kind bt )
    14     : Type( tq ), kind( bt )
    15 {
    16 }
     6BasicType::BasicType( const Type::Qualifiers &tq, Kind bt ) : Type( tq ), kind( bt ) {}
    177
    18 void
    19 BasicType::print( std::ostream &os, int indent ) const
    20 {
     8void BasicType::print( std::ostream &os, int indent ) const {
    219    static const char *kindNames[] = { 
    22         "bool", "char", "signed char", "unsigned char", "short signed int", "short unsigned int",
     10        "_Bool", "char", "signed char", "unsigned char", "short signed int", "short unsigned int",
    2311        "signed int", "unsigned int", "long signed int", "long unsigned int", "long long signed int",
    24         "long long unsigned int", "float", "double", "long double", "float complex", "double complex",
    25         "long double complex", "float imaginary", "double imaginary", "long double imaginary"
     12        "long long unsigned int", "float", "double", "long double", "float _Complex", "double _Complex",
     13        "long double _Complex", "float _Imaginary", "double _Imaginary", "long double _Imaginary"
    2614    };
    2715
     
    3018}
    3119
    32 bool
    33 BasicType::isInteger() const
    34 {
     20bool BasicType::isInteger() const {
    3521    switch( kind ) {
    36     case Bool:
    37     case Char:
    38     case SignedChar:
    39     case UnsignedChar:
    40     case ShortSignedInt:
    41     case ShortUnsignedInt:
    42     case SignedInt:
    43     case UnsignedInt:
    44     case LongSignedInt:
    45     case LongUnsignedInt:
    46     case LongLongSignedInt:
    47     case LongLongUnsignedInt:
     22      case Bool:
     23      case Char:
     24      case SignedChar:
     25      case UnsignedChar:
     26      case ShortSignedInt:
     27      case ShortUnsignedInt:
     28      case SignedInt:
     29      case UnsignedInt:
     30      case LongSignedInt:
     31      case LongUnsignedInt:
     32      case LongLongSignedInt:
     33      case LongLongUnsignedInt:
    4834        return true;
    4935
    50     case Float:
    51     case Double:
    52     case LongDouble:
    53     case FloatComplex:
    54     case DoubleComplex:
    55     case LongDoubleComplex:
    56     case FloatImaginary:
    57     case DoubleImaginary:
    58     case LongDoubleImaginary:
     36      case Float:
     37      case Double:
     38      case LongDouble:
     39      case FloatComplex:
     40      case DoubleComplex:
     41      case LongDoubleComplex:
     42      case FloatImaginary:
     43      case DoubleImaginary:
     44      case LongDoubleImaginary:
    5945        return false;
    6046
    61     case NUMBER_OF_BASIC_TYPES:
     47      case NUMBER_OF_BASIC_TYPES:
    6248        assert( false );
    6349    }
  • translator/SynTree/Declaration.h

    rd9a0e76 r17cd4eb  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: Declaration.h,v 1.22 2005/08/29 20:59:25 rcbilson Exp $
    5  *
    6  */
    7 
    81#ifndef DECLARATION_H
    92#define DECLARATION_H
     
    158
    169
    17 class Declaration
    18 {
    19 public:
    20     enum StorageClass
    21     { 
     10class Declaration {
     11  public:
     12    enum StorageClass { 
    2213        NoStorageClass,
    2314        Auto,
     
    2718        Fortran
    2819    }; 
    29    
     20
    3021    Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage );
    3122    Declaration( const Declaration &other );
     
    3930    void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; }
    4031    UniqueId get_uniqueId() const { return uniqueId; }
    41    
     32
    4233    void fixUniqueId( void );
    4334    virtual Declaration *clone() const = 0;
     
    4637    virtual void print( std::ostream &os, int indent = 0 ) const = 0;
    4738    virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;
    48    
     39
    4940    static const char* storageClassName[]; 
    50    
     41
    5142    static void dumpIds( std::ostream &os );
    5243    static Declaration *declFromId( UniqueId id );
    53    
    54 private:
     44  private:
    5545    std::string name;
    5646    StorageClass storageClass;
     
    5949};
    6050
    61 class DeclarationWithType : public Declaration
    62 {
    63 public:
     51class DeclarationWithType : public Declaration {
     52  public:
    6453    DeclarationWithType( const std::string &name, StorageClass sc, LinkageSpec::Type linkage );
    6554    DeclarationWithType( const DeclarationWithType &other );
     
    6857    std::string get_mangleName() const { return mangleName; }
    6958    void set_mangleName( std::string newValue ) { mangleName = newValue; }
    70    
     59
    7160    virtual DeclarationWithType *clone() const = 0;
    7261    virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
    73    
     62
    7463    virtual Type *get_type() const = 0;
    7564    virtual void set_type(Type *) = 0;
    76    
    77 private:
    78     // this represents the type with all types and typedefs expanded
    79     // it is generated by SymTab::Validate::Pass2
     65  private:
     66    // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
    8067    std::string mangleName;
    8168};
    8269
    83 class ObjectDecl : public DeclarationWithType
    84 {
     70class ObjectDecl : public DeclarationWithType {
    8571    typedef DeclarationWithType Parent;
    86 
    87 public:
     72  public:
    8873    ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init );
    8974    ObjectDecl( const ObjectDecl &other );
     
    9782    Expression *get_bitfieldWidth() const { return bitfieldWidth; }
    9883    void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
    99    
     84
    10085    virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
    10186    virtual void accept( Visitor &v ) { v.visit( this ); }
     
    10388    virtual void print( std::ostream &os, int indent = 0 ) const;
    10489    virtual void printShort( std::ostream &os, int indent = 0 ) const;
    105    
    106 private:
     90  private:
    10791    Type *type;
    10892    Initializer *init;
     
    11094};
    11195
    112 class FunctionDecl : public DeclarationWithType
    113 {
     96class FunctionDecl : public DeclarationWithType {
    11497    typedef DeclarationWithType Parent;
    115 
    116 public:
     98  public:
    11799    FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline );
    118100    FunctionDecl( const FunctionDecl &other );
     
    130112    std::list< std::string >& get_oldIdents() { return oldIdents; }
    131113    std::list< Declaration* >& get_oldDecls() { return oldDecls; }
    132    
     114
    133115    virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
    134116    virtual void accept( Visitor &v ) { v.visit( this ); }
     
    136118    virtual void print( std::ostream &os, int indent = 0 ) const;
    137119    virtual void printShort( std::ostream &os, int indent = 0 ) const;
    138    
    139 private:
     120  private:
    140121    FunctionType *type;
    141122    CompoundStmt *statements;
     
    145126};
    146127
    147 class NamedTypeDecl : public Declaration
    148 {
     128class NamedTypeDecl : public Declaration {
    149129    typedef Declaration Parent;
    150 
    151 public:
     130  public:
    152131    NamedTypeDecl( const std::string &name, StorageClass sc, Type *type );
    153132    NamedTypeDecl( const TypeDecl &other );
     
    162141    virtual void print( std::ostream &os, int indent = 0 ) const;
    163142    virtual void printShort( std::ostream &os, int indent = 0 ) const;
    164    
    165 protected:
     143  protected:
    166144    virtual std::string typeString() const = 0;
    167    
    168 private:
     145  private:
    169146    Type *base;
    170147    std::list< TypeDecl* > parameters;
     
    172149};
    173150
    174 class TypeDecl : public NamedTypeDecl
    175 {
     151class TypeDecl : public NamedTypeDecl {
    176152    typedef NamedTypeDecl Parent;
    177 
    178 public:
     153  public:
    179154    enum Kind { Any, Dtype, Ftype };
    180155
    181156    TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind );
    182157    TypeDecl( const TypeDecl &other );
    183    
     158
    184159    Kind get_kind() const { return kind; }
    185160
     
    187162    virtual void accept( Visitor &v ) { v.visit( this ); }
    188163    virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    189 
    190 private:
     164  private:
    191165    virtual std::string typeString() const;
    192166    Kind kind;
    193167};
    194    
    195 class TypedefDecl : public NamedTypeDecl
    196 {
     168
     169class TypedefDecl : public NamedTypeDecl {
    197170    typedef NamedTypeDecl Parent;
    198 
    199 public:
     171  public:
    200172    TypedefDecl( const std::string &name, StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
    201173    TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
    202    
     174
    203175    virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }
    204176    virtual void accept( Visitor &v ) { v.visit( this ); }
    205177    virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    206 
    207 private:
    208     virtual std::string typeString() const;
    209 };
    210    
    211 class AggregateDecl : public Declaration
    212 {
     178  private:
     179    virtual std::string typeString() const;
     180};
     181
     182class AggregateDecl : public Declaration {
    213183    typedef Declaration Parent;
    214 
    215 public:
     184  public:
    216185    AggregateDecl( const std::string &name );
    217186    AggregateDecl( const AggregateDecl &other );
     
    220189    std::list<Declaration*>& get_members() { return members; }
    221190    std::list<TypeDecl*>& get_parameters() { return parameters; }
    222    
    223     virtual void print( std::ostream &os, int indent = 0 ) const;
    224     virtual void printShort( std::ostream &os, int indent = 0 ) const;
    225 
    226 protected:
     191
     192    virtual void print( std::ostream &os, int indent = 0 ) const;
     193    virtual void printShort( std::ostream &os, int indent = 0 ) const;
     194  protected:
    227195    virtual std::string typeString() const = 0;
    228    
    229 private:
     196
     197  private:
    230198    std::list<Declaration*> members;
    231199    std::list<TypeDecl*> parameters;
    232200};
    233201
    234 class StructDecl : public AggregateDecl
    235 {
    236     typedef AggregateDecl Parent;
    237 
    238 public:
     202class StructDecl : public AggregateDecl {
     203    typedef AggregateDecl Parent;
     204  public:
    239205    StructDecl( const std::string &name ) : Parent( name ) {}
    240206    StructDecl( const StructDecl &other ) : Parent( other ) {}
    241    
     207
    242208    virtual StructDecl *clone() const { return new StructDecl( *this ); }
    243209    virtual void accept( Visitor &v ) { v.visit( this ); }
    244210    virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    245211
    246 private:
    247     virtual std::string typeString() const;
    248 };
    249    
    250 class UnionDecl : public AggregateDecl
    251 {
    252     typedef AggregateDecl Parent;
    253 
    254 public:
     212  private:
     213    virtual std::string typeString() const;
     214};
     215
     216class UnionDecl : public AggregateDecl {
     217    typedef AggregateDecl Parent;
     218  public:
    255219    UnionDecl( const std::string &name ) : Parent( name ) {}
    256220    UnionDecl( const UnionDecl &other ) : Parent( other ) {}
    257    
     221
    258222    virtual UnionDecl *clone() const { return new UnionDecl( *this ); }
    259223    virtual void accept( Visitor &v ) { v.visit( this ); }
    260224    virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    261 
    262 private:
    263     virtual std::string typeString() const;
    264 };
    265    
    266 class EnumDecl : public AggregateDecl
    267 {
    268     typedef AggregateDecl Parent;
    269 
    270 public:
     225  private:
     226    virtual std::string typeString() const;
     227};
     228
     229class EnumDecl : public AggregateDecl {
     230    typedef AggregateDecl Parent;
     231  public:
    271232    EnumDecl( const std::string &name ) : Parent( name ) {}
    272233    EnumDecl( const EnumDecl &other ) : Parent( other ) {}
    273    
     234
    274235    virtual EnumDecl *clone() const { return new EnumDecl( *this ); }
    275236    virtual void accept( Visitor &v ) { v.visit( this ); }
    276237    virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    277 
    278 private:
    279     virtual std::string typeString() const;
    280 };
    281    
    282 class ContextDecl : public AggregateDecl
    283 {
    284     typedef AggregateDecl Parent;
    285 
    286 public:
     238  private:
     239    virtual std::string typeString() const;
     240};
     241
     242class ContextDecl : public AggregateDecl {
     243    typedef AggregateDecl Parent;
     244  public:
    287245    ContextDecl( const std::string &name ) : Parent( name ) {}
    288246    ContextDecl( const ContextDecl &other ) : Parent( other ) {}
    289    
     247
    290248    virtual ContextDecl *clone() const { return new ContextDecl( *this ); }
    291249    virtual void accept( Visitor &v ) { v.visit( this ); }
    292250    virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    293 
    294 private:
    295     virtual std::string typeString() const;
    296 };
    297    
    298 
    299 
    300 #endif /* #ifndef DECLARATION_H */
     251  private:
     252    virtual std::string typeString() const;
     253};
     254
     255#endif // DECLARATION_H
  • translator/SynTree/NamedTypeDecl.cc

    rd9a0e76 r17cd4eb  
    66NamedTypeDecl::NamedTypeDecl( const std::string &name, StorageClass sc, Type *base )
    77    : Parent( name, sc, LinkageSpec::Cforall ), base( base )
    8 {
    9 }
     8{}
    109
    1110NamedTypeDecl::NamedTypeDecl( const TypeDecl &other )
     
    1615}
    1716
    18 NamedTypeDecl::~NamedTypeDecl()
    19 {
     17NamedTypeDecl::~NamedTypeDecl() {
    2018    delete base;
    2119    deleteAll( parameters );
     
    2321}
    2422
    25 void
    26 NamedTypeDecl::print( std::ostream &os, int indent ) const
    27 {
     23void NamedTypeDecl::print( std::ostream &os, int indent ) const {
    2824    using namespace std;
    2925   
    30     if( get_name() != "" ) {
     26    if ( get_name() != "" ) {
    3127        os << get_name() << ": a ";
    32     }
    33     if( get_storageClass() != NoStorageClass ) {
     28    } // if
     29    if ( get_storageClass() != NoStorageClass ) {
    3430        os << storageClassName[ get_storageClass() ] << ' ';
    35     }
     31    } // if
    3632    os << typeString();
    37     if( base ) {
     33    if ( base ) {
    3834        os << " for ";
    3935        base->print( os, indent );
    40     }
    41     if( !parameters.empty() ) {
     36    } // if
     37    if ( !parameters.empty() ) {
    4238        os << endl << string( indent, ' ' ) << "with parameters" << endl;
    4339        printAll( parameters, os, indent+2 );
    44     }
    45     if( !assertions.empty() ) {
     40    } // if
     41    if ( !assertions.empty() ) {
    4642        os << endl << string( indent, ' ' ) << "with assertions" << endl;
    4743        printAll( assertions, os, indent+2 );
    48     }
     44    } // if
    4945}
    5046
    51 void
    52 NamedTypeDecl::printShort( std::ostream &os, int indent ) const
    53 {
     47void NamedTypeDecl::printShort( std::ostream &os, int indent ) const {
    5448    using namespace std;
    5549   
    56     if( get_name() != "" ) {
     50    if ( get_name() != "" ) {
    5751        os << get_name() << ": a ";
    58     }
    59     if( get_storageClass() != NoStorageClass ) {
     52    } // if
     53    if ( get_storageClass() != NoStorageClass ) {
    6054        os << storageClassName[ get_storageClass() ] << ' ';
    61     }
     55    } // if
    6256    os << typeString();
    63     if( base ) {
     57    if ( base ) {
    6458        os << " for ";
    6559        base->print( os, indent );
    66     }
    67     if( !parameters.empty() ) {
     60    } // if
     61    if ( !parameters.empty() ) {
    6862        os << endl << string( indent, ' ' ) << "with parameters" << endl;
    6963        printAll( parameters, os, indent+2 );
    70     }
     64    } // if
    7165}
    7266
    7367std::string TypedefDecl::typeString() const { return "typedef"; }
    74    
  • translator/SynTree/Type.cc

    rd9a0e76 r17cd4eb  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: Type.cc,v 1.6 2005/08/29 20:59:26 rcbilson Exp $
    5  *
    6  */
    7 
    81#include "SynTree.h"
    92#include "Visitor.h"
     
    125#include "utility.h"
    136
     7const char *BasicType::typeNames[BasicType::NUMBER_OF_BASIC_TYPES] = {
     8    "_Bool",
     9    "char",
     10    "char",
     11    "unsigned char",
     12    "short",
     13    "short unsigned",
     14    "int",
     15    "unsigned int",
     16    "long int",
     17    "long unsigned int",
     18    "long long int",
     19    "long long unsigned int",
     20    "float",
     21    "double",
     22    "long double",
     23    "float _Complex",
     24    "double _Complex",
     25    "long double _Complex",
     26    "float _Imaginary",
     27    "double _Imaginary",
     28    "long double _Imaginary",
     29};
    1430
    15 Type::Type( const Qualifiers &tq )
    16     : tq( tq )
    17 {
    18 }
     31Type::Type( const Qualifiers &tq ) : tq( tq ) {}
    1932
    20 Type::Type( const Type &other )
    21     : tq( other.tq )
    22 {
     33Type::Type( const Type &other ) : tq( other.tq ) {
    2334    cloneAll( other.forall, forall );
    2435}
    2536
    26 Type::~Type()
    27 {
     37Type::~Type() {
    2838    deleteAll( forall );
    2939}
    3040
    31 void
    32 Type::print( std::ostream &os, int indent ) const
    33 {
    34     if( !forall.empty() ) {
     41void Type::print( std::ostream &os, int indent ) const {
     42    if ( !forall.empty() ) {
    3543        os << "forall" << std::endl;
    3644        printAll( forall, os, indent + 4 );
    3745        os << std::string( indent+2, ' ' );
    38     }
    39     if( tq.isConst ) {
     46    } // if
     47    if ( tq.isConst ) {
    4048        os << "const ";
    41     }
    42     if( tq.isVolatile ) {
     49    } // if
     50    if ( tq.isVolatile ) {
    4351        os << "volatile ";
    44     }
    45     if( tq.isRestrict ) {
     52    } // if
     53    if ( tq.isRestrict ) {
    4654        os << "restrict ";
    47     }
    48     if( tq.isLvalue ) {
     55    } // if
     56    if ( tq.isLvalue ) {
    4957        os << "lvalue ";
    50     }
     58    } // if
    5159}
    52 
  • translator/SynTree/Type.h

    rd9a0e76 r17cd4eb  
    9090    }; 
    9191
     92    static const char *typeNames[];                     // string names for basic types, MUST MATCH with Kind
     93
    9294    BasicType( const Type::Qualifiers &tq, Kind bt );
    9395
Note: See TracChangeset for help on using the changeset viewer.