Changeset 4c03e63
- Timestamp:
- Jun 23, 2017, 4:20:33 PM (6 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:
- 74e58ea3, 7bbba76
- Parents:
- e1c1829 (diff), 88177cf (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. - Files:
-
- 2 added
- 52 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/LaTeXmacros/common.tex
re1c1829 r4c03e63 11 11 %% Created On : Sat Apr 9 10:06:17 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Mon May 15 18:03:29201714 %% Update Count : 3 0213 %% Last Modified On : Sun Jun 18 20:32:32 2017 14 %% Update Count : 319 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 36 36 % Names used in the document. 37 37 38 \newcommand{\CFA}{\textrm{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\xspace} % Cforall symbolic name 38 \newcommand{\CFAIcon}{\textrm{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\xspace} % Cforall symbolic name 39 \newcommand{\CFA}{\protect\CFAIcon} % safe for section/caption 39 40 \newcommand{\CFL}{\textrm{Cforall}\xspace} % Cforall symbolic name 40 41 \newcommand{\Celeven}{\textrm{C11}\xspace} % C11 symbolic name … … 241 242 belowskip=3pt, 242 243 % replace/adjust listing characters that look bad in sanserif 243 literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0. 075ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1244 literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1 244 245 {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1 245 {__}{\_\,\_}2 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2 246 {___}{\_\,\_\,\_}3, 246 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2, 247 247 moredelim=**[is][\color{red}]{®}{®}, % red highlighting ®...® (registered trademark symbol) emacs: C-q M-. 248 248 moredelim=**[is][\color{blue}]{ß}{ß}, % blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_ -
doc/proposals/tagged-struct.txt
re1c1829 r4c03e63 14 14 say which of the possible values is currently stored in the union. The idea 15 15 here is similar, however the possibilities are more open ended. 16 17 Alternate names include virtual structure and abstract structure. 16 18 17 19 … … 36 38 their parent's fields to their field list so they can be upcast. 37 39 40 The type field may be public, if it is then it can be accessed through a 41 simple field access "instance.type". The type field would then be able to be 42 used to access the type object, which contains the information for the type. 43 It may just be a pointer to the type object "*instance.type", although a 44 lookup function could also be used. 45 46 47 Usage: 48 49 The central feature for tagged structs is a checked cast between pointer types 50 to the structures. A cast is successful if the true type of the pointed object 51 is of the type being cast to or any of its children, otherwise the cast 52 returns null. 53 54 The type field should also allow for equality comparison of types. 55 56 Currently, with only these operations (and similar features) the type field 57 could be hidden and the operations given through helper functions. However 58 if the type object has more complex (or even open ended) information in it 59 than providing direct access becomes very valuable. 60 38 61 39 62 Implemenation: 40 63 41 Adding to the field list is a simple matter, should be doable during 42 translation. The type field is just a pointer to a type object. With proper 43 linking we can create a single unique instance of the type object for each 44 declared tagged struct. The instance's address is used as an id for the type. 45 It also holds data about the type, such as its parent's id/a pointer to the 46 parent type object. 64 Adding to the field list would have to be handled during translation. The 65 simple act of adding declarations should not be difficult, althought it might 66 take a bit of work to find the parent's declarations. 47 67 48 The type field could be hidden (as best as C can hide it) or it could be 49 visible to the user with easy access to allow the user to examine the type 50 object directly. 51 52 Direct access is more useful if the data on the type-objects can change, other 53 wise the build in function could handle all cases. Perhaps each root object 54 can specify a type object to use or the type objects are themselves tagged, 55 although there may not be a base case with the latter. 56 57 In the simplest case the type object is a pointer to the parent type object. 58 Additional data could be added, such as a name, or a function pointer to the 59 destructor. 68 Type objects are also simple in to generate, they should just be global 69 (program lifetime) structures. Getting there to be exactly one instance of 70 each allows the pointer to the structure to be used as the type id, and that 71 should be possible to do during linking. 60 72 61 73 … … 94 106 If unions are declared tagged instead of creating a new tagged type, all 95 107 possible values of the union must be of that tagged type or a child type. 108 109 110 Custom Type Objects (Extention): 111 112 Some method to define type objects used within a tree of types. One option is 113 to allow the tree's type object to be specified by the tree root. It would 114 then have to be filled in for each type in the tree, including the root. 115 116 The only required field is the parent field, a pointer to the type object's 117 type. (This is also the only required field on the tagged structure itself.) 118 119 A further extention could allow expanding type objects, so child types could 120 append fields to their parent's feild list. They might need their own type 121 objects at that point, or maybe static checks will be enough to see the 122 minimum field list. -
doc/rob_thesis/intro.tex
re1c1829 r4c03e63 3 3 %====================================================================== 4 4 5 \section{\ CFA Background}5 \section{\protect\CFA Background} 6 6 \label{s:background} 7 7 \CFA \footnote{Pronounced ``C-for-all'', and written \CFA or Cforall.} is a modern non-object-oriented extension to the C programming language. … … 370 370 \end{tabular} 371 371 \end{center} 372 \caption{\label{table:types} The different kinds of type parameters in \ CFA}372 \caption{\label{table:types} The different kinds of type parameters in \protect\CFA} 373 373 \end{table} 374 374 -
doc/rob_thesis/thesis.tex
re1c1829 r4c03e63 66 66 % ,monochrome % toggle black and white mode 67 67 }{xcolor} 68 \PassOptionsToPackage{pdftex}{graphicx} 68 69 \documentclass[letterpaper,12pt,titlepage,oneside,final]{book} 69 70 -
doc/working/exception/translate.c
re1c1829 r4c03e63 1 1 /* Translation rules for exception handling code, from Cforall to C. 2 2 * 3 * Note that these are not final. Names, syntax and the exact translation 4 * will be updated. The first section is the shared definitions, not generated 5 * by the local translations but used by the translated code. 3 * Reminder: This is not final. Besides names and things it is also going very 4 * much for correctness and simplisity over efficiency. 5 * 6 * The first section is the shared definitions, not generated by the local 7 * translations but used by the translated code. 6 8 * 7 9 * Most of these exist only after translation (in C code). The first (the … … 16 18 typedef int exception; 17 19 20 // Will have to be availibe to user. Consider new name. Requires tagged types. 21 forall(dtype parent | tagged(parent), dtype child | tagged(child)) 22 parent *dynamic_cast(child *); 23 18 24 void __throw_terminate(exception except) __attribute__((noreturn)); 19 25 void __rethrow_terminate() __attribute__((noreturn)); … … 116 122 } 117 123 int match1(exception except) { 118 OtherException inner_except; 119 if (dynamic_cast__SomeException(except)) { 120 return 1; 121 } 122 else if ( (inner_except = dynamic_cast__OtherException(except)) && 123 inner_except.priority > 3) { 124 return 2; 125 } 126 else return 0; 124 { 125 if (dynamic_cast__SomeException(except)) { 126 return 1; 127 } 128 } 129 { 130 OtherException err; 131 if ( (err = dynamic_cast__OtherException(except)) && 132 err.priority > 3) { 133 return 2; 134 } 135 } 136 return 0; 127 137 } 128 138 __try_terminate(try1, catch1, match1); … … 151 161 { 152 162 bool handle1(exception except) { 153 OtherException inner_except; 154 if (dynamic_cast__SomeException(except)) { 155 fiddleThing(); 156 return true; 157 } else if (dynamic_cast__OtherException(except) && 158 inner_except.priority > 3) { 159 twiddleWidget(); 160 return true; 161 } else { 162 return false; 163 } 163 { 164 if (dynamic_cast__SomeException(except)) { 165 fiddleThing(); 166 return true; 167 } 168 } 169 { 170 OtherException err; 171 if ( ( err = dynamic_cast__OtherException(except) ) && 172 err.priority > 3) { 173 twiddleWidget(); 174 return true; 175 } 176 } 177 return false; 164 178 } 165 179 struct __try_resume_node data = … … 230 244 } 231 245 bool handle1(exception except) { 232 if (dynamic_cast__SomeException(except)) { 233 fiddleThing(); 234 return true; 235 } else { 236 return false; 237 } 246 { 247 if (dynamic_cast__SomeException(except)) { 248 fiddleThing(); 249 return true; 250 } 251 } 252 return false; 238 253 } 239 254 struct __cleanup_hook generated_name … … 273 288 { 274 289 bool handle1() { 275 if (dynamic_cast__OtherException(except)) { 276 twiddleWidget(); 277 return true; 290 { 291 if (dynamic_cast__OtherException(except)) { 292 twiddleWidget(); 293 return true; 294 } 278 295 } 279 296 return false; … … 297 314 } 298 315 int match1(exception except) { 299 if (dynamic_cast__SomeException(except)) { 300 return 1; 316 { 317 if (dynamic_cast__SomeException(except)) { 318 return 1; 319 } 301 320 } 302 321 return 0; -
src/CodeGen/FixNames.cc
re1c1829 r4c03e63 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 16 07:50:30201713 // Update Count : 1 612 // Last Modified On : Wed Jun 21 14:22:59 2017 13 // Update Count : 19 14 14 // 15 15 … … 114 114 throw SemanticError("Main expected to have 0, 2 or 3 arguments\n", functionDecl); 115 115 } 116 functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new ConstantExpr( Constant ( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), "0") ) ) );116 functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new ConstantExpr( Constant::from_int( 0 ) ) ) ); 117 117 CodeGen::FixMain::registerMain( functionDecl ); 118 118 } -
src/Common/PassVisitor.h
re1c1829 r4c03e63 18 18 // Templated visitor type 19 19 // To use declare a PassVisitor< YOUR VISITOR TYPE > 20 // The visitor type should specify the previsit/postvisit for types that are desired. 20 // The visitor type should specify the previsit/postvisit/premutate/postmutate for types that are desired. 21 // Note: previsit/postvisit/premutate/postmutate must be **public** members 22 // 23 // Several additional features are available through inheritance 24 // | WithTypeSubstitution - provides polymorphic TypeSubstitution * env for the current expression 25 // | WithStmtsToAdd - provides the ability to insert statements before or after the current statement by adding new statements into 26 // stmtsToAddBefore or stmtsToAddAfter respectively. 27 // | WithShortCircuiting - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children 28 // | WithScopes - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable 29 // will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates. 21 30 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 22 31 template< typename pass_type > … … 28 37 PassVisitor(Args &&... args) 29 38 : pass( std::forward<Args>( args )... ) 30 {} 39 { 40 typedef PassVisitor<pass_type> this_t; 41 this_t * const * visitor = visitor_impl(pass, 0); 42 if(visitor) { 43 *const_cast<this_t **>( visitor ) = this; 44 } 45 } 31 46 32 47 virtual ~PassVisitor() = default; … … 86 101 virtual void visit( ConstructorExpr * ctorExpr ) override final; 87 102 virtual void visit( CompoundLiteralExpr *compLitExpr ) override final; 88 virtual void visit( UntypedValofExpr *valofExpr ) override final;89 103 virtual void visit( RangeExpr *rangeExpr ) override final; 90 104 virtual void visit( UntypedTupleExpr *tupleExpr ) override final; … … 172 186 virtual Expression* mutate( ConstructorExpr *ctorExpr ) override final; 173 187 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ) override final; 174 virtual Expression* mutate( UntypedValofExpr *valofExpr ) override final;175 188 virtual Expression* mutate( RangeExpr *rangeExpr ) override final; 176 189 virtual Expression* mutate( UntypedTupleExpr *tupleExpr ) override final; … … 207 220 208 221 private: 222 template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); 223 template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); 224 209 225 template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); } 210 226 template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); } … … 218 234 void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); } 219 235 220 void visitStatementList( std::list< Statement* > &statements ); 236 template< typename func_t > 237 void handleStatementList( std::list< Statement * > & statements, func_t func ); 238 void visitStatementList ( std::list< Statement* > &statements ); 221 239 void mutateStatementList( std::list< Statement* > &statements ); 222 240 223 Statement * visitStatement( Statement * stmt ); 241 template< typename func_t > 242 Statement * handleStatement( Statement * stmt, func_t func ); 243 Statement * visitStatement ( Statement * stmt ); 224 244 Statement * mutateStatement( Statement * stmt ); 225 245 226 void visitExpression( Expression * expr ); 246 template< typename func_t > 247 Expression * handleExpression( Expression * expr, func_t func ); 248 Expression * visitExpression ( Expression * expr ); 227 249 Expression * mutateExpression( Expression * expr ); 228 250 … … 231 253 std::list< Statement* > * get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); } 232 254 std::list< Statement* > * get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); } 233 bool visit_children() { bool* skip = skip_children_impl(pass, 0); return ! (skip && *skip); } 234 void reset_visit() { bool* skip = skip_children_impl(pass, 0); if(skip) *skip = false; } 255 std::list< Declaration* > * get_beforeDecls() { return declsToAddBefore_impl( pass, 0); } 256 std::list< Declaration* > * get_afterDecls () { return declsToAddAfter_impl ( pass, 0); } 257 258 void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); } 235 259 236 260 guard_value_impl init_guard() { … … 271 295 std::list< Statement* > stmtsToAddAfter; 272 296 }; 273 274 297 class WithShortCircuiting { 275 298 protected: … … 278 301 279 302 public: 280 bool skip_children;303 bool_ref visit_children; 281 304 }; 282 305 … … 297 320 }; 298 321 322 template<typename pass_type> 323 class WithVisitorRef { 324 protected: 325 WithVisitorRef() = default; 326 ~WithVisitorRef() = default; 327 328 public: 329 PassVisitor<pass_type> * const visitor; 330 }; 299 331 300 332 #include "PassVisitor.impl.h" -
src/Common/PassVisitor.impl.h
re1c1829 r4c03e63 4 4 __attribute__((unused)) \ 5 5 const auto & guard = init_guard(); \ 6 bool visit_children = true; \ 7 set_visit_children( visit_children ); \ 6 8 call_previsit( node ); \ 7 if( visit_children() ) { \ 8 reset_visit(); \ 9 if( visit_children ) { \ 9 10 10 11 #define VISIT_END( node ) \ … … 15 16 __attribute__((unused)) \ 16 17 const auto & guard = init_guard(); \ 18 bool visit_children = true; \ 19 set_visit_children( visit_children ); \ 17 20 call_premutate( node ); \ 18 if( visit_children() ) { \ 19 reset_visit(); \ 21 if( visit_children ) { \ 20 22 21 23 #define MUTATE_END( type, node ) \ … … 42 44 } 43 45 44 typedef std::list< Statement * > StmtList_t; 45 46 template< typename pass_type > 47 void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) { 46 typedef std::list< Statement * > StmtList_t; 47 typedef std::list< Declaration * > DeclList_t; 48 49 template<typename iterator_t> 50 static inline void splice( iterator_t it, DeclList_t * decls ) { 51 std::transform( 52 decls->begin(), 53 decls->end(), 54 it, 55 [](Declaration * decl) -> auto { 56 return new DeclStmt( noLabels, decl ); 57 } 58 ); 59 decls->clear(); 60 } 61 62 template< typename pass_type > 63 static inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) { 64 65 DeclList_t* beforeDecls = visitor.get_beforeDecls(); 66 DeclList_t* afterDecls = visitor.get_afterDecls(); 67 68 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { 69 // splice in new declarations after previous decl 70 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } 71 72 if ( i == decls.end() ) break; 73 74 // run mutator on declaration 75 maybeAccept( *i, visitor ); 76 77 // splice in new declarations before current decl 78 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 79 } 80 } 81 82 template< typename pass_type > 83 static inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) { 84 85 DeclList_t* beforeDecls = mutator.get_beforeDecls(); 86 DeclList_t* afterDecls = mutator.get_afterDecls(); 87 88 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { 89 // splice in new declarations after previous decl 90 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } 91 92 if ( i == decls.end() ) break; 93 94 // run mutator on declaration 95 *i = maybeMutate( *i, mutator ); 96 97 // splice in new declarations before current decl 98 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 99 } 100 } 101 102 template< typename pass_type > 103 template< typename func_t > 104 void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) { 48 105 SemanticError errors; 49 106 50 107 StmtList_t* beforeStmts = get_beforeStmts(); 51 108 StmtList_t* afterStmts = get_afterStmts(); 109 DeclList_t* beforeDecls = get_beforeDecls(); 110 DeclList_t* afterDecls = get_afterDecls(); 52 111 53 112 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 113 114 if ( !empty( afterDecls ) ) { splice( std::inserter( statements, i ), afterDecls ); } 54 115 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 116 55 117 try { 56 (*i)->accept( *this ); 118 func( *i ); 119 assert(( empty( beforeStmts ) && empty( afterStmts )) 120 || ( empty( beforeDecls ) && empty( afterDecls )) ); 121 57 122 } catch ( SemanticError &e ) { 58 123 errors.append( e ); 59 124 } 125 126 if ( !empty( beforeDecls ) ) { splice( std::inserter( statements, i ), beforeDecls ); } 60 127 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } 61 128 } 62 129 130 if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); } 63 131 if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); } 64 132 if ( !errors.isEmpty() ) { throw errors; } … … 66 134 67 135 template< typename pass_type > 136 void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) { 137 handleStatementList( statements, [this]( Statement * stmt) { 138 stmt->accept( *this ); 139 }); 140 } 141 142 template< typename pass_type > 68 143 void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) { 69 SemanticError errors; 144 handleStatementList( statements, [this]( Statement *& stmt) { 145 stmt = stmt->acceptMutator( *this ); 146 }); 147 } 148 149 150 template< typename pass_type > 151 template< typename func_t > 152 Statement * PassVisitor< pass_type >::handleStatement( Statement * stmt, func_t func ) { 153 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 154 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr () ); 155 ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() ); 156 ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () ); 157 ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() ); 158 ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () ); 159 160 Statement *newStmt = func( stmt ); 70 161 71 162 StmtList_t* beforeStmts = get_beforeStmts(); 72 163 StmtList_t* afterStmts = get_afterStmts(); 73 74 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 75 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 76 try { 77 *i = (*i)->acceptMutator( *this ); 78 } catch ( SemanticError &e ) { 79 errors.append( e ); 80 } 81 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } 82 } 83 84 if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); } 85 if ( !errors.isEmpty() ) { throw errors; } 86 } 87 88 template< typename pass_type > 89 Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) { 90 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 91 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 92 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 93 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 94 95 maybeAccept( stmt, *this ); 96 97 StmtList_t* beforeStmts = get_beforeStmts(); 98 StmtList_t* afterStmts = get_afterStmts(); 99 100 if( empty(beforeStmts) && empty(afterStmts) ) { return stmt; } 164 DeclList_t* beforeDecls = get_beforeDecls(); 165 DeclList_t* afterDecls = get_afterDecls(); 166 167 if( empty(beforeStmts) && empty(afterStmts) && empty(beforeDecls) && empty(afterDecls) ) { return newStmt; } 168 assert(( empty( beforeStmts ) && empty( afterStmts )) 169 || ( empty( beforeDecls ) && empty( afterDecls )) ); 101 170 102 171 CompoundStmt *compound = new CompoundStmt( noLabels ); 172 if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); } 103 173 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 104 compound->get_kids().push_back( stmt ); 174 compound->get_kids().push_back( newStmt ); 175 if( !empty(afterDecls) ) { splice( std::back_inserter( compound->get_kids() ), afterDecls ); } 105 176 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 106 177 return compound; … … 108 179 109 180 template< typename pass_type > 181 Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) { 182 return handleStatement( stmt, [this]( Statement * stmt ) { 183 maybeAccept( stmt, *this ); 184 return stmt; 185 }); 186 } 187 188 template< typename pass_type > 110 189 Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) { 111 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 112 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 113 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 114 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 115 116 Statement *newStmt = maybeMutate( stmt, *this ); 117 118 StmtList_t* beforeStmts = get_beforeStmts(); 119 StmtList_t* afterStmts = get_afterStmts(); 120 121 if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; } 122 123 CompoundStmt *compound = new CompoundStmt( noLabels ); 124 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 125 compound->get_kids().push_back( newStmt ); 126 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 127 return compound; 128 } 129 130 131 132 template< typename pass_type > 133 void PassVisitor< pass_type >::visitExpression( Expression * expr ) { 134 if( !expr ) return; 190 return handleStatement( stmt, [this]( Statement * stmt ) { 191 return maybeMutate( stmt, *this ); 192 }); 193 } 194 195 template< typename pass_type > 196 template< typename func_t > 197 Expression * PassVisitor< pass_type >::handleExpression( Expression * expr, func_t func ) { 198 if( !expr ) return nullptr; 135 199 136 200 auto env_ptr = get_env_ptr(); … … 138 202 *env_ptr = expr->get_env(); 139 203 } 140 // xxx - should env be cloned (or moved) onto the result of the mutate? 141 expr->accept( *this ); 204 205 // should env be cloned (or moved) onto the result of the mutate? 206 return func( expr ); 207 } 208 209 template< typename pass_type > 210 Expression * PassVisitor< pass_type >::visitExpression( Expression * expr ) { 211 return handleExpression(expr, [this]( Expression * expr ) { 212 expr->accept( *this ); 213 return expr; 214 }); 142 215 } 143 216 144 217 template< typename pass_type > 145 218 Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) { 146 if( !expr ) return nullptr; 147 148 auto env_ptr = get_env_ptr(); 149 if ( env_ptr && expr->get_env() ) { 150 *env_ptr = expr->get_env(); 151 } 152 // xxx - should env be cloned (or moved) onto the result of the mutate? 153 return expr->acceptMutator( *this ); 154 } 155 219 return handleExpression(expr, [this]( Expression * expr ) { 220 return expr->acceptMutator( *this ); 221 }); 222 } 156 223 157 224 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ … … 159 226 template< typename pass_type > 160 227 void PassVisitor< pass_type >::visit( ObjectDecl * node ) { 161 VISIT_BODY( node ); 228 VISIT_BODY( node ); 162 229 } 163 230 164 231 template< typename pass_type > 165 232 void PassVisitor< pass_type >::visit( FunctionDecl * node ) { 166 VISIT_BODY( node ); 233 VISIT_BODY( node ); 167 234 } 168 235 169 236 template< typename pass_type > 170 237 void PassVisitor< pass_type >::visit( StructDecl * node ) { 171 VISIT_BODY( node ); 238 VISIT_BODY( node ); 172 239 } 173 240 174 241 template< typename pass_type > 175 242 void PassVisitor< pass_type >::visit( UnionDecl * node ) { 176 VISIT_BODY( node ); 243 VISIT_BODY( node ); 177 244 } 178 245 179 246 template< typename pass_type > 180 247 void PassVisitor< pass_type >::visit( EnumDecl * node ) { 181 VISIT_BODY( node ); 248 VISIT_BODY( node ); 182 249 } 183 250 184 251 template< typename pass_type > 185 252 void PassVisitor< pass_type >::visit( TraitDecl * node ) { 186 VISIT_BODY( node ); 253 VISIT_BODY( node ); 187 254 } 188 255 189 256 template< typename pass_type > 190 257 void PassVisitor< pass_type >::visit( TypeDecl * node ) { 191 VISIT_BODY( node ); 258 VISIT_BODY( node ); 192 259 } 193 260 194 261 template< typename pass_type > 195 262 void PassVisitor< pass_type >::visit( TypedefDecl * node ) { 196 VISIT_BODY( node ); 263 VISIT_BODY( node ); 197 264 } 198 265 199 266 template< typename pass_type > 200 267 void PassVisitor< pass_type >::visit( AsmDecl * node ) { 201 VISIT_BODY( node ); 268 VISIT_BODY( node ); 202 269 } 203 270 … … 231 298 void PassVisitor< pass_type >::visit( ExprStmt * node ) { 232 299 VISIT_START( node ); 233 call_beginScope();234 300 235 301 visitExpression( node->get_expr() ); 236 302 237 call_endScope();238 303 VISIT_END( node ); 239 304 } … … 248 313 } 249 314 315 //-------------------------------------------------------------------------- 316 // AsmStmt 250 317 template< typename pass_type > 251 318 void PassVisitor< pass_type >::visit( AsmStmt * node ) { 252 VISIT_BODY( node ); 319 VISIT_BODY( node ); 320 } 321 322 template< typename pass_type > 323 Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) { 324 MUTATE_BODY( Statement, node ); 253 325 } 254 326 … … 257 329 template< typename pass_type > 258 330 void PassVisitor< pass_type >::visit( IfStmt * node ) { 259 VISIT_START( node ); 331 VISIT_START( node ); 260 332 261 333 visitExpression( node->get_condition() ); … … 268 340 template< typename pass_type > 269 341 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) { 270 MUTATE_START( node ); 342 MUTATE_START( node ); 271 343 272 344 node->set_condition( mutateExpression( node->get_condition() ) ); … … 281 353 template< typename pass_type > 282 354 void PassVisitor< pass_type >::visit( WhileStmt * node ) { 283 VISIT_START( node ); 355 VISIT_START( node ); 284 356 285 357 visitExpression( node->get_condition() ); … … 291 363 template< typename pass_type > 292 364 Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) { 293 MUTATE_START( node ); 365 MUTATE_START( node ); 294 366 295 367 node->set_condition( mutateExpression( node->get_condition() ) ); … … 300 372 301 373 //-------------------------------------------------------------------------- 302 // WhileStmt374 // ForStmt 303 375 template< typename pass_type > 304 376 void PassVisitor< pass_type >::visit( ForStmt * node ) { 305 VISIT_START( node ); 377 VISIT_START( node ); 306 378 307 379 acceptAll( node->get_initialization(), *this ); … … 315 387 template< typename pass_type > 316 388 Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) { 317 MUTATE_START( node ); 389 MUTATE_START( node ); 318 390 319 391 mutateAll( node->get_initialization(), *this ); … … 329 401 template< typename pass_type > 330 402 void PassVisitor< pass_type >::visit( SwitchStmt * node ) { 331 VISIT_START( node ); 403 VISIT_START( node ); 332 404 333 405 visitExpression( node->get_condition() ); … … 339 411 template< typename pass_type > 340 412 Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) { 341 MUTATE_START( node ); 342 413 MUTATE_START( node ); 414 343 415 node->set_condition( mutateExpression( node->get_condition() ) ); 344 416 mutateStatementList( node->get_statements() ); 345 417 346 418 MUTATE_END( Statement, node ); 347 419 } 348 420 349 421 //-------------------------------------------------------------------------- 350 // SwitchStmt422 // CaseStmt 351 423 template< typename pass_type > 352 424 void PassVisitor< pass_type >::visit( CaseStmt * node ) { 353 VISIT_START( node ); 354 425 VISIT_START( node ); 426 355 427 visitExpression( node->get_condition() ); 356 428 visitStatementList( node->get_statements() ); 357 429 358 430 VISIT_END( node ); 359 431 } … … 361 433 template< typename pass_type > 362 434 Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) { 363 MUTATE_START( node ); 364 435 MUTATE_START( node ); 436 365 437 node->set_condition( mutateExpression( node->get_condition() ) ); 366 438 mutateStatementList( node->get_statements() ); 367 439 368 440 MUTATE_END( Statement, node ); 369 441 } 370 442 443 //-------------------------------------------------------------------------- 444 // BranchStmt 371 445 template< typename pass_type > 372 446 void PassVisitor< pass_type >::visit( BranchStmt * node ) { 373 VISIT_BODY( node ); 447 VISIT_BODY( node ); 448 } 449 450 template< typename pass_type > 451 Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) { 452 MUTATE_BODY( Statement, node ); 374 453 } 375 454 … … 415 494 maybeAccept( node->get_block(), *this ); 416 495 acceptAll( node->get_catchers(), *this ); 496 maybeAccept( node->get_finally(), *this ); 417 497 418 498 VISIT_END( node ); … … 425 505 node->set_block( maybeMutate( node->get_block(), *this ) ); 426 506 mutateAll( node->get_catchers(), *this ); 427 507 node->set_finally( maybeMutate( node->get_finally(), *this ) ); 508 428 509 MUTATE_END( Statement, node ); 429 510 } … … 435 516 VISIT_START( node ); 436 517 518 maybeAccept( node->get_decl(), *this ); 519 node->set_cond( visitExpression( node->get_cond() ) ); 437 520 node->set_body( visitStatement( node->get_body() ) ); 438 maybeAccept( node->get_decl(), *this );439 521 440 522 VISIT_END( node ); … … 444 526 Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) { 445 527 MUTATE_START( node ); 446 447 node->set_body( mutateStatement( node->get_body() ) ); 448 node->set_decl( maybeMutate( node->get_decl(), *this ) ); 449 528 529 node->set_decl( maybeMutate( node->get_decl(), *this ) ); 530 node->set_cond( mutateExpression( node->get_cond() ) ); 531 node->set_body( mutateStatement( node->get_body() ) ); 532 450 533 MUTATE_END( Statement, node ); 451 534 } … … 453 536 template< typename pass_type > 454 537 void PassVisitor< pass_type >::visit( FinallyStmt * node ) { 455 VISIT_BODY( node ); 538 VISIT_BODY( node ); 456 539 } 457 540 458 541 template< typename pass_type > 459 542 void PassVisitor< pass_type >::visit( NullStmt * node ) { 460 VISIT_BODY( node ); 543 VISIT_BODY( node ); 461 544 } 462 545 463 546 template< typename pass_type > 464 547 void PassVisitor< pass_type >::visit( DeclStmt * node ) { 465 VISIT_BODY( node ); 548 VISIT_BODY( node ); 466 549 } 467 550 468 551 template< typename pass_type > 469 552 void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) { 470 VISIT_BODY( node ); 553 VISIT_BODY( node ); 471 554 } 472 555 473 556 template< typename pass_type > 474 557 void PassVisitor< pass_type >::visit( ApplicationExpr * node ) { 475 VISIT_BODY( node ); 558 VISIT_BODY( node ); 476 559 } 477 560 … … 502 585 template< typename pass_type > 503 586 void PassVisitor< pass_type >::visit( NameExpr * node ) { 504 VISIT_BODY( node ); 587 VISIT_BODY( node ); 505 588 } 506 589 507 590 template< typename pass_type > 508 591 void PassVisitor< pass_type >::visit( CastExpr * node ) { 509 VISIT_BODY( node ); 592 VISIT_BODY( node ); 510 593 } 511 594 512 595 template< typename pass_type > 513 596 void PassVisitor< pass_type >::visit( AddressExpr * node ) { 514 VISIT_BODY( node ); 597 VISIT_BODY( node ); 515 598 } 516 599 517 600 template< typename pass_type > 518 601 void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) { 519 VISIT_BODY( node ); 602 VISIT_BODY( node ); 520 603 } 521 604 522 605 template< typename pass_type > 523 606 void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) { 524 VISIT_BODY( node ); 607 VISIT_BODY( node ); 525 608 } 526 609 527 610 template< typename pass_type > 528 611 void PassVisitor< pass_type >::visit( MemberExpr * node ) { 529 VISIT_BODY( node ); 612 VISIT_BODY( node ); 530 613 } 531 614 532 615 template< typename pass_type > 533 616 void PassVisitor< pass_type >::visit( VariableExpr * node ) { 534 VISIT_BODY( node ); 617 VISIT_BODY( node ); 535 618 } 536 619 537 620 template< typename pass_type > 538 621 void PassVisitor< pass_type >::visit( ConstantExpr * node ) { 539 VISIT_BODY( node ); 622 VISIT_BODY( node ); 540 623 } 541 624 542 625 template< typename pass_type > 543 626 void PassVisitor< pass_type >::visit( SizeofExpr * node ) { 544 VISIT_BODY( node ); 627 VISIT_BODY( node ); 545 628 } 546 629 547 630 template< typename pass_type > 548 631 void PassVisitor< pass_type >::visit( AlignofExpr * node ) { 549 VISIT_BODY( node ); 632 VISIT_BODY( node ); 550 633 } 551 634 552 635 template< typename pass_type > 553 636 void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) { 554 VISIT_BODY( node ); 637 VISIT_BODY( node ); 555 638 } 556 639 557 640 template< typename pass_type > 558 641 void PassVisitor< pass_type >::visit( OffsetofExpr * node ) { 559 VISIT_BODY( node ); 642 VISIT_BODY( node ); 560 643 } 561 644 562 645 template< typename pass_type > 563 646 void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) { 564 VISIT_BODY( node ); 647 VISIT_BODY( node ); 565 648 } 566 649 567 650 template< typename pass_type > 568 651 void PassVisitor< pass_type >::visit( AttrExpr * node ) { 569 VISIT_BODY( node ); 652 VISIT_BODY( node ); 570 653 } 571 654 572 655 template< typename pass_type > 573 656 void PassVisitor< pass_type >::visit( LogicalExpr * node ) { 574 VISIT_BODY( node ); 657 VISIT_BODY( node ); 575 658 } 576 659 577 660 template< typename pass_type > 578 661 void PassVisitor< pass_type >::visit( ConditionalExpr * node ) { 579 VISIT_BODY( node ); 662 VISIT_BODY( node ); 580 663 } 581 664 582 665 template< typename pass_type > 583 666 void PassVisitor< pass_type >::visit( CommaExpr * node ) { 584 VISIT_BODY( node ); 667 VISIT_BODY( node ); 585 668 } 586 669 587 670 template< typename pass_type > 588 671 void PassVisitor< pass_type >::visit( TypeExpr * node ) { 589 VISIT_BODY( node ); 672 VISIT_BODY( node ); 590 673 } 591 674 592 675 template< typename pass_type > 593 676 void PassVisitor< pass_type >::visit( AsmExpr * node ) { 594 VISIT_BODY( node ); 677 VISIT_BODY( node ); 595 678 } 596 679 597 680 template< typename pass_type > 598 681 void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) { 599 VISIT_BODY( node ); 682 VISIT_BODY( node ); 600 683 } 601 684 602 685 template< typename pass_type > 603 686 void PassVisitor< pass_type >::visit( ConstructorExpr * node ) { 604 VISIT_BODY( node ); 687 VISIT_BODY( node ); 605 688 } 606 689 607 690 template< typename pass_type > 608 691 void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) { 609 VISIT_BODY( node ); 610 } 611 612 template< typename pass_type > 613 void PassVisitor< pass_type >::visit( UntypedValofExpr * node ) { 614 VISIT_BODY( node ); 692 VISIT_BODY( node ); 615 693 } 616 694 617 695 template< typename pass_type > 618 696 void PassVisitor< pass_type >::visit( RangeExpr * node ) { 619 VISIT_BODY( node ); 697 VISIT_BODY( node ); 620 698 } 621 699 622 700 template< typename pass_type > 623 701 void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) { 624 VISIT_BODY( node ); 702 VISIT_BODY( node ); 625 703 } 626 704 627 705 template< typename pass_type > 628 706 void PassVisitor< pass_type >::visit( TupleExpr * node ) { 629 VISIT_BODY( node ); 707 VISIT_BODY( node ); 630 708 } 631 709 632 710 template< typename pass_type > 633 711 void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) { 634 VISIT_BODY( node ); 712 VISIT_BODY( node ); 635 713 } 636 714 637 715 template< typename pass_type > 638 716 void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) { 639 VISIT_BODY( node ); 717 VISIT_BODY( node ); 640 718 } 641 719 … … 659 737 Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) { 660 738 MUTATE_START( node ); 661 739 662 740 // don't want statements from outer CompoundStmts to be added to this StmtExpr 663 741 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); … … 672 750 template< typename pass_type > 673 751 void PassVisitor< pass_type >::visit( UniqueExpr * node ) { 674 VISIT_BODY( node ); 752 VISIT_BODY( node ); 675 753 } 676 754 677 755 template< typename pass_type > 678 756 void PassVisitor< pass_type >::visit( VoidType * node ) { 679 VISIT_BODY( node ); 757 VISIT_BODY( node ); 680 758 } 681 759 682 760 template< typename pass_type > 683 761 void PassVisitor< pass_type >::visit( BasicType * node ) { 684 VISIT_BODY( node ); 762 VISIT_BODY( node ); 685 763 } 686 764 687 765 template< typename pass_type > 688 766 void PassVisitor< pass_type >::visit( PointerType * node ) { 689 VISIT_BODY( node ); 767 VISIT_BODY( node ); 690 768 } 691 769 692 770 template< typename pass_type > 693 771 void PassVisitor< pass_type >::visit( ArrayType * node ) { 694 VISIT_BODY( node ); 772 VISIT_BODY( node ); 695 773 } 696 774 697 775 template< typename pass_type > 698 776 void PassVisitor< pass_type >::visit( FunctionType * node ) { 699 VISIT_BODY( node ); 777 VISIT_BODY( node ); 700 778 } 701 779 702 780 template< typename pass_type > 703 781 void PassVisitor< pass_type >::visit( StructInstType * node ) { 704 VISIT_BODY( node ); 782 VISIT_BODY( node ); 705 783 } 706 784 707 785 template< typename pass_type > 708 786 void PassVisitor< pass_type >::visit( UnionInstType * node ) { 709 VISIT_BODY( node ); 787 VISIT_BODY( node ); 710 788 } 711 789 712 790 template< typename pass_type > 713 791 void PassVisitor< pass_type >::visit( EnumInstType * node ) { 714 VISIT_BODY( node ); 792 VISIT_BODY( node ); 715 793 } 716 794 717 795 template< typename pass_type > 718 796 void PassVisitor< pass_type >::visit( TraitInstType * node ) { 719 VISIT_BODY( node ); 797 VISIT_BODY( node ); 720 798 } 721 799 722 800 template< typename pass_type > 723 801 void PassVisitor< pass_type >::visit( TypeInstType * node ) { 724 VISIT_BODY( node ); 802 VISIT_BODY( node ); 725 803 } 726 804 727 805 template< typename pass_type > 728 806 void PassVisitor< pass_type >::visit( TupleType * node ) { 729 VISIT_BODY( node ); 807 VISIT_BODY( node ); 730 808 } 731 809 732 810 template< typename pass_type > 733 811 void PassVisitor< pass_type >::visit( TypeofType * node ) { 734 VISIT_BODY( node ); 812 VISIT_BODY( node ); 735 813 } 736 814 737 815 template< typename pass_type > 738 816 void PassVisitor< pass_type >::visit( AttrType * node ) { 739 VISIT_BODY( node ); 817 VISIT_BODY( node ); 740 818 } 741 819 742 820 template< typename pass_type > 743 821 void PassVisitor< pass_type >::visit( VarArgsType * node ) { 744 VISIT_BODY( node ); 822 VISIT_BODY( node ); 745 823 } 746 824 747 825 template< typename pass_type > 748 826 void PassVisitor< pass_type >::visit( ZeroType * node ) { 749 VISIT_BODY( node ); 827 VISIT_BODY( node ); 750 828 } 751 829 752 830 template< typename pass_type > 753 831 void PassVisitor< pass_type >::visit( OneType * node ) { 754 VISIT_BODY( node ); 832 VISIT_BODY( node ); 755 833 } 756 834 … … 777 855 template< typename pass_type > 778 856 void PassVisitor< pass_type >::visit( ListInit * node ) { 779 VISIT_BODY( node ); 857 VISIT_BODY( node ); 780 858 } 781 859 782 860 template< typename pass_type > 783 861 void PassVisitor< pass_type >::visit( ConstructorInit * node ) { 784 VISIT_BODY( node ); 862 VISIT_BODY( node ); 785 863 } 786 864 787 865 template< typename pass_type > 788 866 void PassVisitor< pass_type >::visit( Subrange * node ) { 789 VISIT_BODY( node ); 867 VISIT_BODY( node ); 790 868 } 791 869 792 870 template< typename pass_type > 793 871 void PassVisitor< pass_type >::visit( Constant * node ) { 794 VISIT_BODY( node ); 872 VISIT_BODY( node ); 795 873 } 796 874 … … 843 921 844 922 template< typename pass_type > 845 Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {846 MUTATE_BODY( Statement, node );847 }848 849 template< typename pass_type >850 Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {851 MUTATE_BODY( Statement, node );852 }853 854 template< typename pass_type >855 923 Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) { 856 924 MUTATE_BODY( Statement, node ); … … 988 1056 989 1057 template< typename pass_type > 990 Expression * PassVisitor< pass_type >::mutate( UntypedValofExpr * node ) {991 MUTATE_BODY( Expression, node );992 }993 994 template< typename pass_type >995 1058 Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) { 996 1059 MUTATE_BODY( Expression, node ); -
src/Common/PassVisitor.proto.h
re1c1829 r4c03e63 1 1 #pragma once 2 3 template<typename pass_type> 4 class PassVisitor; 2 5 3 6 typedef std::function<void( void * )> cleanup_func_t; … … 31 34 32 35 typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t; 36 37 class bool_ref { 38 public: 39 bool_ref() = default; 40 ~bool_ref() = default; 41 42 operator bool() { return *m_ref; } 43 bool operator=( bool val ) { return *m_ref = val; } 44 45 private: 46 47 template<typename pass> 48 friend class PassVisitor; 49 50 void set( bool & val ) { m_ref = &val; }; 51 52 bool * m_ref; 53 }; 33 54 34 55 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- … … 112 133 FIELD_PTR( std::list< Statement* >, stmtsToAddBefore ) 113 134 FIELD_PTR( std::list< Statement* >, stmtsToAddAfter ) 114 FIELD_PTR( bool, skip_children ) 135 FIELD_PTR( std::list< Declaration* >, declsToAddBefore ) 136 FIELD_PTR( std::list< Declaration* >, declsToAddAfter ) 137 FIELD_PTR( bool_ref, visit_children ) 115 138 FIELD_PTR( at_cleanup_t, at_cleanup ) 139 FIELD_PTR( PassVisitor<pass_type> * const, visitor ) -
src/GenPoly/Box.cc
re1c1829 r4c03e63 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 13 09:26:38201713 // Update Count : 34 112 // Last Modified On : Wed Jun 21 15:49:59 2017 13 // Update Count : 346 14 14 // 15 15 … … 62 62 namespace GenPoly { 63 63 namespace { 64 const std::list<Label> noLabels;65 66 64 FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars ); 67 65 … … 343 341 Statement *makeAlignTo( Expression *lhs, Expression *rhs ) { 344 342 // check that the lhs is zeroed out to the level of rhs 345 Expression *ifCond = makeOp( "?&?", lhs, makeOp( "?-?", rhs, new ConstantExpr( Constant ( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), "1") ) ) );343 Expression *ifCond = makeOp( "?&?", lhs, makeOp( "?-?", rhs, new ConstantExpr( Constant::from_ulong( 1 ) ) ) ); 346 344 // if not aligned, increment to alignment 347 345 Expression *ifExpr = makeOp( "?+=?", lhs->clone(), makeOp( "?-?", rhs->clone(), ifCond->clone() ) ); … … 386 384 387 385 // initialize size and alignment to 0 and 1 (will have at least one member to re-edit size) 388 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant ( sizeAlignType->clone(), "0") ) ) );389 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant ( sizeAlignType->clone(), "1") ) ) );386 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant::from_ulong( 0 ) ) ) ); 387 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) ); 390 388 unsigned long n_members = 0; 391 389 bool firstMember = true; … … 443 441 444 442 // calculate union layout in function body 445 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant ( sizeAlignType->clone(), "1") ) ) );446 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant ( sizeAlignType->clone(), "1") ) ) );443 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( sizeParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) ); 444 addExpr( layoutDecl->get_statements(), makeOp( "?=?", derefVar( alignParam ), new ConstantExpr( Constant::from_ulong( 1 ) ) ) ); 447 445 for ( std::list< Declaration* >::const_iterator member = unionDecl->get_members().begin(); member != unionDecl->get_members().end(); ++member ) { 448 446 DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ); … … 1566 1564 /// Returns an index expression into the offset array for a type 1567 1565 Expression *makeOffsetIndex( Type *objectType, long i ) { 1568 std::stringstream offset_namer; 1569 offset_namer << i; 1570 ConstantExpr *fieldIndex = new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), offset_namer.str() ) ); 1566 ConstantExpr *fieldIndex = new ConstantExpr( Constant::from_ulong( i ) ); 1571 1567 UntypedExpr *fieldOffset = new UntypedExpr( new NameExpr( "?[?]" ) ); 1572 1568 fieldOffset->get_args().push_back( new NameExpr( offsetofName( mangleType( objectType ) ) ) ); … … 1781 1777 // all union members are at offset zero 1782 1778 delete offsetofExpr; 1783 return new ConstantExpr( Constant ( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), "0") );1779 return new ConstantExpr( Constant::from_ulong( 0 ) ); 1784 1780 } else return offsetofExpr; 1785 1781 } -
src/GenPoly/CopyParams.cc
re1c1829 r4c03e63 45 45 46 46 CopyParams::CopyParams() : namer( "_cp" ) {} 47 48 static const std::list< Label > noLabels;49 47 50 48 void CopyParams::visit( FunctionDecl *funcDecl ) { -
src/GenPoly/DeclMutator.cc
re1c1829 r4c03e63 9 9 // Author : Aaron B. Moss 10 10 // Created On : Fri Nov 27 14:44:00 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Aug 4 11:16:43 201613 // Update Count : 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Jun 22 13:49:00 2017 13 // Update Count : 4 14 14 // 15 15 … … 20 20 21 21 namespace GenPoly { 22 namespace {23 const std::list<Label> noLabels;24 }25 26 22 DeclMutator::DeclMutator() : Mutator(), declsToAdd(1), declsToAddAfter(1) {} 27 23 28 24 DeclMutator::~DeclMutator() {} 29 25 30 26 void DeclMutator::mutateDeclarationList( std::list< Declaration* > &decls ) { 31 27 for ( std::list< Declaration* >::iterator decl = decls.begin(); ; ++decl ) { … … 34 30 35 31 if ( decl == decls.end() ) break; 36 32 37 33 // run mutator on declaration 38 34 *decl = maybeMutate( *decl, *this ); … … 55 51 newBack->splice( newBack->end(), *back ); 56 52 declsToAdd.pop_back(); 57 53 58 54 back = declsToAddAfter.rbegin(); 59 55 newBack = back + 1; … … 66 62 CompoundStmt *compoundStmt = dynamic_cast< CompoundStmt* >(stmt); 67 63 if ( compoundStmt ) return mutate( compoundStmt ); 68 64 69 65 doBeginScope(); 70 66 71 67 // run mutator on statement 72 68 stmt = maybeMutate( stmt, *this ); … … 102 98 doBeginScope(); 103 99 104 100 105 101 for ( std::list< Statement* >::iterator stmt = stmts.begin(); ; ++stmt ) { 106 102 // add any new declarations after the previous statement … … 112 108 113 109 if ( stmt == stmts.end() ) break; 114 110 115 111 // run mutator on statement 116 112 *stmt = maybeMutate( *stmt, *this ); … … 123 119 declsToAdd.back().clear(); 124 120 } 125 121 126 122 doEndScope(); 127 123 } … … 139 135 return compoundStmt; 140 136 } 141 137 142 138 Statement* DeclMutator::mutate(IfStmt *ifStmt) { 143 139 ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) ); … … 146 142 return ifStmt; 147 143 } 148 144 149 145 Statement* DeclMutator::mutate(WhileStmt *whileStmt) { 150 146 whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) ); … … 152 148 return whileStmt; 153 149 } 154 150 155 151 Statement* DeclMutator::mutate(ForStmt *forStmt) { 156 152 mutateAll( forStmt->get_initialization(), *this ); … … 160 156 return forStmt; 161 157 } 162 158 163 159 Statement* DeclMutator::mutate(SwitchStmt *switchStmt) { 164 160 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); … … 166 162 return switchStmt; 167 163 } 168 164 169 165 Statement* DeclMutator::mutate(CaseStmt *caseStmt) { 170 166 caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) ); … … 172 168 return caseStmt; 173 169 } 174 170 175 171 Statement* DeclMutator::mutate(TryStmt *tryStmt) { 176 172 tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) ); … … 179 175 return tryStmt; 180 176 } 181 177 182 178 Statement* DeclMutator::mutate(CatchStmt *catchStmt) { 183 179 catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) ); 180 catchStmt->set_cond( maybeMutate( catchStmt->get_cond(), *this ) ); 184 181 catchStmt->set_body( mutateStatement( catchStmt->get_body() ) ); 185 182 return catchStmt; -
src/GenPoly/Lvalue.cc
re1c1829 r4c03e63 35 35 namespace GenPoly { 36 36 namespace { 37 const std::list<Label> noLabels;38 39 37 /// Replace uses of lvalue returns with appropriate pointers 40 38 class Pass1 : public Mutator { -
src/GenPoly/PolyMutator.cc
re1c1829 r4c03e63 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Aug 4 11:26:22 201613 // Update Count : 1 611 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Jun 22 13:47:00 2017 13 // Update Count : 17 14 14 // 15 15 … … 123 123 124 124 Statement * PolyMutator::mutate(TryStmt *tryStmt) { 125 tryStmt->set_block( 125 tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) ); 126 126 mutateAll( tryStmt->get_catchers(), *this ); 127 tryStmt->set_finally( maybeMutate( tryStmt->get_finally(), *this ) ); 127 128 return tryStmt; 128 129 } 129 130 130 131 Statement * PolyMutator::mutate(CatchStmt *cathStmt) { 131 cathStmt->set_body( mutateStatement( cathStmt->get_body() ) ); 132 cathStmt->set_decl( maybeMutate( cathStmt->get_decl(), *this ) ); 132 cathStmt->set_body( mutateStatement( cathStmt->get_body() ) ); 133 cathStmt->set_cond( maybeMutate( cathStmt->get_cond(), *this ) ); 134 cathStmt->set_decl( maybeMutate( cathStmt->get_decl(), *this ) ); 133 135 return cathStmt; 134 136 } -
src/GenPoly/Specialize.cc
re1c1829 r4c03e63 99 99 if ( FunctionType * fftype = getFunctionType( formalType ) ) { 100 100 if ( fftype->isTtype() ) return true; 101 // conversion of 0 (null) to function type does not require tuple specialization 102 if ( dynamic_cast< ZeroType * >( actualType ) ) return false; 101 103 FunctionType * aftype = getFunctionType( actualType ); 102 104 assertf( aftype, "formal type is a function type, but actual type is not." ); -
src/InitTweak/FixGlobalInit.cc
re1c1829 r4c03e63 26 26 27 27 namespace InitTweak { 28 namespace {29 const std::list<Label> noLabels;30 }31 32 28 class GlobalFixer : public Visitor { 33 29 public: -
src/InitTweak/FixInit.cc
re1c1829 r4c03e63 10 10 // Created On : Wed Jan 13 16:29:30 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 17 09:13:47201713 // Update Count : 7 112 // Last Modified On : Wed Jun 21 17:35:05 2017 13 // Update Count : 74 14 14 // 15 15 … … 56 56 typedef std::unordered_map< int, int > UnqCount; 57 57 58 class InsertImplicitCalls {58 class InsertImplicitCalls : public WithTypeSubstitution { 59 59 public: 60 60 /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which … … 69 69 // collects environments for relevant nodes 70 70 EnvMap & envMap; 71 TypeSubstitution * env; //Magically populated by the PassVisitor72 71 }; 73 72 … … 192 191 }; 193 192 194 class FixInit {193 class FixInit : public WithStmtsToAdd { 195 194 public: 196 195 /// expand each object declaration to use its constructor after it is declared. … … 200 199 201 200 std::list< Declaration * > staticDtorDecls; 202 std::list< Statement * > stmtsToAddAfter; // found by PassVisitor203 201 }; 204 202 … … 726 724 // static bool __objName_uninitialized = true 727 725 BasicType * boolType = new BasicType( Type::Qualifiers(), BasicType::Bool ); 728 SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant ( boolType->clone(), "1") ), noDesignators );726 SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant::from_int( 1 ) ), noDesignators ); 729 727 ObjectDecl * isUninitializedVar = new ObjectDecl( objDecl->get_mangleName() + "_uninitialized", Type::StorageClasses( Type::Static ), LinkageSpec::Cforall, 0, boolType, boolInitExpr ); 730 728 isUninitializedVar->fixUniqueId(); … … 733 731 UntypedExpr * setTrue = new UntypedExpr( new NameExpr( "?=?" ) ); 734 732 setTrue->get_args().push_back( new VariableExpr( isUninitializedVar ) ); 735 setTrue->get_args().push_back( new ConstantExpr( Constant ( boolType->clone(), "0") ) );733 setTrue->get_args().push_back( new ConstantExpr( Constant::from_int( 0 ) ) ); 736 734 737 735 // generate body of if -
src/InitTweak/GenInit.cc
re1c1829 r4c03e63 21 21 22 22 #include "Common/PassVisitor.h" 23 24 #include "GenPoly/DeclMutator.h" 25 #include "GenPoly/PolyMutator.h" 26 #include "GenPoly/ScopedSet.h" 27 28 #include "ResolvExpr/typeops.h" 23 29 24 30 #include "SynTree/Declaration.h" … … 31 37 #include "SymTab/Autogen.h" 32 38 #include "SymTab/Mangler.h" 33 34 #include "GenPoly/DeclMutator.h"35 #include "GenPoly/PolyMutator.h"36 #include "GenPoly/ScopedSet.h"37 38 #include "ResolvExpr/typeops.h"39 39 40 40 namespace InitTweak { -
src/InitTweak/InitTweak.cc
re1c1829 r4c03e63 474 474 public: 475 475 ConstExprChecker() : isConstExpr( true ) {} 476 477 using Visitor::visit; 476 478 477 479 virtual void visit( __attribute((unused)) ApplicationExpr *applicationExpr ) { isConstExpr = false; } -
src/Parser/ExpressionNode.cc
re1c1829 r4c03e63 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 17 21:31:01201713 // Update Count : 5 2712 // Last Modified On : Wed Jun 21 16:44:46 2017 13 // Update Count : 541 14 14 // 15 15 … … 62 62 bool dec = true, Unsigned = false; // decimal, unsigned constant 63 63 int size; // 0 => int, 1 => long, 2 => long long 64 unsigned long long v; // converted integral value64 unsigned long long int v; // converted integral value 65 65 size_t last = str.length() - 1; // last character of constant 66 66 … … 118 118 } // if 119 119 120 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str ) );120 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str, v ) ); 121 121 delete &str; // created by lex 122 122 return ret; … … 133 133 // floating-point constant has minimum of 2 characters: 1. or .1 134 134 size_t last = str.length() - 1; 135 double v; 136 137 sscanf( str.c_str(), "%lg", &v ); 135 138 136 139 if ( checkI( str[last] ) ) { // imaginary ? … … 150 153 } // if 151 154 152 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str ) );155 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str, v ) ); 153 156 delete &str; // created by lex 154 157 return ret; … … 156 159 157 160 Expression *build_constantChar( const std::string & str ) { 158 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str ) );161 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) ); 159 162 delete &str; // created by lex 160 163 return ret; … … 164 167 // string should probably be a primitive type 165 168 ArrayType *at = new ArrayType( emptyQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), 166 new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::UnsignedInt ), 167 toString( str.size()+1-2 ) ) ), // +1 for '\0' and -2 for '"' 169 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 168 170 false, false ); 169 ConstantExpr * ret = new ConstantExpr( Constant( at, str ) ); 171 // constant 0 is ignored for pure string value 172 ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); 170 173 delete &str; // created by lex 171 174 return ret; … … 173 176 174 177 Expression *build_constantZeroOne( const std::string & str ) { 175 Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( emptyQualifiers ) : (Type*)new OneType( emptyQualifiers ), str ) ); 178 Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( emptyQualifiers ) : (Type*)new OneType( emptyQualifiers ), str, 179 str == "0" ? (unsigned long long int)0 : (unsigned long long int)1 ) ); 176 180 delete &str; // created by lex 177 181 return ret; … … 184 188 std::stringstream ss( str ); 185 189 ss >> a >> dot >> b; 186 UntypedMemberExpr * ret = new UntypedMemberExpr( 187 new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::SignedInt ), toString( b ) ) ), 188 new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::SignedInt ), toString( a ) ) ) ); 190 UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) ); 189 191 delete &str; 190 192 return ret; … … 346 348 347 349 Expression *build_valexpr( StatementNode *s ) { 348 return new UntypedValofExpr( maybeMoveBuild< Statement >(s), nullptr);350 return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ) ); 349 351 } 350 352 Expression *build_typevalue( DeclarationNode *decl ) { -
src/Parser/ParseNode.h
re1c1829 r4c03e63 415 415 result->location = cur->location; 416 416 * out++ = result; 417 } else { 418 assertf(false, "buildList unknown type"); 417 419 } // if 418 420 } catch( SemanticError &e ) { -
src/Parser/StatementNode.cc
re1c1829 r4c03e63 168 168 169 169 Statement *build_resume_at( ExpressionNode *ctl, ExpressionNode *target ) { 170 std::list< Expression * > exps; 171 buildMoveList( ctl, exps ); 172 assertf( exps.size() < 2, "This means we are leaking memory"); 173 return new ThrowStmt( noLabels, ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr ); 170 (void)ctl; 171 (void)target; 172 assertf( false, "resume at (non-local throw) is not yet supported," ); 174 173 } 175 174 176 175 Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) { 177 std::list< Statement * > branches;178 buildMoveList< Statement, StatementNode >( catch_stmt, branches );176 std::list< CatchStmt * > branches; 177 buildMoveList< CatchStmt, StatementNode >( catch_stmt, branches ); 179 178 CompoundStmt *tryBlock = safe_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt)); 180 179 FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) ); -
src/Parser/parseutility.cc
re1c1829 r4c03e63 10 10 // Created On : Sat May 16 15:30:39 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 14 23:45:03 201613 // Update Count : 312 // Last Modified On : Wed Jun 21 15:33:41 2017 13 // Update Count : 5 14 14 // 15 15 … … 26 26 UntypedExpr *comparison = new UntypedExpr( new NameExpr( "?!=?" ) ); 27 27 comparison->get_args().push_back( orig ); 28 comparison->get_args().push_back( new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0" ) ) );28 comparison->get_args().push_back( new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0", (unsigned long long int)0 ) ) ); 29 29 return new CastExpr( comparison, new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 30 30 } -
src/SymTab/Autogen.h
re1c1829 r4c03e63 10 10 // Created On : Sun May 17 21:53:34 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 17 09:10:41201713 // Update Count : 912 // Last Modified On : Wed Jun 21 17:25:26 2017 13 // Update Count : 14 14 14 // 15 15 … … 25 25 26 26 namespace SymTab { 27 28 27 /// Generates assignment operators, constructors, and destructor for aggregate types as required 28 void autogenerateRoutines( std::list< Declaration * > &translationUnit ); 29 29 30 31 30 /// returns true if obj's name is the empty string and it has a bitfield width 31 bool isUnnamedBitfield( ObjectDecl * obj ); 32 32 33 34 35 33 /// size_t type - set when size_t typedef is seen. Useful in a few places, 34 /// such as in determining array dimension type 35 extern Type * SizeType; 36 36 37 38 37 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. 38 template< typename OutputIterator > 39 39 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true ); 40 40 41 42 43 41 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types. 42 /// optionally returns a statement which must be inserted prior to the containing loop, if there is one 43 template< typename OutputIterator > 44 44 Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) { 45 46 47 45 // want to be able to generate assignment, ctor, and dtor generically, 46 // so fname is either ?=?, ?{}, or ^?{} 47 UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) ); 48 48 49 50 51 52 53 54 55 56 57 58 59 49 // do something special for unnamed members 50 dstParam = new AddressExpr( dstParam ); 51 if ( addCast ) { 52 // cast to T* with qualifiers removed, so that qualified objects can be constructed 53 // and destructed with the same functions as non-qualified objects. 54 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument 55 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever 56 // remove lvalue as a qualifier, this can change to 57 // type->get_qualifiers() = Type::Qualifiers(); 58 assert( type ); 59 Type * castType = type->clone(); 60 60 // castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, false); 61 62 63 64 65 61 castType->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic ); 62 castType->set_lvalue( true ); // xxx - might not need this 63 dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) ); 64 } 65 fExpr->get_args().push_back( dstParam ); 66 66 67 67 Statement * listInit = srcParam.buildListInit( fExpr ); 68 68 69 70 69 std::list< Expression * > args = *++srcParam; 70 fExpr->get_args().splice( fExpr->get_args().end(), args ); 71 71 72 72 *out++ = new ExprStmt( noLabels, fExpr ); 73 73 74 74 srcParam.clearArrayIndices(); 75 75 76 return listInit; 76 return listInit; 77 } 78 79 /// Store in out a loop which calls fname on each element of the array with srcParam and dstParam as arguments. 80 /// If forward is true, loop goes from 0 to N-1, else N-1 to 0 81 template< typename OutputIterator > 82 void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool addCast = false, bool forward = true ) { 83 static UniqueName indexName( "_index" ); 84 85 // for a flexible array member nothing is done -- user must define own assignment 86 if ( ! array->get_dimension() ) return ; 87 88 Expression * begin, * end, * update, * cmp; 89 if ( forward ) { 90 // generate: for ( int i = 0; i < N; ++i ) 91 begin = new ConstantExpr( Constant::from_int( 0 ) ); 92 end = array->get_dimension()->clone(); 93 cmp = new NameExpr( "?<?" ); 94 update = new NameExpr( "++?" ); 95 } else { 96 // generate: for ( int i = N-1; i >= 0; --i ) 97 begin = new UntypedExpr( new NameExpr( "?-?" ) ); 98 ((UntypedExpr*)begin)->get_args().push_back( array->get_dimension()->clone() ); 99 ((UntypedExpr*)begin)->get_args().push_back( new ConstantExpr( Constant::from_int( 1 ) ) ); 100 end = new ConstantExpr( Constant::from_int( 0 ) ); 101 cmp = new NameExpr( "?>=?" ); 102 update = new NameExpr( "--?" ); 77 103 } 78 104 79 /// Store in out a loop which calls fname on each element of the array with srcParam and dstParam as arguments. 80 /// If forward is true, loop goes from 0 to N-1, else N-1 to 0 81 template< typename OutputIterator > 82 void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool addCast = false, bool forward = true ) { 83 static UniqueName indexName( "_index" ); 105 ObjectDecl *index = new ObjectDecl( indexName.newName(), Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), new SingleInit( begin, std::list<Expression*>() ) ); 84 106 85 // for a flexible array member nothing is done -- user must define own assignment 86 if ( ! array->get_dimension() ) return ; 107 UntypedExpr *cond = new UntypedExpr( cmp ); 108 cond->get_args().push_back( new VariableExpr( index ) ); 109 cond->get_args().push_back( end ); 87 110 88 Expression * begin, * end, * update, * cmp; 89 if ( forward ) { 90 // generate: for ( int i = 0; i < 0; ++i ) 91 begin = new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0" ) ); 92 end = array->get_dimension()->clone(); 93 cmp = new NameExpr( "?<?" ); 94 update = new NameExpr( "++?" ); 95 } else { 96 // generate: for ( int i = N-1; i >= 0; --i ) 97 begin = new UntypedExpr( new NameExpr( "?-?" ) ); 98 ((UntypedExpr*)begin)->get_args().push_back( array->get_dimension()->clone() ); 99 ((UntypedExpr*)begin)->get_args().push_back( new ConstantExpr( Constant( new OneType( emptyQualifiers ), "1" ) ) ); 100 end = new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0" ) ); 101 cmp = new NameExpr( "?>=?" ); 102 update = new NameExpr( "--?" ); 103 } 111 UntypedExpr *inc = new UntypedExpr( update ); 112 inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) ); 104 113 105 ObjectDecl *index = new ObjectDecl( indexName.newName(), Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), new SingleInit( begin, std::list<Expression*>() ) ); 114 UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?[?]" ) ); 115 dstIndex->get_args().push_back( dstParam ); 116 dstIndex->get_args().push_back( new VariableExpr( index ) ); 117 dstParam = dstIndex; 106 118 107 UntypedExpr *cond = new UntypedExpr( cmp );108 cond->get_args().push_back( new VariableExpr( index ) );109 cond->get_args().push_back( end);119 // srcParam must keep track of the array indices to build the 120 // source parameter and/or array list initializer 121 srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone() ); 110 122 111 UntypedExpr *inc = new UntypedExpr( update ); 112 inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) ); 123 // for stmt's body, eventually containing call 124 CompoundStmt * body = new CompoundStmt( noLabels ); 125 Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward ); 113 126 114 UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?[?]" ) ); 115 dstIndex->get_args().push_back( dstParam ); 116 dstIndex->get_args().push_back( new VariableExpr( index ) ); 117 dstParam = dstIndex; 127 // block containing for stmt and index variable 128 std::list<Statement *> initList; 129 CompoundStmt * block = new CompoundStmt( noLabels ); 130 block->get_kids().push_back( new DeclStmt( noLabels, index ) ); 131 if ( listInit ) block->get_kids().push_back( listInit ); 132 block->get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, body ) ); 118 133 119 // srcParam must keep track of the array indices to build the 120 // source parameter and/or array list initializer 121 srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone() ); 134 *out++ = block; 135 } 122 136 123 // for stmt's body, eventually containing call 124 CompoundStmt * body = new CompoundStmt( noLabels ); 125 Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward ); 137 template< typename OutputIterator > 138 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) { 139 if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 140 genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward ); 141 return 0; 142 } else { 143 return genScalarCall( srcParam, dstParam, fname, out, type, addCast ); 144 } 145 } 126 146 127 // block containing for stmt and index variable 128 std::list<Statement *> initList; 129 CompoundStmt * block = new CompoundStmt( noLabels ); 130 block->get_kids().push_back( new DeclStmt( noLabels, index ) ); 131 if ( listInit ) block->get_kids().push_back( listInit ); 132 block->get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, body ) ); 147 /// inserts into out a generated call expression to function fname with arguments dstParam 148 /// and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. decl is the 149 /// object being constructed. The function wraps constructor and destructor calls in an 150 /// ImplicitCtorDtorStmt node. 151 template< typename OutputIterator > 152 void genImplicitCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) { 153 ObjectDecl *obj = dynamic_cast<ObjectDecl *>( decl ); 154 assert( obj ); 155 // unnamed bit fields are not copied as they cannot be accessed 156 if ( isUnnamedBitfield( obj ) ) return; 133 157 134 *out++ = block; 158 bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) ); 159 std::list< Statement * > stmts; 160 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), addCast, forward ); 161 162 // currently genCall should produce at most one element, but if that changes then the next line needs to be updated to grab the statement which contains the call 163 assert( stmts.size() <= 1 ); 164 if ( stmts.size() == 1 ) { 165 Statement * callStmt = stmts.front(); 166 if ( addCast ) { 167 // implicitly generated ctor/dtor calls should be wrapped 168 // so that later passes are aware they were generated. 169 // xxx - don't mark as an implicit ctor/dtor if obj is a bitfield, 170 // because this causes the address to be taken at codegen, which is illegal in C. 171 callStmt = new ImplicitCtorDtorStmt( callStmt ); 172 } 173 *out++ = callStmt; 135 174 } 136 137 template< typename OutputIterator > 138 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) { 139 if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 140 genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward ); 141 return 0; 142 } else { 143 return genScalarCall( srcParam, dstParam, fname, out, type, addCast ); 144 } 145 } 146 147 /// inserts into out a generated call expression to function fname with arguments dstParam 148 /// and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. decl is the 149 /// object being constructed. The function wraps constructor and destructor calls in an 150 /// ImplicitCtorDtorStmt node. 151 template< typename OutputIterator > 152 void genImplicitCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) { 153 ObjectDecl *obj = dynamic_cast<ObjectDecl *>( decl ); 154 assert( obj ); 155 // unnamed bit fields are not copied as they cannot be accessed 156 if ( isUnnamedBitfield( obj ) ) return; 157 158 bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) ); 159 std::list< Statement * > stmts; 160 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), addCast, forward ); 161 162 // currently genCall should produce at most one element, but if that changes then the next line needs to be updated to grab the statement which contains the call 163 assert( stmts.size() <= 1 ); 164 if ( stmts.size() == 1 ) { 165 Statement * callStmt = stmts.front(); 166 if ( addCast ) { 167 // implicitly generated ctor/dtor calls should be wrapped 168 // so that later passes are aware they were generated. 169 // xxx - don't mark as an implicit ctor/dtor if obj is a bitfield, 170 // because this causes the address to be taken at codegen, which is illegal in C. 171 callStmt = new ImplicitCtorDtorStmt( callStmt ); 172 } 173 *out++ = callStmt; 174 } 175 } 175 } 176 176 } // namespace SymTab 177 177 #endif // AUTOGEN_H -
src/SymTab/Indexer.cc
re1c1829 r4c03e63 493 493 acceptNewScope( compLitExpr->get_result(), *this ); 494 494 maybeAccept( compLitExpr->get_initializer(), *this ); 495 }496 497 void Indexer::visit( UntypedValofExpr *valofExpr ) {498 acceptNewScope( valofExpr->get_result(), *this );499 maybeAccept( valofExpr->get_body(), *this );500 495 } 501 496 -
src/SymTab/Indexer.h
re1c1829 r4c03e63 69 69 virtual void visit( ConstructorExpr * ctorExpr ); 70 70 virtual void visit( CompoundLiteralExpr *compLitExpr ); 71 virtual void visit( UntypedValofExpr *valofExpr );72 71 virtual void visit( RangeExpr *rangeExpr ); 73 72 virtual void visit( UntypedTupleExpr *tupleExpr ); -
src/SymTab/Validate.cc
re1c1829 r4c03e63 66 66 #include "ResolvExpr/typeops.h" 67 67 68 #include "SynTree/Attribute.h" 68 69 #include "SynTree/Expression.h" 69 70 #include "SynTree/Mutator.h" … … 114 115 115 116 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers. 116 class EnumAndPointerDecay Pass final : public Visitor{117 typedef Visitor Parent;118 v irtual voidvisit( EnumDecl *aggregateDecl );119 v irtual voidvisit( FunctionType *func );117 class EnumAndPointerDecay { 118 public: 119 void previsit( EnumDecl *aggregateDecl ); 120 void previsit( FunctionType *func ); 120 121 }; 121 122 … … 125 126 public: 126 127 LinkReferenceToTypes( bool doDebug, const Indexer *indexer ); 127 private:128 128 using Parent::visit; 129 129 void visit( EnumInstType *enumInst ) final; … … 135 135 void visit( UnionDecl *unionDecl ) final; 136 136 void visit( TypeInstType *typeInst ) final; 137 137 private: 138 138 const Indexer *indexer; 139 139 … … 146 146 }; 147 147 148 /// Replaces array and function types in forall lists by appropriate pointer type 149 class Pass3final : public Indexer {148 /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID. 149 class ForallPointerDecay final : public Indexer { 150 150 typedef Indexer Parent; 151 151 public: 152 152 using Parent::visit; 153 Pass3( const Indexer *indexer );154 private: 153 ForallPointerDecay( const Indexer *indexer ); 154 155 155 virtual void visit( ObjectDecl *object ) override; 156 156 virtual void visit( FunctionDecl *func ) override; … … 159 159 }; 160 160 161 class ReturnChecker {161 class ReturnChecker : public WithScopes { 162 162 public: 163 163 /// Checks that return statements return nothing if their return type is void … … 166 166 private: 167 167 void previsit( FunctionDecl * functionDecl ); 168 void postvisit( FunctionDecl * functionDecl );169 168 void previsit( ReturnStmt * returnStmt ); 170 169 171 170 typedef std::list< DeclarationWithType * > ReturnVals; 172 171 ReturnVals returnVals; 173 std::stack< ReturnVals > returnValsStack;174 172 }; 175 173 … … 247 245 248 246 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 249 EnumAndPointerDecayPassepc;247 PassVisitor<EnumAndPointerDecay> epc; 250 248 LinkReferenceToTypes lrt( doDebug, 0 ); 251 Pass3 pass3( 0 );249 ForallPointerDecay fpd( 0 ); 252 250 CompoundLiteral compoundliteral; 253 251 PassVisitor<ValidateGenericParameters> genericParams; … … 261 259 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 262 260 Concurrency::applyKeywords( translationUnit ); 263 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay Pass261 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay 264 262 Concurrency::implementMutexFuncs( translationUnit ); 265 263 Concurrency::implementThreadStarter( translationUnit ); 266 264 ReturnChecker::checkFunctionReturns( translationUnit ); 267 265 compoundliteral.mutateDeclarationList( translationUnit ); 268 acceptAll( translationUnit, pass3);266 acceptAll( translationUnit, fpd ); 269 267 ArrayLength::computeLength( translationUnit ); 270 268 } 271 269 272 270 void validateType( Type *type, const Indexer *indexer ) { 273 EnumAndPointerDecayPassepc;271 PassVisitor<EnumAndPointerDecay> epc; 274 272 LinkReferenceToTypes lrt( false, indexer ); 275 Pass3 pass3( indexer );273 ForallPointerDecay fpd( indexer ); 276 274 type->accept( epc ); 277 275 type->accept( lrt ); 278 type->accept( pass3);276 type->accept( fpd ); 279 277 } 280 278 … … 355 353 } 356 354 357 void EnumAndPointerDecay Pass::visit( EnumDecl *enumDecl ) {355 void EnumAndPointerDecay::previsit( EnumDecl *enumDecl ) { 358 356 // Set the type of each member of the enumeration to be EnumConstant 359 357 for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) { … … 362 360 obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) ); 363 361 } // for 364 Parent::visit( enumDecl );365 362 } 366 363 … … 369 366 void fixFunctionList( DWTList & dwts, FunctionType * func ) { 370 367 // the only case in which "void" is valid is where it is the only one in the list; then it should be removed 371 // entirely other fix ups are handled by the FixFunction class368 // entirely. other fix ups are handled by the FixFunction class 372 369 typedef typename DWTList::iterator DWTIterator; 373 370 DWTIterator begin( dwts.begin() ), end( dwts.end() ); … … 388 385 for ( ; i != end; ++i ) { 389 386 FixFunction fixer; 390 *i = (*i 387 *i = (*i)->acceptMutator( fixer ); 391 388 if ( fixer.get_isVoid() ) { 392 389 throw SemanticError( "invalid type void in function type ", func ); … … 397 394 } 398 395 399 void EnumAndPointerDecay Pass::visit( FunctionType *func ) {396 void EnumAndPointerDecay::previsit( FunctionType *func ) { 400 397 // Fix up parameters and return types 401 398 fixFunctionList( func->get_parameters(), func ); 402 399 fixFunctionList( func->get_returnVals(), func ); 403 Visitor::visit( func );404 400 } 405 401 … … 548 544 } 549 545 550 Pass3::Pass3( const Indexer *other_indexer ) : Indexer( false ) {546 ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) : Indexer( false ) { 551 547 if ( other_indexer ) { 552 548 indexer = other_indexer; … … 586 582 } 587 583 588 void Pass3::visit( ObjectDecl *object ) {584 void ForallPointerDecay::visit( ObjectDecl *object ) { 589 585 forallFixer( object->get_type() ); 590 586 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) { … … 595 591 } 596 592 597 void Pass3::visit( FunctionDecl *func ) {593 void ForallPointerDecay::visit( FunctionDecl *func ) { 598 594 forallFixer( func->get_type() ); 599 595 Parent::visit( func ); … … 607 603 608 604 void ReturnChecker::previsit( FunctionDecl * functionDecl ) { 609 returnValsStack.push( returnVals );605 GuardValue( returnVals ); 610 606 returnVals = functionDecl->get_functionType()->get_returnVals(); 611 }612 void ReturnChecker::postvisit( __attribute__((unused)) FunctionDecl * functionDecl ) {613 returnVals = returnValsStack.top();614 returnValsStack.pop();615 607 } 616 608 … … 927 919 ret->set_name( toString( "_retval_", CodeGen::genName( functionDecl ) ) ); 928 920 } 921 ret->get_attributes().push_back( new Attribute( "unused" ) ); 929 922 } 930 923 } -
src/SynTree/Attribute.h
re1c1829 r4c03e63 40 40 }; 41 41 42 const std::list< Attribute * > noAttributes; 43 42 44 #endif 43 45 -
src/SynTree/BaseSyntaxNode.h
re1c1829 r4c03e63 24 24 CodeLocation location; 25 25 26 virtual void accept( Visitor & v ) = 0; // temporary -- needs to be here so that BaseSyntaxNode is polymorphic and can be dynamic_cast 26 virtual ~BaseSyntaxNode() {} 27 28 virtual void accept( Visitor & v ) = 0; 27 29 }; 28 30 -
src/SynTree/Constant.cc
re1c1829 r4c03e63 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Th u Jul 30 15:18:38 201513 // Update Count : 1211 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Jun 22 10:11:00 2017 13 // Update Count : 28 14 14 // 15 15 … … 21 21 #include "Type.h" 22 22 23 Constant::Constant( Type *type_, std::string value_ ) : type( type_ ), value( value_ ) {} 23 Constant::Constant( Type * type, std::string rep, unsigned long long val ) : type( type ), rep( rep ), val( val ) {} 24 Constant::Constant( Type * type, std::string rep, double val ) : type( type ), rep( rep ), val( val ) {} 24 25 25 Constant::Constant( const Constant &other ) {26 Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ) { 26 27 type = other.type->clone(); 27 value = other.value;28 28 } 29 29 30 30 Constant::~Constant() { delete type; } 31 31 32 Constant Constant::from_bool( bool b ) { 33 return Constant( new BasicType( Type::Qualifiers(), BasicType::Bool ), b ? "1" : "0" , (unsigned long long int)b ); 34 } 35 32 36 Constant Constant::from_int( int i ) { 33 return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ) );37 return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ), (unsigned long long int)i ); 34 38 } 35 39 36 40 Constant Constant::from_ulong( unsigned long i ) { 37 return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ) );41 return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ), (unsigned long long int)i ); 38 42 } 39 43 40 44 Constant Constant::from_double( double d ) { 41 return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ) );45 return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ), d ); 42 46 } 43 47 44 Constant *Constant::clone() const { assert( false ); return 0; }45 46 48 void Constant::print( std::ostream &os ) const { 47 os << "(" << value;49 os << "(" << rep << " " << val.ival; 48 50 if ( type ) { 49 51 os << ": "; -
src/SynTree/Constant.h
re1c1829 r4c03e63 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Th u Jun 30 13:33:17 201613 // Update Count : 611 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Jun 22 10:13:00 2017 13 // Update Count : 15 14 14 // 15 15 … … 23 23 class Constant { 24 24 public: 25 Constant( Type *type, std::string value ); 26 Constant( const Constant &other ); 25 Constant( Type * type, std::string rep, unsigned long long val ); 26 Constant( Type * type, std::string rep, double val ); 27 Constant( const Constant & other ); 27 28 virtual ~Constant(); 28 29 29 Type * get_type() { return type; }30 void set_type( Type * newValue ) { type = newValue; }31 std::string & get_value() { return value; }32 void set_value( std::string newValue ) { value= newValue; }30 Type * get_type() { return type; } 31 void set_type( Type * newValue ) { type = newValue; } 32 std::string & get_value() { return rep; } 33 void set_value( std::string newValue ) { rep = newValue; } 33 34 35 /// generates a boolean constant of the given bool 36 static Constant from_bool( bool b ); 34 37 /// generates an integer constant of the given int 35 38 static Constant from_int( int i ); … … 39 42 static Constant from_double( double d ); 40 43 41 virtual Constant *clone() const; 42 virtual void accept( Visitor &v ) { v.visit( this ); } 43 virtual Constant *acceptMutator( Mutator &m ) { return m.mutate( this ); } 44 virtual void print( std::ostream &os ) const; 44 virtual void accept( Visitor & v ) { v.visit( this ); } 45 virtual Constant * acceptMutator( Mutator & m ) { return m.mutate( this ); } 46 virtual void print( std::ostream & os ) const; 45 47 private: 46 Type *type; 47 std::string value; 48 Type * type; 49 std::string rep; 50 union Val { 51 unsigned long long ival; 52 double dval; 53 Val( unsigned long long ival ) : ival( ival ) {} 54 Val( double dval ) : dval( dval ) {} 55 } val; 48 56 }; 49 57 -
src/SynTree/Expression.cc
re1c1829 r4c03e63 288 288 } 289 289 290 // CastExpr *CastExpr::clone() const { return 0; }291 292 290 void CastExpr::print( std::ostream &os, int indent ) const { 293 291 os << "Cast of:" << std::endl << std::string( indent+2, ' ' ); … … 355 353 } 356 354 357 //// is this right? It's cloning the member, but the member is a declaration so probably shouldn't be cloned...358 355 MemberExpr::MemberExpr( const MemberExpr &other ) : 359 356 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { … … 361 358 362 359 MemberExpr::~MemberExpr() { 363 // d elete member;360 // don't delete the member declaration, since it points somewhere else in the tree 364 361 delete aggregate; 365 362 } … … 591 588 } 592 589 593 UntypedValofExpr::UntypedValofExpr( const UntypedValofExpr & other ) : Expression( other ), body ( maybeClone( other.body ) ) {}594 595 UntypedValofExpr::~UntypedValofExpr() { delete body; }596 597 void UntypedValofExpr::print( std::ostream &os, int indent ) const {598 os << std::string( indent, ' ' ) << "Valof Expression: " << std::endl;599 if ( get_body() != 0 )600 get_body()->print( os, indent + 2 );601 }602 603 590 RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {} 604 591 RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {} -
src/SynTree/Expression.h
re1c1829 r4c03e63 226 226 }; 227 227 228 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer 228 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer. 229 /// Does not take ownership of member. 229 230 class MemberExpr : public Expression { 230 231 public: … … 247 248 }; 248 249 249 /// VariableExpr represents an expression that simply refers to the value of a named variable 250 /// VariableExpr represents an expression that simply refers to the value of a named variable. 251 /// Does not take ownership of var. 250 252 class VariableExpr : public Expression { 251 253 public: … … 598 600 }; 599 601 600 /// ValofExpr represents a GCC 'lambda expression'601 class UntypedValofExpr : public Expression {602 public:603 UntypedValofExpr( Statement *_body, Expression *_aname = nullptr ) : Expression( _aname ), body ( _body ) {}604 UntypedValofExpr( const UntypedValofExpr & other );605 virtual ~UntypedValofExpr();606 607 Expression * get_value();608 Statement * get_body() const { return body; }609 610 virtual UntypedValofExpr * clone() const { return new UntypedValofExpr( * this ); }611 virtual void accept( Visitor & v ) { v.visit( this ); }612 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }613 virtual void print( std::ostream & os, int indent = 0 ) const;614 private:615 Statement * body;616 };617 618 602 /// RangeExpr represents a range e.g. '3 ... 5' or '1~10' 619 603 class RangeExpr : public Expression { -
src/SynTree/Mutator.cc
re1c1829 r4c03e63 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Mar 8 16:36:00 201713 // Update Count : 2 312 // Last Modified On : Thu Jun 22 13:43:00 2017 13 // Update Count : 24 14 14 // 15 15 … … 162 162 tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) ); 163 163 mutateAll( tryStmt->get_catchers(), *this ); 164 tryStmt->set_finally( maybeMutate( tryStmt->get_finally(), *this ) ); 164 165 return tryStmt; 165 166 } … … 167 168 Statement *Mutator::mutate( CatchStmt *catchStmt ) { 168 169 catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) ); 170 catchStmt->set_cond( maybeMutate( catchStmt->get_cond(), *this ) ); 169 171 catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) ); 170 172 return catchStmt; … … 380 382 } 381 383 382 Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {383 valofExpr->set_env( maybeMutate( valofExpr->get_env(), *this ) );384 valofExpr->set_result( maybeMutate( valofExpr->get_result(), *this ) );385 return valofExpr;386 }387 388 384 Expression *Mutator::mutate( RangeExpr *rangeExpr ) { 389 385 rangeExpr->set_env( maybeMutate( rangeExpr->get_env(), *this ) ); -
src/SynTree/Mutator.h
re1c1829 r4c03e63 78 78 virtual Expression* mutate( ConstructorExpr *ctorExpr ); 79 79 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ); 80 virtual Expression* mutate( UntypedValofExpr *valofExpr );81 80 virtual Expression* mutate( RangeExpr *rangeExpr ); 82 81 virtual Expression* mutate( UntypedTupleExpr *tupleExpr ); -
src/SynTree/ObjectDecl.cc
re1c1829 r4c03e63 56 56 57 57 if ( init ) { 58 os << " with initializer " ;59 init->print( os, indent );60 os << std::endl << std::string(indent , ' ');58 os << " with initializer " << std::endl; 59 init->print( os, indent+2 ); 60 os << std::endl << std::string(indent+2, ' '); 61 61 os << "maybeConstructed? " << init->get_maybeConstructed(); 62 62 } // if -
src/SynTree/Statement.cc
re1c1829 r4c03e63 313 313 } 314 314 315 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list< Statement *> &_handlers, FinallyStmt *_finallyBlock ) :315 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) : 316 316 Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) { 317 317 } … … 334 334 // handlers 335 335 os << string( indent + 2, ' ' ) << "and handlers: " << endl; 336 for ( std::list< Statement *>::const_iterator i = handlers.begin(); i != handlers.end(); i++)336 for ( std::list<CatchStmt *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) 337 337 (*i )->print( os, indent + 4 ); 338 338 -
src/SynTree/Statement.h
re1c1829 r4c03e63 315 315 class TryStmt : public Statement { 316 316 public: 317 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list< Statement *> &handlers, FinallyStmt *finallyBlock = 0 );317 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 ); 318 318 TryStmt( const TryStmt &other ); 319 319 virtual ~TryStmt(); … … 321 321 CompoundStmt *get_block() const { return block; } 322 322 void set_block( CompoundStmt *newValue ) { block = newValue; } 323 std::list< Statement *>& get_catchers() { return handlers; }323 std::list<CatchStmt *>& get_catchers() { return handlers; } 324 324 325 325 FinallyStmt *get_finally() const { return finallyBlock; } … … 333 333 private: 334 334 CompoundStmt *block; 335 std::list< Statement *> handlers;335 std::list<CatchStmt *> handlers; 336 336 FinallyStmt *finallyBlock; 337 337 }; -
src/SynTree/Visitor.cc
re1c1829 r4c03e63 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Jun 8 16:31:00 201713 // Update Count : 2 512 // Last Modified On : Thu Jun 22 13:41:00 2017 13 // Update Count : 26 14 14 // 15 15 … … 137 137 maybeAccept( tryStmt->get_block(), *this ); 138 138 acceptAll( tryStmt->get_catchers(), *this ); 139 maybeAccept( tryStmt->get_finally(), *this ); 139 140 } 140 141 141 142 void Visitor::visit( CatchStmt *catchStmt ) { 142 143 maybeAccept( catchStmt->get_decl(), *this ); 144 maybeAccept( catchStmt->get_cond(), *this ); 143 145 maybeAccept( catchStmt->get_body(), *this ); 144 146 } … … 299 301 maybeAccept( compLitExpr->get_result(), *this ); 300 302 maybeAccept( compLitExpr->get_initializer(), *this ); 301 }302 303 void Visitor::visit( UntypedValofExpr *valofExpr ) {304 maybeAccept( valofExpr->get_result(), *this );305 maybeAccept( valofExpr->get_body(), *this );306 303 } 307 304 -
src/SynTree/Visitor.h
re1c1829 r4c03e63 81 81 virtual void visit( ConstructorExpr * ctorExpr ); 82 82 virtual void visit( CompoundLiteralExpr *compLitExpr ); 83 virtual void visit( UntypedValofExpr *valofExpr );84 83 virtual void visit( RangeExpr *rangeExpr ); 85 84 virtual void visit( UntypedTupleExpr *tupleExpr ); … … 163 162 } // if 164 163 } catch( SemanticError &e ) { 165 e.set_location( (*i)->location ); 164 e.set_location( (*i)->location ); 166 165 errors.append( e ); 167 166 } // try -
src/Tuples/TupleExpansion.cc
re1c1829 r4c03e63 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 16 08:05:17201713 // Update Count : 1 512 // Last Modified On : Wed Jun 21 17:35:04 2017 13 // Update Count : 19 14 14 // 15 15 … … 191 191 commaExpr->set_arg1( nullptr ); 192 192 } 193 BasicType * boolType = new BasicType( Type::Qualifiers(), BasicType::Bool );194 ObjectDecl * finished = new ObjectDecl( toString( "_unq", id, "_finished_" ), Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::Bool ), new SingleInit( new ConstantExpr( Constant( boolType->clone(), "0") ), noDesignators ) );193 ObjectDecl * finished = new ObjectDecl( toString( "_unq", id, "_finished_" ), Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::Bool ), 194 new SingleInit( new ConstantExpr( Constant::from_int( 0 ) ), noDesignators ) ); 195 195 addDeclaration( finished ); 196 196 // (finished ? _unq_expr_N : (_unq_expr_N = <unqExpr->get_expr()>, finished = 1, _unq_expr_N)) 197 197 // This pattern ensures that each unique expression is evaluated once, regardless of evaluation order of the generated C code. 198 Expression * assignFinished = UntypedExpr::createAssign( new VariableExpr(finished), new ConstantExpr( Constant ( boolType->clone(), "1") ) );198 Expression * assignFinished = UntypedExpr::createAssign( new VariableExpr(finished), new ConstantExpr( Constant::from_int( 1 ) ) ); 199 199 ConditionalExpr * condExpr = new ConditionalExpr( new VariableExpr( finished ), var->clone(), 200 200 new CommaExpr( new CommaExpr( assignUnq, assignFinished ), var->clone() ) ); -
src/tests/.expect/32/KRfunctions.txt
re1c1829 r4c03e63 6 6 extern int printf(const char *__restrict __format, ...); 7 7 int __f0__Fi_iPCii__1(int __a__i_1, const int *__b__PCi_1, int __c__i_1){ 8 int ___retval_f0__i_1;8 __attribute__ ((unused)) int ___retval_f0__i_1; 9 9 } 10 10 int __f1__Fi_PiiPi__1(int *__a__Pi_1, __attribute__ ((unused)) int __b__i_1, int *__c__Pi_1){ 11 int ___retval_f1__i_1;11 __attribute__ ((unused)) int ___retval_f1__i_1; 12 12 } 13 13 int __f2__Fi_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1){ 14 int ___retval_f2__i_1;14 __attribute__ ((unused)) int ___retval_f2__i_1; 15 15 } 16 16 struct S { … … 40 40 } 41 41 int __f3__Fi_2sS2sSPi__1(struct S __a__2sS_1, struct S __b__2sS_1, int *__c__Pi_1){ 42 int ___retval_f3__i_1;42 __attribute__ ((unused)) int ___retval_f3__i_1; 43 43 struct S __s__2sS_2; 44 44 } 45 45 int __f4__Fi_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1){ 46 int ___retval_f4__i_1;46 __attribute__ ((unused)) int ___retval_f4__i_1; 47 47 } 48 48 int __f5__Fi_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1){ 49 int ___retval_f5__i_1;49 __attribute__ ((unused)) int ___retval_f5__i_1; 50 50 } 51 51 int (*__f6__FPFi_i__iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))(int __anonymous_object0){ 52 int (*___retval_f6__PFi_i__1)(int __anonymous_object1);52 __attribute__ ((unused)) int (*___retval_f6__PFi_i__1)(int __anonymous_object1); 53 53 } 54 54 int (*__f7__FPFi_ii__iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))(int __a__i_1, int __b__i_1){ 55 int (*___retval_f7__PFi_ii__1)(int __a__i_1, int __b__i_1);55 __attribute__ ((unused)) int (*___retval_f7__PFi_ii__1)(int __a__i_1, int __b__i_1); 56 56 } 57 57 int *__f8__FPi_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1){ 58 int *___retval_f8__Pi_1;58 __attribute__ ((unused)) int *___retval_f8__Pi_1; 59 59 } 60 60 int *const __f9__FCPi_PiiPi__1(int *__a__Pi_1, int __b__i_1, int *__c__Pi_1){ 61 int *const ___retval_f9__CPi_1;61 __attribute__ ((unused)) int *const ___retval_f9__CPi_1; 62 62 } 63 63 int *(*__f10__FPFPi_ii__iPiPid__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1, double __y__d_1))(int __x__i_1, int __y__i_1){ 64 int *(*___retval_f10__PFPi_ii__1)(int __x__i_1, int __y__i_1);64 __attribute__ ((unused)) int *(*___retval_f10__PFPi_ii__1)(int __x__i_1, int __y__i_1); 65 65 int *__x__FPi_ii__2(int __anonymous_object2, int __anonymous_object3); 66 66 ((void)(___retval_f10__PFPi_ii__1=__x__FPi_ii__2) /* ?{} */); … … 68 68 } 69 69 int (*__f11__FPA0i_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))[]{ 70 int (*___retval_f11__PA0i_1)[];70 __attribute__ ((unused)) int (*___retval_f11__PA0i_1)[]; 71 71 } 72 72 int (*__f12__FPA0A0i_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))[][((unsigned int )10)]{ 73 int (*___retval_f12__PA0A0i_1)[][((unsigned int )10)];73 __attribute__ ((unused)) int (*___retval_f12__PA0A0i_1)[][((unsigned int )10)]; 74 74 } 75 75 int (*__f13__FPA0A0i_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))[][((unsigned int )10)]{ 76 int (*___retval_f13__PA0A0i_1)[][((unsigned int )10)];76 __attribute__ ((unused)) int (*___retval_f13__PA0A0i_1)[][((unsigned int )10)]; 77 77 } 78 78 int (*__f14__FPA0A0i_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))[][((unsigned int )10)]{ 79 int (*___retval_f14__PA0A0i_1)[][((unsigned int )10)];79 __attribute__ ((unused)) int (*___retval_f14__PA0A0i_1)[][((unsigned int )10)]; 80 80 } 81 81 const int __fred__FCi___1(){ 82 const int ___retval_fred__Ci_1;82 __attribute__ ((unused)) const int ___retval_fred__Ci_1; 83 83 int *(*__x__PFPi_ii__2)(int __anonymous_object4, int __anonymous_object5); 84 84 int __a__i_2; … … 88 88 ((void)((*((int *(**)(int __x__i_1, int __y__i_1))(&_tmp_cp_ret0)))) /* ^?{} */); 89 89 const int __f1__FCi_iPiPi__2(int __a__i_2, int *__b__Pi_2, int *__c__Pi_2){ 90 const int ___retval_f1__Ci_2;90 __attribute__ ((unused)) const int ___retval_f1__Ci_2; 91 91 } 92 92 const int __f2__FCi_iii__2(int __a__i_2, int __b__i_2, int __c__i_2){ 93 const int ___retval_f2__Ci_2;93 __attribute__ ((unused)) const int ___retval_f2__Ci_2; 94 94 } 95 95 } -
src/tests/.expect/32/attributes.txt
re1c1829 r4c03e63 6 6 extern int printf(const char *__restrict __format, ...); 7 7 int __la__Fi___1(){ 8 int ___retval_la__i_1;8 __attribute__ ((unused)) int ___retval_la__i_1; 9 9 L: __attribute__ ((unused)) ((void)1); 10 10 } … … 226 226 __attribute__ ((unused,used)) int __f1__Fi___1(); 227 227 __attribute__ ((unused)) int __f1__Fi___1(){ 228 int ___retval_f1__i_1;228 __attribute__ ((unused)) int ___retval_f1__i_1; 229 229 } 230 230 __attribute__ ((unused,unused,unused,used)) int **const __f2__FCPPi___1(); 231 231 __attribute__ ((unused,unused,unused)) int **const __f2__FCPPi___1(){ 232 int **const ___retval_f2__CPPi_1;232 __attribute__ ((unused)) int **const ___retval_f2__CPPi_1; 233 233 } 234 234 __attribute__ ((unused,used,unused)) int (*__f3__FPA0i_i__1(int __anonymous_object1))[]; 235 235 __attribute__ ((unused,unused)) int (*__f3__FPA0i_i__1(int __p__i_1))[]{ 236 int (*___retval_f3__PA0i_1)[];236 __attribute__ ((unused)) int (*___retval_f3__PA0i_1)[]; 237 237 } 238 238 __attribute__ ((unused,used,unused)) int (*__f4__FPFi_i____1())(int __anonymous_object2); 239 239 __attribute__ ((unused,unused)) int (*__f4__FPFi_i____1())(int __anonymous_object3){ 240 int (*___retval_f4__PFi_i__1)(int __anonymous_object4);240 __attribute__ ((unused)) int (*___retval_f4__PFi_i__1)(int __anonymous_object4); 241 241 } 242 242 int __vtr__Fi___1(){ 243 int ___retval_vtr__i_1;243 __attribute__ ((unused)) int ___retval_vtr__i_1; 244 244 __attribute__ ((unused,unused,used)) int __t1__i_2; 245 245 __attribute__ ((unused,unused,unused,unused,unused)) int **__t2__PPi_2; … … 251 251 int __ipd1__Fi_ii__1(__attribute__ ((unused,unused,unused)) int __p__i_1, __attribute__ ((unused,unused,unused)) int __q__i_1); 252 252 int __ipd1__Fi_ii__1(__attribute__ ((unused,unused,unused)) int __p__i_1, __attribute__ ((unused,unused,unused)) int __q__i_1){ 253 int ___retval_ipd1__i_1;253 __attribute__ ((unused)) int ___retval_ipd1__i_1; 254 254 } 255 255 int __ipd2__Fi_PiPi__1(__attribute__ ((unused,unused,unused,unused)) int *__p__Pi_1, __attribute__ ((unused,unused,unused)) int *__q__Pi_1); 256 256 int __ipd2__Fi_PiPi__1(__attribute__ ((unused,unused,unused,unused)) int *__p__Pi_1, __attribute__ ((unused,unused,unused)) int *__q__Pi_1){ 257 int ___retval_ipd2__i_1;257 __attribute__ ((unused)) int ___retval_ipd2__i_1; 258 258 } 259 259 int __ipd3__Fi_PiPi__1(__attribute__ ((unused,unused,unused)) int *__p__Pi_1, __attribute__ ((unused,unused,unused)) int *__q__Pi_1); 260 260 int __ipd3__Fi_PiPi__1(__attribute__ ((unused,unused,unused)) int *__p__Pi_1, __attribute__ ((unused,unused,unused)) int *__q__Pi_1){ 261 int ___retval_ipd3__i_1;261 __attribute__ ((unused)) int ___retval_ipd3__i_1; 262 262 } 263 263 int __ipd4__Fi_PFi__PFi____1(__attribute__ ((unused,unused,unused)) int (*__p__PFi___1)(), __attribute__ ((unused,unused,unused)) int (*__q__PFi___1)()); 264 264 int __ipd4__Fi_PFi__PFi____1(__attribute__ ((unused,unused,unused)) int (*__p__PFi___1)(), __attribute__ ((unused,unused,unused)) int (*__q__PFi___1)()){ 265 int ___retval_ipd4__i_1;265 __attribute__ ((unused)) int ___retval_ipd4__i_1; 266 266 } 267 267 int __tpr1__Fi_i__1(__attribute__ ((unused,unused,unused)) int __Foo__i_1); … … 273 273 int __tpr7__Fi_PFi_PFi_i____1(__attribute__ ((unused,unused)) int (*__anonymous_object7)(__attribute__ ((unused)) int (*__anonymous_object8)(__attribute__ ((unused,unused)) int __anonymous_object9))); 274 274 int __ad__Fi___1(){ 275 int ___retval_ad__i_1;275 __attribute__ ((unused)) int ___retval_ad__i_1; 276 276 __attribute__ ((used,unused)) int __ad1__i_2; 277 277 __attribute__ ((unused,unused,unused)) int *__ad2__Pi_2; -
src/tests/.expect/32/declarationSpecifier.txt
re1c1829 r4c03e63 670 670 static inline volatile const short __f48__FCVs___1(); 671 671 int __main__Fi_iPPCc__1(int __argc__i_1, const char **__argv__PPCc_1){ 672 int ___retval_main__i_1;672 __attribute__ ((unused)) int ___retval_main__i_1; 673 673 ((void)(___retval_main__i_1=((int )0)) /* ?{} */); 674 674 return ((int )___retval_main__i_1); … … 685 685 static inline int invoke_main(int argc, char **argv, char **envp); 686 686 int main(int __argc__i_1, char **__argv__PPc_1, char **__envp__PPc_1){ 687 int ___retval_main__i_1;687 __attribute__ ((unused)) int ___retval_main__i_1; 688 688 int _tmp_cp_ret0; 689 689 ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */); -
src/tests/.expect/32/extension.txt
re1c1829 r4c03e63 85 85 __extension__ int j; 86 86 __extension__ int __fred__Fi_i__1(int __p__i_1){ 87 int ___retval_fred__i_1;87 __attribute__ ((unused)) int ___retval_fred__i_1; 88 88 __extension__ struct S { 89 89 __extension__ int __a__i_2; … … 105 105 ((void)((*((int *)(&_tmp_cp_ret0)))) /* ^?{} */); 106 106 __extension__ int __mary__Fi_i__2(int __p__i_2){ 107 int ___retval_mary__i_2;107 __attribute__ ((unused)) int ___retval_mary__i_2; 108 108 } 109 109 ((void)__extension__ sizeof(3)); -
src/tests/.expect/32/gccExtensions.txt
re1c1829 r4c03e63 7 7 extern int __x__i_1 asm ( "xx" ); 8 8 int __main__Fi_iPPCc__1(int __argc__i_1, const char **__argv__PPCc_1){ 9 int ___retval_main__i_1;9 __attribute__ ((unused)) int ___retval_main__i_1; 10 10 asm ( "nop" : : : ); 11 11 asm ( "nop" : : : ); … … 26 26 const int __i3__Ci_2; 27 27 inline int __f1__Fi___2(){ 28 int ___retval_f1__i_2;28 __attribute__ ((unused)) int ___retval_f1__i_2; 29 29 } 30 30 inline int __f2__Fi___2(){ 31 int ___retval_f2__i_2;31 __attribute__ ((unused)) int ___retval_f2__i_2; 32 32 } 33 33 int __s1__i_2; … … 182 182 static inline int invoke_main(int argc, char **argv, char **envp); 183 183 int main(int __argc__i_1, char **__argv__PPc_1, char **__envp__PPc_1){ 184 int ___retval_main__i_1;184 __attribute__ ((unused)) int ___retval_main__i_1; 185 185 int _tmp_cp_ret0; 186 186 ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */); -
src/tests/.expect/64/KRfunctions.txt
re1c1829 r4c03e63 6 6 extern int printf(const char *__restrict __format, ...); 7 7 int __f0__Fi_iPCii__1(int __a__i_1, const int *__b__PCi_1, int __c__i_1){ 8 int ___retval_f0__i_1;8 __attribute__ ((unused)) int ___retval_f0__i_1; 9 9 } 10 10 int __f1__Fi_PiiPi__1(int *__a__Pi_1, __attribute__ ((unused)) int __b__i_1, int *__c__Pi_1){ 11 int ___retval_f1__i_1;11 __attribute__ ((unused)) int ___retval_f1__i_1; 12 12 } 13 13 int __f2__Fi_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1){ 14 int ___retval_f2__i_1;14 __attribute__ ((unused)) int ___retval_f2__i_1; 15 15 } 16 16 struct S { … … 40 40 } 41 41 int __f3__Fi_2sS2sSPi__1(struct S __a__2sS_1, struct S __b__2sS_1, int *__c__Pi_1){ 42 int ___retval_f3__i_1;42 __attribute__ ((unused)) int ___retval_f3__i_1; 43 43 struct S __s__2sS_2; 44 44 } 45 45 int __f4__Fi_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1){ 46 int ___retval_f4__i_1;46 __attribute__ ((unused)) int ___retval_f4__i_1; 47 47 } 48 48 int __f5__Fi_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1){ 49 int ___retval_f5__i_1;49 __attribute__ ((unused)) int ___retval_f5__i_1; 50 50 } 51 51 int (*__f6__FPFi_i__iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))(int __anonymous_object0){ 52 int (*___retval_f6__PFi_i__1)(int __anonymous_object1);52 __attribute__ ((unused)) int (*___retval_f6__PFi_i__1)(int __anonymous_object1); 53 53 } 54 54 int (*__f7__FPFi_ii__iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))(int __a__i_1, int __b__i_1){ 55 int (*___retval_f7__PFi_ii__1)(int __a__i_1, int __b__i_1);55 __attribute__ ((unused)) int (*___retval_f7__PFi_ii__1)(int __a__i_1, int __b__i_1); 56 56 } 57 57 int *__f8__FPi_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1){ 58 int *___retval_f8__Pi_1;58 __attribute__ ((unused)) int *___retval_f8__Pi_1; 59 59 } 60 60 int *const __f9__FCPi_PiiPi__1(int *__a__Pi_1, int __b__i_1, int *__c__Pi_1){ 61 int *const ___retval_f9__CPi_1;61 __attribute__ ((unused)) int *const ___retval_f9__CPi_1; 62 62 } 63 63 int *(*__f10__FPFPi_ii__iPiPid__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1, double __y__d_1))(int __x__i_1, int __y__i_1){ 64 int *(*___retval_f10__PFPi_ii__1)(int __x__i_1, int __y__i_1);64 __attribute__ ((unused)) int *(*___retval_f10__PFPi_ii__1)(int __x__i_1, int __y__i_1); 65 65 int *__x__FPi_ii__2(int __anonymous_object2, int __anonymous_object3); 66 66 ((void)(___retval_f10__PFPi_ii__1=__x__FPi_ii__2) /* ?{} */); … … 68 68 } 69 69 int (*__f11__FPA0i_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))[]{ 70 int (*___retval_f11__PA0i_1)[];70 __attribute__ ((unused)) int (*___retval_f11__PA0i_1)[]; 71 71 } 72 72 int (*__f12__FPA0A0i_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))[][((long unsigned int )10)]{ 73 int (*___retval_f12__PA0A0i_1)[][((long unsigned int )10)];73 __attribute__ ((unused)) int (*___retval_f12__PA0A0i_1)[][((long unsigned int )10)]; 74 74 } 75 75 int (*__f13__FPA0A0i_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))[][((long unsigned int )10)]{ 76 int (*___retval_f13__PA0A0i_1)[][((long unsigned int )10)];76 __attribute__ ((unused)) int (*___retval_f13__PA0A0i_1)[][((long unsigned int )10)]; 77 77 } 78 78 int (*__f14__FPA0A0i_iPiPi__1(int __a__i_1, int *__b__Pi_1, int *__c__Pi_1))[][((long unsigned int )10)]{ 79 int (*___retval_f14__PA0A0i_1)[][((long unsigned int )10)];79 __attribute__ ((unused)) int (*___retval_f14__PA0A0i_1)[][((long unsigned int )10)]; 80 80 } 81 81 const int __fred__FCi___1(){ 82 const int ___retval_fred__Ci_1;82 __attribute__ ((unused)) const int ___retval_fred__Ci_1; 83 83 int *(*__x__PFPi_ii__2)(int __anonymous_object4, int __anonymous_object5); 84 84 int __a__i_2; … … 88 88 ((void)((*((int *(**)(int __x__i_1, int __y__i_1))(&_tmp_cp_ret0)))) /* ^?{} */); 89 89 const int __f1__FCi_iPiPi__2(int __a__i_2, int *__b__Pi_2, int *__c__Pi_2){ 90 const int ___retval_f1__Ci_2;90 __attribute__ ((unused)) const int ___retval_f1__Ci_2; 91 91 } 92 92 const int __f2__FCi_iii__2(int __a__i_2, int __b__i_2, int __c__i_2){ 93 const int ___retval_f2__Ci_2;93 __attribute__ ((unused)) const int ___retval_f2__Ci_2; 94 94 } 95 95 } -
src/tests/.expect/64/attributes.txt
re1c1829 r4c03e63 6 6 extern int printf(const char *__restrict __format, ...); 7 7 int __la__Fi___1(){ 8 int ___retval_la__i_1;8 __attribute__ ((unused)) int ___retval_la__i_1; 9 9 L: __attribute__ ((unused)) ((void)1); 10 10 } … … 226 226 __attribute__ ((unused,used)) int __f1__Fi___1(); 227 227 __attribute__ ((unused)) int __f1__Fi___1(){ 228 int ___retval_f1__i_1;228 __attribute__ ((unused)) int ___retval_f1__i_1; 229 229 } 230 230 __attribute__ ((unused,unused,unused,used)) int **const __f2__FCPPi___1(); 231 231 __attribute__ ((unused,unused,unused)) int **const __f2__FCPPi___1(){ 232 int **const ___retval_f2__CPPi_1;232 __attribute__ ((unused)) int **const ___retval_f2__CPPi_1; 233 233 } 234 234 __attribute__ ((unused,used,unused)) int (*__f3__FPA0i_i__1(int __anonymous_object1))[]; 235 235 __attribute__ ((unused,unused)) int (*__f3__FPA0i_i__1(int __p__i_1))[]{ 236 int (*___retval_f3__PA0i_1)[];236 __attribute__ ((unused)) int (*___retval_f3__PA0i_1)[]; 237 237 } 238 238 __attribute__ ((unused,used,unused)) int (*__f4__FPFi_i____1())(int __anonymous_object2); 239 239 __attribute__ ((unused,unused)) int (*__f4__FPFi_i____1())(int __anonymous_object3){ 240 int (*___retval_f4__PFi_i__1)(int __anonymous_object4);240 __attribute__ ((unused)) int (*___retval_f4__PFi_i__1)(int __anonymous_object4); 241 241 } 242 242 int __vtr__Fi___1(){ 243 int ___retval_vtr__i_1;243 __attribute__ ((unused)) int ___retval_vtr__i_1; 244 244 __attribute__ ((unused,unused,used)) int __t1__i_2; 245 245 __attribute__ ((unused,unused,unused,unused,unused)) int **__t2__PPi_2; … … 251 251 int __ipd1__Fi_ii__1(__attribute__ ((unused,unused,unused)) int __p__i_1, __attribute__ ((unused,unused,unused)) int __q__i_1); 252 252 int __ipd1__Fi_ii__1(__attribute__ ((unused,unused,unused)) int __p__i_1, __attribute__ ((unused,unused,unused)) int __q__i_1){ 253 int ___retval_ipd1__i_1;253 __attribute__ ((unused)) int ___retval_ipd1__i_1; 254 254 } 255 255 int __ipd2__Fi_PiPi__1(__attribute__ ((unused,unused,unused,unused)) int *__p__Pi_1, __attribute__ ((unused,unused,unused)) int *__q__Pi_1); 256 256 int __ipd2__Fi_PiPi__1(__attribute__ ((unused,unused,unused,unused)) int *__p__Pi_1, __attribute__ ((unused,unused,unused)) int *__q__Pi_1){ 257 int ___retval_ipd2__i_1;257 __attribute__ ((unused)) int ___retval_ipd2__i_1; 258 258 } 259 259 int __ipd3__Fi_PiPi__1(__attribute__ ((unused,unused,unused)) int *__p__Pi_1, __attribute__ ((unused,unused,unused)) int *__q__Pi_1); 260 260 int __ipd3__Fi_PiPi__1(__attribute__ ((unused,unused,unused)) int *__p__Pi_1, __attribute__ ((unused,unused,unused)) int *__q__Pi_1){ 261 int ___retval_ipd3__i_1;261 __attribute__ ((unused)) int ___retval_ipd3__i_1; 262 262 } 263 263 int __ipd4__Fi_PFi__PFi____1(__attribute__ ((unused,unused,unused)) int (*__p__PFi___1)(), __attribute__ ((unused,unused,unused)) int (*__q__PFi___1)()); 264 264 int __ipd4__Fi_PFi__PFi____1(__attribute__ ((unused,unused,unused)) int (*__p__PFi___1)(), __attribute__ ((unused,unused,unused)) int (*__q__PFi___1)()){ 265 int ___retval_ipd4__i_1;265 __attribute__ ((unused)) int ___retval_ipd4__i_1; 266 266 } 267 267 int __tpr1__Fi_i__1(__attribute__ ((unused,unused,unused)) int __Foo__i_1); … … 273 273 int __tpr7__Fi_PFi_PFi_i____1(__attribute__ ((unused,unused)) int (*__anonymous_object7)(__attribute__ ((unused)) int (*__anonymous_object8)(__attribute__ ((unused,unused)) int __anonymous_object9))); 274 274 int __ad__Fi___1(){ 275 int ___retval_ad__i_1;275 __attribute__ ((unused)) int ___retval_ad__i_1; 276 276 __attribute__ ((used,unused)) int __ad1__i_2; 277 277 __attribute__ ((unused,unused,unused)) int *__ad2__Pi_2; -
src/tests/.expect/64/declarationSpecifier.txt
re1c1829 r4c03e63 670 670 static inline volatile const short __f48__FCVs___1(); 671 671 int __main__Fi_iPPCc__1(int __argc__i_1, const char **__argv__PPCc_1){ 672 int ___retval_main__i_1;672 __attribute__ ((unused)) int ___retval_main__i_1; 673 673 ((void)(___retval_main__i_1=((int )0)) /* ?{} */); 674 674 return ((int )___retval_main__i_1); … … 685 685 static inline int invoke_main(int argc, char **argv, char **envp); 686 686 int main(int __argc__i_1, char **__argv__PPc_1, char **__envp__PPc_1){ 687 int ___retval_main__i_1;687 __attribute__ ((unused)) int ___retval_main__i_1; 688 688 int _tmp_cp_ret0; 689 689 ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */); -
src/tests/.expect/64/extension.txt
re1c1829 r4c03e63 85 85 __extension__ int j; 86 86 __extension__ int __fred__Fi_i__1(int __p__i_1){ 87 int ___retval_fred__i_1;87 __attribute__ ((unused)) int ___retval_fred__i_1; 88 88 __extension__ struct S { 89 89 __extension__ int __a__i_2; … … 105 105 ((void)((*((int *)(&_tmp_cp_ret0)))) /* ^?{} */); 106 106 __extension__ int __mary__Fi_i__2(int __p__i_2){ 107 int ___retval_mary__i_2;107 __attribute__ ((unused)) int ___retval_mary__i_2; 108 108 } 109 109 ((void)__extension__ sizeof(3)); -
src/tests/.expect/64/gccExtensions.txt
re1c1829 r4c03e63 7 7 extern int __x__i_1 asm ( "xx" ); 8 8 int __main__Fi_iPPCc__1(int __argc__i_1, const char **__argv__PPCc_1){ 9 int ___retval_main__i_1;9 __attribute__ ((unused)) int ___retval_main__i_1; 10 10 asm ( "nop" : : : ); 11 11 asm ( "nop" : : : ); … … 26 26 const int __i3__Ci_2; 27 27 inline int __f1__Fi___2(){ 28 int ___retval_f1__i_2;28 __attribute__ ((unused)) int ___retval_f1__i_2; 29 29 } 30 30 inline int __f2__Fi___2(){ 31 int ___retval_f2__i_2;31 __attribute__ ((unused)) int ___retval_f2__i_2; 32 32 } 33 33 int __s1__i_2; … … 182 182 static inline int invoke_main(int argc, char **argv, char **envp); 183 183 int main(int __argc__i_1, char **__argv__PPc_1, char **__envp__PPc_1){ 184 int ___retval_main__i_1;184 __attribute__ ((unused)) int ___retval_main__i_1; 185 185 int _tmp_cp_ret0; 186 186 ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */); -
src/tests/.expect/scopeErrors.txt
re1c1829 r4c03e63 3 3 with parameters 4 4 double 5 returning 6 _retval_butThisIsAnError: double 7 with body 5 returning 6 _retval_butThisIsAnError: Attribute with name: unused 7 double 8 with body 8 9 CompoundStmt
Note: See TracChangeset
for help on using the changeset viewer.