Changeset 17cd4eb for translator/SynTree
- Timestamp:
- Jan 7, 2015, 6:04:42 PM (11 years ago)
- 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
- Location:
- translator/SynTree
- Files:
-
- 5 edited
-
BasicType.cc (modified) (3 diffs)
-
Declaration.h (modified) (17 diffs)
-
NamedTypeDecl.cc (modified) (3 diffs)
-
Type.cc (modified) (2 diffs)
-
Type.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
translator/SynTree/BasicType.cc
rd9a0e76 r17cd4eb 1 /*2 * This file is part of the Cforall project3 *4 * $Id: BasicType.cc,v 1.10 2005/08/29 20:59:25 rcbilson Exp $5 *6 */7 8 1 #include <cassert> 9 2 … … 11 4 12 5 13 BasicType::BasicType( const Type::Qualifiers &tq, Kind bt ) 14 : Type( tq ), kind( bt ) 15 { 16 } 6 BasicType::BasicType( const Type::Qualifiers &tq, Kind bt ) : Type( tq ), kind( bt ) {} 17 7 18 void 19 BasicType::print( std::ostream &os, int indent ) const 20 { 8 void BasicType::print( std::ostream &os, int indent ) const { 21 9 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", 23 11 "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" 26 14 }; 27 15 … … 30 18 } 31 19 32 bool 33 BasicType::isInteger() const 34 { 20 bool BasicType::isInteger() const { 35 21 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: 48 34 return true; 49 35 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: 59 45 return false; 60 46 61 case NUMBER_OF_BASIC_TYPES:47 case NUMBER_OF_BASIC_TYPES: 62 48 assert( false ); 63 49 } -
translator/SynTree/Declaration.h
rd9a0e76 r17cd4eb 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Declaration.h,v 1.22 2005/08/29 20:59:25 rcbilson Exp $5 *6 */7 8 1 #ifndef DECLARATION_H 9 2 #define DECLARATION_H … … 15 8 16 9 17 class Declaration 18 { 19 public: 20 enum StorageClass 21 { 10 class Declaration { 11 public: 12 enum StorageClass { 22 13 NoStorageClass, 23 14 Auto, … … 27 18 Fortran 28 19 }; 29 20 30 21 Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ); 31 22 Declaration( const Declaration &other ); … … 39 30 void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; } 40 31 UniqueId get_uniqueId() const { return uniqueId; } 41 32 42 33 void fixUniqueId( void ); 43 34 virtual Declaration *clone() const = 0; … … 46 37 virtual void print( std::ostream &os, int indent = 0 ) const = 0; 47 38 virtual void printShort( std::ostream &os, int indent = 0 ) const = 0; 48 39 49 40 static const char* storageClassName[]; 50 41 51 42 static void dumpIds( std::ostream &os ); 52 43 static Declaration *declFromId( UniqueId id ); 53 54 private: 44 private: 55 45 std::string name; 56 46 StorageClass storageClass; … … 59 49 }; 60 50 61 class DeclarationWithType : public Declaration 62 { 63 public: 51 class DeclarationWithType : public Declaration { 52 public: 64 53 DeclarationWithType( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ); 65 54 DeclarationWithType( const DeclarationWithType &other ); … … 68 57 std::string get_mangleName() const { return mangleName; } 69 58 void set_mangleName( std::string newValue ) { mangleName = newValue; } 70 59 71 60 virtual DeclarationWithType *clone() const = 0; 72 61 virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0; 73 62 74 63 virtual Type *get_type() const = 0; 75 64 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 80 67 std::string mangleName; 81 68 }; 82 69 83 class ObjectDecl : public DeclarationWithType 84 { 70 class ObjectDecl : public DeclarationWithType { 85 71 typedef DeclarationWithType Parent; 86 87 public: 72 public: 88 73 ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init ); 89 74 ObjectDecl( const ObjectDecl &other ); … … 97 82 Expression *get_bitfieldWidth() const { return bitfieldWidth; } 98 83 void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; } 99 84 100 85 virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); } 101 86 virtual void accept( Visitor &v ) { v.visit( this ); } … … 103 88 virtual void print( std::ostream &os, int indent = 0 ) const; 104 89 virtual void printShort( std::ostream &os, int indent = 0 ) const; 105 106 private: 90 private: 107 91 Type *type; 108 92 Initializer *init; … … 110 94 }; 111 95 112 class FunctionDecl : public DeclarationWithType 113 { 96 class FunctionDecl : public DeclarationWithType { 114 97 typedef DeclarationWithType Parent; 115 116 public: 98 public: 117 99 FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline ); 118 100 FunctionDecl( const FunctionDecl &other ); … … 130 112 std::list< std::string >& get_oldIdents() { return oldIdents; } 131 113 std::list< Declaration* >& get_oldDecls() { return oldDecls; } 132 114 133 115 virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); } 134 116 virtual void accept( Visitor &v ) { v.visit( this ); } … … 136 118 virtual void print( std::ostream &os, int indent = 0 ) const; 137 119 virtual void printShort( std::ostream &os, int indent = 0 ) const; 138 139 private: 120 private: 140 121 FunctionType *type; 141 122 CompoundStmt *statements; … … 145 126 }; 146 127 147 class NamedTypeDecl : public Declaration 148 { 128 class NamedTypeDecl : public Declaration { 149 129 typedef Declaration Parent; 150 151 public: 130 public: 152 131 NamedTypeDecl( const std::string &name, StorageClass sc, Type *type ); 153 132 NamedTypeDecl( const TypeDecl &other ); … … 162 141 virtual void print( std::ostream &os, int indent = 0 ) const; 163 142 virtual void printShort( std::ostream &os, int indent = 0 ) const; 164 165 protected: 143 protected: 166 144 virtual std::string typeString() const = 0; 167 168 private: 145 private: 169 146 Type *base; 170 147 std::list< TypeDecl* > parameters; … … 172 149 }; 173 150 174 class TypeDecl : public NamedTypeDecl 175 { 151 class TypeDecl : public NamedTypeDecl { 176 152 typedef NamedTypeDecl Parent; 177 178 public: 153 public: 179 154 enum Kind { Any, Dtype, Ftype }; 180 155 181 156 TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind ); 182 157 TypeDecl( const TypeDecl &other ); 183 158 184 159 Kind get_kind() const { return kind; } 185 160 … … 187 162 virtual void accept( Visitor &v ) { v.visit( this ); } 188 163 virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); } 189 190 private: 164 private: 191 165 virtual std::string typeString() const; 192 166 Kind kind; 193 167 }; 194 195 class TypedefDecl : public NamedTypeDecl 196 { 168 169 class TypedefDecl : public NamedTypeDecl { 197 170 typedef NamedTypeDecl Parent; 198 199 public: 171 public: 200 172 TypedefDecl( const std::string &name, StorageClass sc, Type *type ) : Parent( name, sc, type ) {} 201 173 TypedefDecl( const TypedefDecl &other ) : Parent( other ) {} 202 174 203 175 virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); } 204 176 virtual void accept( Visitor &v ) { v.visit( this ); } 205 177 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 182 class AggregateDecl : public Declaration { 213 183 typedef Declaration Parent; 214 215 public: 184 public: 216 185 AggregateDecl( const std::string &name ); 217 186 AggregateDecl( const AggregateDecl &other ); … … 220 189 std::list<Declaration*>& get_members() { return members; } 221 190 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: 227 195 virtual std::string typeString() const = 0; 228 229 private:196 197 private: 230 198 std::list<Declaration*> members; 231 199 std::list<TypeDecl*> parameters; 232 200 }; 233 201 234 class StructDecl : public AggregateDecl 235 { 236 typedef AggregateDecl Parent; 237 238 public: 202 class StructDecl : public AggregateDecl { 203 typedef AggregateDecl Parent; 204 public: 239 205 StructDecl( const std::string &name ) : Parent( name ) {} 240 206 StructDecl( const StructDecl &other ) : Parent( other ) {} 241 207 242 208 virtual StructDecl *clone() const { return new StructDecl( *this ); } 243 209 virtual void accept( Visitor &v ) { v.visit( this ); } 244 210 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } 245 211 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 216 class UnionDecl : public AggregateDecl { 217 typedef AggregateDecl Parent; 218 public: 255 219 UnionDecl( const std::string &name ) : Parent( name ) {} 256 220 UnionDecl( const UnionDecl &other ) : Parent( other ) {} 257 221 258 222 virtual UnionDecl *clone() const { return new UnionDecl( *this ); } 259 223 virtual void accept( Visitor &v ) { v.visit( this ); } 260 224 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 229 class EnumDecl : public AggregateDecl { 230 typedef AggregateDecl Parent; 231 public: 271 232 EnumDecl( const std::string &name ) : Parent( name ) {} 272 233 EnumDecl( const EnumDecl &other ) : Parent( other ) {} 273 234 274 235 virtual EnumDecl *clone() const { return new EnumDecl( *this ); } 275 236 virtual void accept( Visitor &v ) { v.visit( this ); } 276 237 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 242 class ContextDecl : public AggregateDecl { 243 typedef AggregateDecl Parent; 244 public: 287 245 ContextDecl( const std::string &name ) : Parent( name ) {} 288 246 ContextDecl( const ContextDecl &other ) : Parent( other ) {} 289 247 290 248 virtual ContextDecl *clone() const { return new ContextDecl( *this ); } 291 249 virtual void accept( Visitor &v ) { v.visit( this ); } 292 250 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 6 6 NamedTypeDecl::NamedTypeDecl( const std::string &name, StorageClass sc, Type *base ) 7 7 : Parent( name, sc, LinkageSpec::Cforall ), base( base ) 8 { 9 } 8 {} 10 9 11 10 NamedTypeDecl::NamedTypeDecl( const TypeDecl &other ) … … 16 15 } 17 16 18 NamedTypeDecl::~NamedTypeDecl() 19 { 17 NamedTypeDecl::~NamedTypeDecl() { 20 18 delete base; 21 19 deleteAll( parameters ); … … 23 21 } 24 22 25 void 26 NamedTypeDecl::print( std::ostream &os, int indent ) const 27 { 23 void NamedTypeDecl::print( std::ostream &os, int indent ) const { 28 24 using namespace std; 29 25 30 if ( get_name() != "" ) {26 if ( get_name() != "" ) { 31 27 os << get_name() << ": a "; 32 } 33 if ( get_storageClass() != NoStorageClass ) {28 } // if 29 if ( get_storageClass() != NoStorageClass ) { 34 30 os << storageClassName[ get_storageClass() ] << ' '; 35 } 31 } // if 36 32 os << typeString(); 37 if ( base ) {33 if ( base ) { 38 34 os << " for "; 39 35 base->print( os, indent ); 40 } 41 if ( !parameters.empty() ) {36 } // if 37 if ( !parameters.empty() ) { 42 38 os << endl << string( indent, ' ' ) << "with parameters" << endl; 43 39 printAll( parameters, os, indent+2 ); 44 } 45 if ( !assertions.empty() ) {40 } // if 41 if ( !assertions.empty() ) { 46 42 os << endl << string( indent, ' ' ) << "with assertions" << endl; 47 43 printAll( assertions, os, indent+2 ); 48 } 44 } // if 49 45 } 50 46 51 void 52 NamedTypeDecl::printShort( std::ostream &os, int indent ) const 53 { 47 void NamedTypeDecl::printShort( std::ostream &os, int indent ) const { 54 48 using namespace std; 55 49 56 if ( get_name() != "" ) {50 if ( get_name() != "" ) { 57 51 os << get_name() << ": a "; 58 } 59 if ( get_storageClass() != NoStorageClass ) {52 } // if 53 if ( get_storageClass() != NoStorageClass ) { 60 54 os << storageClassName[ get_storageClass() ] << ' '; 61 } 55 } // if 62 56 os << typeString(); 63 if ( base ) {57 if ( base ) { 64 58 os << " for "; 65 59 base->print( os, indent ); 66 } 67 if ( !parameters.empty() ) {60 } // if 61 if ( !parameters.empty() ) { 68 62 os << endl << string( indent, ' ' ) << "with parameters" << endl; 69 63 printAll( parameters, os, indent+2 ); 70 } 64 } // if 71 65 } 72 66 73 67 std::string TypedefDecl::typeString() const { return "typedef"; } 74 -
translator/SynTree/Type.cc
rd9a0e76 r17cd4eb 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Type.cc,v 1.6 2005/08/29 20:59:26 rcbilson Exp $5 *6 */7 8 1 #include "SynTree.h" 9 2 #include "Visitor.h" … … 12 5 #include "utility.h" 13 6 7 const 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 }; 14 30 15 Type::Type( const Qualifiers &tq ) 16 : tq( tq ) 17 { 18 } 31 Type::Type( const Qualifiers &tq ) : tq( tq ) {} 19 32 20 Type::Type( const Type &other ) 21 : tq( other.tq ) 22 { 33 Type::Type( const Type &other ) : tq( other.tq ) { 23 34 cloneAll( other.forall, forall ); 24 35 } 25 36 26 Type::~Type() 27 { 37 Type::~Type() { 28 38 deleteAll( forall ); 29 39 } 30 40 31 void 32 Type::print( std::ostream &os, int indent ) const 33 { 34 if( !forall.empty() ) { 41 void Type::print( std::ostream &os, int indent ) const { 42 if ( !forall.empty() ) { 35 43 os << "forall" << std::endl; 36 44 printAll( forall, os, indent + 4 ); 37 45 os << std::string( indent+2, ' ' ); 38 } 39 if ( tq.isConst ) {46 } // if 47 if ( tq.isConst ) { 40 48 os << "const "; 41 } 42 if ( tq.isVolatile ) {49 } // if 50 if ( tq.isVolatile ) { 43 51 os << "volatile "; 44 } 45 if ( tq.isRestrict ) {52 } // if 53 if ( tq.isRestrict ) { 46 54 os << "restrict "; 47 } 48 if ( tq.isLvalue ) {55 } // if 56 if ( tq.isLvalue ) { 49 57 os << "lvalue "; 50 } 58 } // if 51 59 } 52 -
translator/SynTree/Type.h
rd9a0e76 r17cd4eb 90 90 }; 91 91 92 static const char *typeNames[]; // string names for basic types, MUST MATCH with Kind 93 92 94 BasicType( const Type::Qualifiers &tq, Kind bt ); 93 95
Note:
See TracChangeset
for help on using the changeset viewer.