Changeset 083cf31 for src/SymTab
- Timestamp:
- Jan 7, 2016, 11:28:48 AM (10 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, with_gc
- Children:
- 1e9d87b
- Parents:
- 267cb3d (diff), de91427b (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. - Location:
- src/SymTab
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Indexer.cc
r267cb3d r083cf31 215 215 } else { 216 216 maybeAccept( sizeofExpr->get_expr(), *this ); 217 } 218 } 219 220 void Indexer::visit( AlignofExpr *alignofExpr ) { 221 acceptAllNewScope( alignofExpr->get_results(), *this ); 222 if ( alignofExpr->get_isType() ) { 223 maybeAccept( alignofExpr->get_type(), *this ); 224 } else { 225 maybeAccept( alignofExpr->get_expr(), *this ); 217 226 } 218 227 } -
src/SymTab/Indexer.h
r267cb3d r083cf31 54 54 virtual void visit( ConstantExpr *constantExpr ); 55 55 virtual void visit( SizeofExpr *sizeofExpr ); 56 virtual void visit( AlignofExpr *alignofExpr ); 56 57 virtual void visit( AttrExpr *attrExpr ); 57 58 virtual void visit( LogicalExpr *logicalExpr ); -
src/SymTab/Mangler.cc
r267cb3d r083cf31 30 30 31 31 namespace SymTab { 32 Mangler::Mangler( bool mangleOverridable ) : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ) { 33 } 34 35 //Mangler::Mangler( const Mangler & ) 36 // : mangleName(), varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( isTopLevel ) 37 //{ 38 //} 32 std::string Mangler::mangleType( Type *ty ) { 33 Mangler mangler( false, true ); 34 maybeAccept( ty, mangler ); 35 return mangler.get_mangleName(); 36 } 37 38 Mangler::Mangler( bool mangleOverridable, bool typeMode ) 39 : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ), typeMode( typeMode ) {} 40 39 41 Mangler::Mangler( const Mangler &rhs ) : mangleName() { 40 42 varNums = rhs.varNums; … … 42 44 isTopLevel = rhs.isTopLevel; 43 45 mangleOverridable = rhs.mangleOverridable; 46 typeMode = rhs.typeMode; 44 47 } 45 48 … … 152 155 void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) { 153 156 printQualifiers( refType ); 157 154 158 mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name(); 155 159 } 156 160 161 void Mangler::mangleGenericRef( ReferenceToType *refType, std::string prefix ) { 162 printQualifiers( refType ); 163 164 std::ostringstream oldName( mangleName.str() ); 165 mangleName.clear(); 166 167 mangleName << prefix << refType->get_name(); 168 169 std::list< Expression* >& params = refType->get_parameters(); 170 if ( ! params.empty() ) { 171 mangleName << "_"; 172 for ( std::list< Expression* >::const_iterator param = params.begin(); param != params.end(); ++param ) { 173 TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param ); 174 assert(paramType && "Aggregate parameters should be type expressions"); 175 maybeAccept( paramType->get_type(), *this ); 176 } 177 mangleName << "_"; 178 } 179 180 oldName << mangleName.str().length() << mangleName.str(); 181 mangleName.str( oldName.str() ); 182 } 183 157 184 void Mangler::visit( StructInstType *aggregateUseType ) { 158 mangleRef( aggregateUseType, "s" ); 185 if ( typeMode ) mangleGenericRef( aggregateUseType, "s" ); 186 else mangleRef( aggregateUseType, "s" ); 159 187 } 160 188 161 189 void Mangler::visit( UnionInstType *aggregateUseType ) { 162 mangleRef( aggregateUseType, "u" ); 190 if ( typeMode ) mangleGenericRef( aggregateUseType, "u" ); 191 else mangleRef( aggregateUseType, "u" ); 163 192 } 164 193 … … 209 238 210 239 void Mangler::printQualifiers( Type *type ) { 240 // skip if not including qualifiers 241 if ( typeMode ) return; 242 211 243 if ( ! type->get_forall().empty() ) { 212 244 std::list< std::string > assertionNames; … … 227 259 varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() ); 228 260 for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) { 229 Mangler sub_mangler( mangleOverridable );261 Mangler sub_mangler( mangleOverridable, typeMode ); 230 262 sub_mangler.nextVarNum = nextVarNum; 231 263 sub_mangler.isTopLevel = false; -
src/SymTab/Mangler.h
r267cb3d r083cf31 22 22 23 23 namespace SymTab { 24 /// Mangles names to a unique C identifier 24 25 class Mangler : public Visitor { 25 26 public: 27 /// Mangle syntax tree object; primary interface to clients 26 28 template< typename SynTreeClass > 27 static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true ); // interface to clients 29 static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true ); 30 /// Mangle a type name; secondary interface 31 static std::string mangleType( Type* ty ); 28 32 29 /// using Visitor::visit;30 33 virtual void visit( ObjectDecl *declaration ); 31 34 virtual void visit( FunctionDecl *declaration ); … … 45 48 std::string get_mangleName() { return mangleName.str(); } 46 49 private: 47 std::ostringstream mangleName; 50 std::ostringstream mangleName; ///< Mangled name being constructed 48 51 typedef std::map< std::string, std::pair< int, int > > VarMapType; 49 VarMapType varNums; 50 int nextVarNum; 51 bool isTopLevel; 52 bool mangleOverridable; 52 VarMapType varNums; ///< Map of type variables to indices 53 int nextVarNum; ///< Next type variable index 54 bool isTopLevel; ///< Is the Mangler at the top level 55 bool mangleOverridable; ///< Specially mangle overridable built-in methods 56 bool typeMode; ///< Produce a unique mangled name for a type 53 57 54 Mangler( bool mangleOverridable );58 Mangler( bool mangleOverridable, bool typeMode ); 55 59 Mangler( const Mangler & ); 56 60 57 61 void mangleDecl( DeclarationWithType *declaration ); 58 62 void mangleRef( ReferenceToType *refType, std::string prefix ); 63 void mangleGenericRef( ReferenceToType *refType, std::string prefix ); 59 64 60 65 void printQualifiers( Type *type ); … … 63 68 template< typename SynTreeClass > 64 69 std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable ) { 65 Mangler mangler( mangleOverridable );70 Mangler mangler( mangleOverridable, false ); 66 71 maybeAccept( decl, mangler ); 67 72 return mangler.get_mangleName(); -
src/SymTab/Validate.cc
r267cb3d r083cf31 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri Dec 18 14:32:59 201513 // Update Count : 26 812 // Last Modified On : Thu Jan 07 11:27:49 2016 13 // Update Count : 269 14 14 // 15 15 … … 86 86 }; 87 87 88 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers 88 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers. 89 89 class Pass1 : public Visitor { 90 90 typedef Visitor Parent; … … 161 161 }; 162 162 163 class ReturnChecker : public Visitor { 164 public: 165 /// Checks that return statements return nothing if their return type is void 166 /// and return something if the return type is non-void. 167 static void checkFunctionReturns( std::list< Declaration * > & translationUnit ); 168 169 private: 170 virtual void visit( FunctionDecl * functionDecl ); 171 172 virtual void visit( ReturnStmt * returnStmt ); 173 174 std::list< DeclarationWithType * > returnVals; 175 }; 176 163 177 class EliminateTypedef : public Mutator { 164 178 public: 165 166 179 EliminateTypedef() : scopeLevel( 0 ) {} 180 /// Replaces typedefs by forward declarations 167 181 static void eliminateTypedef( std::list< Declaration * > &translationUnit ); 168 182 private: … … 209 223 acceptAll( translationUnit, pass1 ); 210 224 acceptAll( translationUnit, pass2 ); 225 ReturnChecker::checkFunctionReturns( translationUnit ); 211 226 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 212 227 acceptAll( translationUnit, pass3 ); … … 850 865 } 851 866 867 void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) { 868 ReturnChecker checker; 869 acceptAll( translationUnit, checker ); 870 } 871 872 void ReturnChecker::visit( FunctionDecl * functionDecl ) { 873 std::list< DeclarationWithType * > oldReturnVals = returnVals; 874 returnVals = functionDecl->get_functionType()->get_returnVals(); 875 Visitor::visit( functionDecl ); 876 returnVals = oldReturnVals; 877 } 878 879 void ReturnChecker::visit( ReturnStmt * returnStmt ) { 880 if ( returnStmt->get_expr() == NULL && returnVals.size() != 0 ) { 881 throw SemanticError( "Non-void function returns no values: " , returnStmt ); 882 } else if ( returnStmt->get_expr() != NULL && returnVals.size() == 0 ) { 883 throw SemanticError( "void function returns values: " , returnStmt ); 884 } 885 } 886 887 852 888 bool isTypedef( Declaration *decl ) { 853 889 return dynamic_cast< TypedefDecl * >( decl );
Note:
See TracChangeset
for help on using the changeset viewer.