Changeset e39241b for src/CodeGen/GenType.cc
- Timestamp:
- Apr 17, 2017, 5:43:01 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 7069652
- Parents:
- 4ae83a4b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/GenType.cc
r4ae83a4b re39241b 28 28 class GenType : public Visitor { 29 29 public: 30 GenType( const std::string &typeString, bool pretty = false );30 GenType( const std::string &typeString, bool pretty = false, bool genC = false ); 31 31 std::string get_typeString() const { return typeString; } 32 32 void set_typeString( const std::string &newValue ) { typeString = newValue; } … … 48 48 private: 49 49 void handleQualifiers( Type *type ); 50 std::string handleGeneric( ReferenceToType * refType ); 50 51 void genArray( const Type::Qualifiers &qualifiers, Type *base, Expression *dimension, bool isVarLen, bool isStatic ); 51 52 52 53 std::string typeString; 53 54 bool pretty = false; // pretty print 55 bool genC = false; // generating C code? 54 56 }; 55 57 56 std::string genType( Type *type, const std::string &baseString, bool pretty ) {57 GenType gt( baseString, pretty );58 std::string genType( Type *type, const std::string &baseString, bool pretty, bool genC ) { 59 GenType gt( baseString, pretty, genC ); 58 60 std::ostringstream os; 59 61 60 62 if ( ! type->get_attributes().empty() ) { 61 CodeGenerator cg( os, pretty );63 CodeGenerator cg( os, pretty, genC ); 62 64 cg.genAttributes( type->get_attributes() ); 63 65 } // if … … 68 70 69 71 std::string genPrettyType( Type * type, const std::string & baseString ) { 70 return genType( type, baseString, true );72 return genType( type, baseString, true, false ); 71 73 } 72 74 73 GenType::GenType( const std::string &typeString, bool pretty ) : typeString( typeString ), pretty( pretty) {}75 GenType::GenType( const std::string &typeString, bool pretty, bool genC ) : typeString( typeString ), pretty( pretty ), genC( genC ) {} 74 76 75 77 void GenType::visit( VoidType *voidType ) { … … 112 114 } // if 113 115 if ( dimension != 0 ) { 114 CodeGenerator cg( os, pretty );116 CodeGenerator cg( os, pretty, genC ); 115 117 dimension->accept( cg ); 116 118 } else if ( isVarLen ) { … … 166 168 } // if 167 169 } else { 168 CodeGenerator cg( os, pretty );170 CodeGenerator cg( os, pretty, genC ); 169 171 os << "(" ; 170 172 … … 186 188 } 187 189 190 std::string GenType::handleGeneric( ReferenceToType * refType ) { 191 if ( ! refType->get_parameters().empty() ) { 192 std::ostringstream os; 193 CodeGenerator cg( os, pretty, genC ); 194 os << "("; 195 cg.genCommaList( refType->get_parameters().begin(), refType->get_parameters().end() ); 196 os << ") "; 197 return os.str(); 198 } 199 return ""; 200 } 201 188 202 void GenType::visit( StructInstType *structInst ) { 189 typeString = "struct " + structInst->get_name() + " " + typeString; 203 typeString = structInst->get_name() + handleGeneric( structInst ) + " " + typeString; 204 if ( genC ) typeString = "struct " + typeString; 190 205 handleQualifiers( structInst ); 191 206 } 192 207 193 208 void GenType::visit( UnionInstType *unionInst ) { 194 typeString = "union " + unionInst->get_name() + " " + typeString; 209 typeString = unionInst->get_name() + handleGeneric( unionInst ) + " " + typeString; 210 if ( genC ) typeString = "union " + typeString; 195 211 handleQualifiers( unionInst ); 196 212 } 197 213 198 214 void GenType::visit( EnumInstType *enumInst ) { 199 typeString = "enum " + enumInst->get_name() + " " + typeString; 215 typeString = enumInst->get_name() + " " + typeString; 216 if ( genC ) typeString = "enum " + typeString; 200 217 handleQualifiers( enumInst ); 201 218 } … … 207 224 208 225 void GenType::visit( TupleType * tupleType ) { 209 assertf( pretty, "Tuple types should not make it to Code Gen." );226 assertf( ! genC, "Tuple types should not reach code generation." ); 210 227 Visitor::visit( tupleType ); 211 228 unsigned int i = 0; … … 214 231 for ( Type * t : *tupleType ) { 215 232 i++; 216 os << genType( t, "", pretty ) << (i == tupleType->size() ? "" : ", ");233 os << genType( t, "", pretty, genC ) << (i == tupleType->size() ? "" : ", "); 217 234 } 218 235 os << "]";
Note: See TracChangeset
for help on using the changeset viewer.