Changes in / [4c03e63:e1c1829]
- Files:
-
- 2 deleted
- 52 edited
-
doc/LaTeXmacros/common.tex (modified) (3 diffs)
-
doc/proposals/tagged-struct.txt (modified) (3 diffs)
-
doc/rob_thesis/intro.tex (modified) (2 diffs)
-
doc/rob_thesis/thesis.tex (modified) (1 diff)
-
doc/working/exception/translate.c (modified) (7 diffs)
-
src/CodeGen/FixNames.cc (modified) (2 diffs)
-
src/Common/PassVisitor.h (modified) (10 diffs)
-
src/Common/PassVisitor.impl.h (modified) (28 diffs)
-
src/Common/PassVisitor.proto.h (modified) (3 diffs)
-
src/ControlStruct/ExceptTranslate.cc (deleted)
-
src/ControlStruct/ExceptTranslate.h (deleted)
-
src/GenPoly/Box.cc (modified) (7 diffs)
-
src/GenPoly/CopyParams.cc (modified) (1 diff)
-
src/GenPoly/DeclMutator.cc (modified) (15 diffs)
-
src/GenPoly/Lvalue.cc (modified) (1 diff)
-
src/GenPoly/PolyMutator.cc (modified) (2 diffs)
-
src/GenPoly/Specialize.cc (modified) (1 diff)
-
src/InitTweak/FixGlobalInit.cc (modified) (1 diff)
-
src/InitTweak/FixInit.cc (modified) (7 diffs)
-
src/InitTweak/GenInit.cc (modified) (2 diffs)
-
src/InitTweak/InitTweak.cc (modified) (1 diff)
-
src/Parser/ExpressionNode.cc (modified) (10 diffs)
-
src/Parser/ParseNode.h (modified) (1 diff)
-
src/Parser/StatementNode.cc (modified) (1 diff)
-
src/Parser/parseutility.cc (modified) (2 diffs)
-
src/SymTab/Autogen.h (modified) (2 diffs)
-
src/SymTab/Indexer.cc (modified) (1 diff)
-
src/SymTab/Indexer.h (modified) (1 diff)
-
src/SymTab/Validate.cc (modified) (19 diffs)
-
src/SynTree/Attribute.h (modified) (1 diff)
-
src/SynTree/BaseSyntaxNode.h (modified) (1 diff)
-
src/SynTree/Constant.cc (modified) (2 diffs)
-
src/SynTree/Constant.h (modified) (3 diffs)
-
src/SynTree/Expression.cc (modified) (4 diffs)
-
src/SynTree/Expression.h (modified) (3 diffs)
-
src/SynTree/Mutator.cc (modified) (4 diffs)
-
src/SynTree/Mutator.h (modified) (1 diff)
-
src/SynTree/ObjectDecl.cc (modified) (1 diff)
-
src/SynTree/Statement.cc (modified) (2 diffs)
-
src/SynTree/Statement.h (modified) (3 diffs)
-
src/SynTree/Visitor.cc (modified) (3 diffs)
-
src/SynTree/Visitor.h (modified) (2 diffs)
-
src/Tuples/TupleExpansion.cc (modified) (2 diffs)
-
src/tests/.expect/32/KRfunctions.txt (modified) (4 diffs)
-
src/tests/.expect/32/attributes.txt (modified) (4 diffs)
-
src/tests/.expect/32/declarationSpecifier.txt (modified) (2 diffs)
-
src/tests/.expect/32/extension.txt (modified) (2 diffs)
-
src/tests/.expect/32/gccExtensions.txt (modified) (3 diffs)
-
src/tests/.expect/64/KRfunctions.txt (modified) (4 diffs)
-
src/tests/.expect/64/attributes.txt (modified) (4 diffs)
-
src/tests/.expect/64/declarationSpecifier.txt (modified) (2 diffs)
-
src/tests/.expect/64/extension.txt (modified) (2 diffs)
-
src/tests/.expect/64/gccExtensions.txt (modified) (3 diffs)
-
src/tests/.expect/scopeErrors.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
doc/LaTeXmacros/common.tex
r4c03e63 re1c1829 11 11 %% Created On : Sat Apr 9 10:06:17 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Sun Jun 18 20:32:32201714 %% Update Count : 3 1913 %% Last Modified On : Mon May 15 18:03:29 2017 14 %% Update Count : 302 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 36 36 % Names used in the document. 37 37 38 \newcommand{\CFAIcon}{\textrm{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\xspace} % Cforall symbolic name 39 \newcommand{\CFA}{\protect\CFAIcon} % safe for section/caption 38 \newcommand{\CFA}{\textrm{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\xspace} % Cforall symbolic name 40 39 \newcommand{\CFL}{\textrm{Cforall}\xspace} % Cforall symbolic name 41 40 \newcommand{\Celeven}{\textrm{C11}\xspace} % C11 symbolic name … … 242 241 belowskip=3pt, 243 242 % replace/adjust listing characters that look bad in sanserif 244 literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0. 1ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1243 literate={-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}}1 {^}{\raisebox{0.6ex}{$\scriptscriptstyle\land\,$}}1 245 244 {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1 {`}{\ttfamily\upshape\hspace*{-0.1ex}`}1 246 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2, 245 {__}{\_\,\_}2 {<-}{$\leftarrow$}2 {=>}{$\Rightarrow$}2 {->}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.8ex}{0.075ex}}}\kern-0.2ex\textgreater}2 246 {___}{\_\,\_\,\_}3, 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
r4c03e63 re1c1829 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.18 16 19 17 … … 38 36 their parent's fields to their field list so they can be upcast. 39 37 40 The type field may be public, if it is then it can be accessed through a41 simple field access "instance.type". The type field would then be able to be42 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 a44 lookup function could also be used.45 46 47 Usage:48 49 The central feature for tagged structs is a checked cast between pointer types50 to the structures. A cast is successful if the true type of the pointed object51 is of the type being cast to or any of its children, otherwise the cast52 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 field57 could be hidden and the operations given through helper functions. However58 if the type object has more complex (or even open ended) information in it59 than providing direct access becomes very valuable.60 61 38 62 39 Implemenation: 63 40 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. 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. 67 47 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. 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. 72 60 73 61 … … 106 94 If unions are declared tagged instead of creating a new tagged type, all 107 95 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 is113 to allow the tree's type object to be specified by the tree root. It would114 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's117 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 could120 append fields to their parent's feild list. They might need their own type121 objects at that point, or maybe static checks will be enough to see the122 minimum field list. -
doc/rob_thesis/intro.tex
r4c03e63 re1c1829 3 3 %====================================================================== 4 4 5 \section{\ protect\CFA Background}5 \section{\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 \ protect\CFA}372 \caption{\label{table:types} The different kinds of type parameters in \CFA} 373 373 \end{table} 374 374 -
doc/rob_thesis/thesis.tex
r4c03e63 re1c1829 66 66 % ,monochrome % toggle black and white mode 67 67 }{xcolor} 68 \PassOptionsToPackage{pdftex}{graphicx}69 68 \documentclass[letterpaper,12pt,titlepage,oneside,final]{book} 70 69 -
doc/working/exception/translate.c
r4c03e63 re1c1829 1 1 /* Translation rules for exception handling code, from Cforall to C. 2 2 * 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. 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. 8 6 * 9 7 * Most of these exist only after translation (in C code). The first (the … … 17 15 // Currently it is a typedef for int, but later it will be a new type. 18 16 typedef int exception; 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 17 24 18 void __throw_terminate(exception except) __attribute__((noreturn)); … … 122 116 } 123 117 int match1(exception except) { 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; 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; 137 127 } 138 128 __try_terminate(try1, catch1, match1); … … 161 151 { 162 152 bool handle1(exception except) { 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; 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 } 178 164 } 179 165 struct __try_resume_node data = … … 244 230 } 245 231 bool handle1(exception except) { 246 { 247 if (dynamic_cast__SomeException(except)) { 248 fiddleThing(); 249 return true; 250 } 251 } 252 return false; 232 if (dynamic_cast__SomeException(except)) { 233 fiddleThing(); 234 return true; 235 } else { 236 return false; 237 } 253 238 } 254 239 struct __cleanup_hook generated_name … … 288 273 { 289 274 bool handle1() { 290 { 291 if (dynamic_cast__OtherException(except)) { 292 twiddleWidget(); 293 return true; 294 } 275 if (dynamic_cast__OtherException(except)) { 276 twiddleWidget(); 277 return true; 295 278 } 296 279 return false; … … 314 297 } 315 298 int match1(exception except) { 316 { 317 if (dynamic_cast__SomeException(except)) { 318 return 1; 319 } 299 if (dynamic_cast__SomeException(except)) { 300 return 1; 320 301 } 321 302 return 0; -
src/CodeGen/FixNames.cc
r4c03e63 re1c1829 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 21 14:22:59201713 // Update Count : 1 912 // Last Modified On : Thu Mar 16 07:50:30 2017 13 // Update Count : 16 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 ::from_int( 0) ) ) );116 functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), "0") ) ) ); 117 117 CodeGen::FixMain::registerMain( functionDecl ); 118 118 } -
src/Common/PassVisitor.h
r4c03e63 re1c1829 18 18 // Templated visitor type 19 19 // To use declare a PassVisitor< YOUR VISITOR TYPE > 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. 20 // The visitor type should specify the previsit/postvisit for types that are desired. 30 21 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 31 22 template< typename pass_type > … … 37 28 PassVisitor(Args &&... args) 38 29 : pass( std::forward<Args>( args )... ) 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 } 30 {} 46 31 47 32 virtual ~PassVisitor() = default; … … 101 86 virtual void visit( ConstructorExpr * ctorExpr ) override final; 102 87 virtual void visit( CompoundLiteralExpr *compLitExpr ) override final; 88 virtual void visit( UntypedValofExpr *valofExpr ) override final; 103 89 virtual void visit( RangeExpr *rangeExpr ) override final; 104 90 virtual void visit( UntypedTupleExpr *tupleExpr ) override final; … … 186 172 virtual Expression* mutate( ConstructorExpr *ctorExpr ) override final; 187 173 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ) override final; 174 virtual Expression* mutate( UntypedValofExpr *valofExpr ) override final; 188 175 virtual Expression* mutate( RangeExpr *rangeExpr ) override final; 189 176 virtual Expression* mutate( UntypedTupleExpr *tupleExpr ) override final; … … 220 207 221 208 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 225 209 template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); } 226 210 template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); } … … 234 218 void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); } 235 219 236 template< typename func_t > 237 void handleStatementList( std::list< Statement * > & statements, func_t func ); 238 void visitStatementList ( std::list< Statement* > &statements ); 220 void visitStatementList( std::list< Statement* > &statements ); 239 221 void mutateStatementList( std::list< Statement* > &statements ); 240 222 241 template< typename func_t > 242 Statement * handleStatement( Statement * stmt, func_t func ); 243 Statement * visitStatement ( Statement * stmt ); 223 Statement * visitStatement( Statement * stmt ); 244 224 Statement * mutateStatement( Statement * stmt ); 245 225 246 template< typename func_t > 247 Expression * handleExpression( Expression * expr, func_t func ); 248 Expression * visitExpression ( Expression * expr ); 226 void visitExpression( Expression * expr ); 249 227 Expression * mutateExpression( Expression * expr ); 250 228 … … 253 231 std::list< Statement* > * get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); } 254 232 std::list< Statement* > * get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); } 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 ); } 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; } 259 235 260 236 guard_value_impl init_guard() { … … 295 271 std::list< Statement* > stmtsToAddAfter; 296 272 }; 273 297 274 class WithShortCircuiting { 298 275 protected: … … 301 278 302 279 public: 303 bool _ref visit_children;280 bool skip_children; 304 281 }; 305 282 … … 320 297 }; 321 298 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 };331 299 332 300 #include "PassVisitor.impl.h" -
src/Common/PassVisitor.impl.h
r4c03e63 re1c1829 4 4 __attribute__((unused)) \ 5 5 const auto & guard = init_guard(); \ 6 bool visit_children = true; \7 set_visit_children( visit_children ); \8 6 call_previsit( node ); \ 9 if( visit_children ) { \ 7 if( visit_children() ) { \ 8 reset_visit(); \ 10 9 11 10 #define VISIT_END( node ) \ … … 16 15 __attribute__((unused)) \ 17 16 const auto & guard = init_guard(); \ 18 bool visit_children = true; \19 set_visit_children( visit_children ); \20 17 call_premutate( node ); \ 21 if( visit_children ) { \ 18 if( visit_children() ) { \ 19 reset_visit(); \ 22 20 23 21 #define MUTATE_END( type, node ) \ … … 44 42 } 45 43 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 ) { 44 typedef std::list< Statement * > StmtList_t; 45 46 template< typename pass_type > 47 void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) { 105 48 SemanticError errors; 106 49 107 50 StmtList_t* beforeStmts = get_beforeStmts(); 108 51 StmtList_t* afterStmts = get_afterStmts(); 109 DeclList_t* beforeDecls = get_beforeDecls();110 DeclList_t* afterDecls = get_afterDecls();111 52 112 53 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 113 114 if ( !empty( afterDecls ) ) { splice( std::inserter( statements, i ), afterDecls ); }115 54 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 116 117 55 try { 118 func( *i ); 119 assert(( empty( beforeStmts ) && empty( afterStmts )) 120 || ( empty( beforeDecls ) && empty( afterDecls )) ); 121 56 (*i)->accept( *this ); 122 57 } catch ( SemanticError &e ) { 123 58 errors.append( e ); 124 59 } 125 126 if ( !empty( beforeDecls ) ) { splice( std::inserter( statements, i ), beforeDecls ); }127 60 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } 128 61 } 129 62 130 if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); }131 63 if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); } 132 64 if ( !errors.isEmpty() ) { throw errors; } … … 134 66 135 67 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 >143 68 void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) { 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 ); 69 SemanticError errors; 161 70 162 71 StmtList_t* beforeStmts = get_beforeStmts(); 163 72 StmtList_t* afterStmts = get_afterStmts(); 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 )) ); 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; } 170 101 171 102 CompoundStmt *compound = new CompoundStmt( noLabels ); 172 if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); } 103 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 104 compound->get_kids().push_back( stmt ); 105 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 106 return compound; 107 } 108 109 template< typename pass_type > 110 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 ); 173 124 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 174 125 compound->get_kids().push_back( newStmt ); 175 if( !empty(afterDecls) ) { splice( std::back_inserter( compound->get_kids() ), afterDecls ); }176 126 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 177 127 return compound; 178 128 } 179 129 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 > 189 Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) { 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; 130 131 132 template< typename pass_type > 133 void PassVisitor< pass_type >::visitExpression( Expression * expr ) { 134 if( !expr ) return; 199 135 200 136 auto env_ptr = get_env_ptr(); … … 202 138 *env_ptr = expr->get_env(); 203 139 } 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 }); 140 // xxx - should env be cloned (or moved) onto the result of the mutate? 141 expr->accept( *this ); 215 142 } 216 143 217 144 template< typename pass_type > 218 145 Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) { 219 return handleExpression(expr, [this]( Expression * expr ) { 220 return expr->acceptMutator( *this ); 221 }); 222 } 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 223 156 224 157 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ … … 226 159 template< typename pass_type > 227 160 void PassVisitor< pass_type >::visit( ObjectDecl * node ) { 228 VISIT_BODY( node ); 161 VISIT_BODY( node ); 229 162 } 230 163 231 164 template< typename pass_type > 232 165 void PassVisitor< pass_type >::visit( FunctionDecl * node ) { 233 VISIT_BODY( node ); 166 VISIT_BODY( node ); 234 167 } 235 168 236 169 template< typename pass_type > 237 170 void PassVisitor< pass_type >::visit( StructDecl * node ) { 238 VISIT_BODY( node ); 171 VISIT_BODY( node ); 239 172 } 240 173 241 174 template< typename pass_type > 242 175 void PassVisitor< pass_type >::visit( UnionDecl * node ) { 243 VISIT_BODY( node ); 176 VISIT_BODY( node ); 244 177 } 245 178 246 179 template< typename pass_type > 247 180 void PassVisitor< pass_type >::visit( EnumDecl * node ) { 248 VISIT_BODY( node ); 181 VISIT_BODY( node ); 249 182 } 250 183 251 184 template< typename pass_type > 252 185 void PassVisitor< pass_type >::visit( TraitDecl * node ) { 253 VISIT_BODY( node ); 186 VISIT_BODY( node ); 254 187 } 255 188 256 189 template< typename pass_type > 257 190 void PassVisitor< pass_type >::visit( TypeDecl * node ) { 258 VISIT_BODY( node ); 191 VISIT_BODY( node ); 259 192 } 260 193 261 194 template< typename pass_type > 262 195 void PassVisitor< pass_type >::visit( TypedefDecl * node ) { 263 VISIT_BODY( node ); 196 VISIT_BODY( node ); 264 197 } 265 198 266 199 template< typename pass_type > 267 200 void PassVisitor< pass_type >::visit( AsmDecl * node ) { 268 VISIT_BODY( node ); 201 VISIT_BODY( node ); 269 202 } 270 203 … … 298 231 void PassVisitor< pass_type >::visit( ExprStmt * node ) { 299 232 VISIT_START( node ); 233 call_beginScope(); 300 234 301 235 visitExpression( node->get_expr() ); 302 236 237 call_endScope(); 303 238 VISIT_END( node ); 304 239 } … … 313 248 } 314 249 315 //--------------------------------------------------------------------------316 // AsmStmt317 250 template< typename pass_type > 318 251 void PassVisitor< pass_type >::visit( AsmStmt * 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 ); 252 VISIT_BODY( node ); 325 253 } 326 254 … … 329 257 template< typename pass_type > 330 258 void PassVisitor< pass_type >::visit( IfStmt * node ) { 331 VISIT_START( node ); 259 VISIT_START( node ); 332 260 333 261 visitExpression( node->get_condition() ); … … 340 268 template< typename pass_type > 341 269 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) { 342 MUTATE_START( node ); 270 MUTATE_START( node ); 343 271 344 272 node->set_condition( mutateExpression( node->get_condition() ) ); … … 353 281 template< typename pass_type > 354 282 void PassVisitor< pass_type >::visit( WhileStmt * node ) { 355 VISIT_START( node ); 283 VISIT_START( node ); 356 284 357 285 visitExpression( node->get_condition() ); … … 363 291 template< typename pass_type > 364 292 Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) { 365 MUTATE_START( node ); 293 MUTATE_START( node ); 366 294 367 295 node->set_condition( mutateExpression( node->get_condition() ) ); … … 372 300 373 301 //-------------------------------------------------------------------------- 374 // ForStmt302 // WhileStmt 375 303 template< typename pass_type > 376 304 void PassVisitor< pass_type >::visit( ForStmt * node ) { 377 VISIT_START( node ); 305 VISIT_START( node ); 378 306 379 307 acceptAll( node->get_initialization(), *this ); … … 387 315 template< typename pass_type > 388 316 Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) { 389 MUTATE_START( node ); 317 MUTATE_START( node ); 390 318 391 319 mutateAll( node->get_initialization(), *this ); … … 401 329 template< typename pass_type > 402 330 void PassVisitor< pass_type >::visit( SwitchStmt * node ) { 403 VISIT_START( node ); 331 VISIT_START( node ); 404 332 405 333 visitExpression( node->get_condition() ); … … 411 339 template< typename pass_type > 412 340 Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) { 413 MUTATE_START( node ); 414 341 MUTATE_START( node ); 342 415 343 node->set_condition( mutateExpression( node->get_condition() ) ); 416 344 mutateStatementList( node->get_statements() ); 417 345 418 346 MUTATE_END( Statement, node ); 419 347 } 420 348 421 349 //-------------------------------------------------------------------------- 422 // CaseStmt350 // SwitchStmt 423 351 template< typename pass_type > 424 352 void PassVisitor< pass_type >::visit( CaseStmt * node ) { 425 VISIT_START( node ); 426 353 VISIT_START( node ); 354 427 355 visitExpression( node->get_condition() ); 428 356 visitStatementList( node->get_statements() ); 429 357 430 358 VISIT_END( node ); 431 359 } … … 433 361 template< typename pass_type > 434 362 Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) { 435 MUTATE_START( node ); 436 363 MUTATE_START( node ); 364 437 365 node->set_condition( mutateExpression( node->get_condition() ) ); 438 366 mutateStatementList( node->get_statements() ); 439 367 440 368 MUTATE_END( Statement, node ); 441 369 } 442 370 443 //--------------------------------------------------------------------------444 // BranchStmt445 371 template< typename pass_type > 446 372 void PassVisitor< pass_type >::visit( BranchStmt * 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 ); 373 VISIT_BODY( node ); 453 374 } 454 375 … … 494 415 maybeAccept( node->get_block(), *this ); 495 416 acceptAll( node->get_catchers(), *this ); 496 maybeAccept( node->get_finally(), *this );497 417 498 418 VISIT_END( node ); … … 505 425 node->set_block( maybeMutate( node->get_block(), *this ) ); 506 426 mutateAll( node->get_catchers(), *this ); 507 node->set_finally( maybeMutate( node->get_finally(), *this ) ); 508 427 509 428 MUTATE_END( Statement, node ); 510 429 } … … 516 435 VISIT_START( node ); 517 436 437 node->set_body( visitStatement( node->get_body() ) ); 518 438 maybeAccept( node->get_decl(), *this ); 519 node->set_cond( visitExpression( node->get_cond() ) );520 node->set_body( visitStatement( node->get_body() ) );521 439 522 440 VISIT_END( node ); … … 526 444 Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) { 527 445 MUTATE_START( node ); 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 446 447 node->set_body( mutateStatement( node->get_body() ) ); 448 node->set_decl( maybeMutate( node->get_decl(), *this ) ); 449 533 450 MUTATE_END( Statement, node ); 534 451 } … … 536 453 template< typename pass_type > 537 454 void PassVisitor< pass_type >::visit( FinallyStmt * node ) { 538 VISIT_BODY( node ); 455 VISIT_BODY( node ); 539 456 } 540 457 541 458 template< typename pass_type > 542 459 void PassVisitor< pass_type >::visit( NullStmt * node ) { 543 VISIT_BODY( node ); 460 VISIT_BODY( node ); 544 461 } 545 462 546 463 template< typename pass_type > 547 464 void PassVisitor< pass_type >::visit( DeclStmt * node ) { 548 VISIT_BODY( node ); 465 VISIT_BODY( node ); 549 466 } 550 467 551 468 template< typename pass_type > 552 469 void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) { 553 VISIT_BODY( node ); 470 VISIT_BODY( node ); 554 471 } 555 472 556 473 template< typename pass_type > 557 474 void PassVisitor< pass_type >::visit( ApplicationExpr * node ) { 558 VISIT_BODY( node ); 475 VISIT_BODY( node ); 559 476 } 560 477 … … 585 502 template< typename pass_type > 586 503 void PassVisitor< pass_type >::visit( NameExpr * node ) { 587 VISIT_BODY( node ); 504 VISIT_BODY( node ); 588 505 } 589 506 590 507 template< typename pass_type > 591 508 void PassVisitor< pass_type >::visit( CastExpr * node ) { 592 VISIT_BODY( node ); 509 VISIT_BODY( node ); 593 510 } 594 511 595 512 template< typename pass_type > 596 513 void PassVisitor< pass_type >::visit( AddressExpr * node ) { 597 VISIT_BODY( node ); 514 VISIT_BODY( node ); 598 515 } 599 516 600 517 template< typename pass_type > 601 518 void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) { 602 VISIT_BODY( node ); 519 VISIT_BODY( node ); 603 520 } 604 521 605 522 template< typename pass_type > 606 523 void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) { 607 VISIT_BODY( node ); 524 VISIT_BODY( node ); 608 525 } 609 526 610 527 template< typename pass_type > 611 528 void PassVisitor< pass_type >::visit( MemberExpr * node ) { 612 VISIT_BODY( node ); 529 VISIT_BODY( node ); 613 530 } 614 531 615 532 template< typename pass_type > 616 533 void PassVisitor< pass_type >::visit( VariableExpr * node ) { 617 VISIT_BODY( node ); 534 VISIT_BODY( node ); 618 535 } 619 536 620 537 template< typename pass_type > 621 538 void PassVisitor< pass_type >::visit( ConstantExpr * node ) { 622 VISIT_BODY( node ); 539 VISIT_BODY( node ); 623 540 } 624 541 625 542 template< typename pass_type > 626 543 void PassVisitor< pass_type >::visit( SizeofExpr * node ) { 627 VISIT_BODY( node ); 544 VISIT_BODY( node ); 628 545 } 629 546 630 547 template< typename pass_type > 631 548 void PassVisitor< pass_type >::visit( AlignofExpr * node ) { 632 VISIT_BODY( node ); 549 VISIT_BODY( node ); 633 550 } 634 551 635 552 template< typename pass_type > 636 553 void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) { 637 VISIT_BODY( node ); 554 VISIT_BODY( node ); 638 555 } 639 556 640 557 template< typename pass_type > 641 558 void PassVisitor< pass_type >::visit( OffsetofExpr * node ) { 642 VISIT_BODY( node ); 559 VISIT_BODY( node ); 643 560 } 644 561 645 562 template< typename pass_type > 646 563 void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) { 647 VISIT_BODY( node ); 564 VISIT_BODY( node ); 648 565 } 649 566 650 567 template< typename pass_type > 651 568 void PassVisitor< pass_type >::visit( AttrExpr * node ) { 652 VISIT_BODY( node ); 569 VISIT_BODY( node ); 653 570 } 654 571 655 572 template< typename pass_type > 656 573 void PassVisitor< pass_type >::visit( LogicalExpr * node ) { 657 VISIT_BODY( node ); 574 VISIT_BODY( node ); 658 575 } 659 576 660 577 template< typename pass_type > 661 578 void PassVisitor< pass_type >::visit( ConditionalExpr * node ) { 662 VISIT_BODY( node ); 579 VISIT_BODY( node ); 663 580 } 664 581 665 582 template< typename pass_type > 666 583 void PassVisitor< pass_type >::visit( CommaExpr * node ) { 667 VISIT_BODY( node ); 584 VISIT_BODY( node ); 668 585 } 669 586 670 587 template< typename pass_type > 671 588 void PassVisitor< pass_type >::visit( TypeExpr * node ) { 672 VISIT_BODY( node ); 589 VISIT_BODY( node ); 673 590 } 674 591 675 592 template< typename pass_type > 676 593 void PassVisitor< pass_type >::visit( AsmExpr * node ) { 677 VISIT_BODY( node ); 594 VISIT_BODY( node ); 678 595 } 679 596 680 597 template< typename pass_type > 681 598 void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) { 682 VISIT_BODY( node ); 599 VISIT_BODY( node ); 683 600 } 684 601 685 602 template< typename pass_type > 686 603 void PassVisitor< pass_type >::visit( ConstructorExpr * node ) { 687 VISIT_BODY( node ); 604 VISIT_BODY( node ); 688 605 } 689 606 690 607 template< typename pass_type > 691 608 void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) { 692 VISIT_BODY( node ); 609 VISIT_BODY( node ); 610 } 611 612 template< typename pass_type > 613 void PassVisitor< pass_type >::visit( UntypedValofExpr * node ) { 614 VISIT_BODY( node ); 693 615 } 694 616 695 617 template< typename pass_type > 696 618 void PassVisitor< pass_type >::visit( RangeExpr * node ) { 697 VISIT_BODY( node ); 619 VISIT_BODY( node ); 698 620 } 699 621 700 622 template< typename pass_type > 701 623 void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) { 702 VISIT_BODY( node ); 624 VISIT_BODY( node ); 703 625 } 704 626 705 627 template< typename pass_type > 706 628 void PassVisitor< pass_type >::visit( TupleExpr * node ) { 707 VISIT_BODY( node ); 629 VISIT_BODY( node ); 708 630 } 709 631 710 632 template< typename pass_type > 711 633 void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) { 712 VISIT_BODY( node ); 634 VISIT_BODY( node ); 713 635 } 714 636 715 637 template< typename pass_type > 716 638 void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) { 717 VISIT_BODY( node ); 639 VISIT_BODY( node ); 718 640 } 719 641 … … 737 659 Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) { 738 660 MUTATE_START( node ); 739 661 740 662 // don't want statements from outer CompoundStmts to be added to this StmtExpr 741 663 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); … … 750 672 template< typename pass_type > 751 673 void PassVisitor< pass_type >::visit( UniqueExpr * node ) { 752 VISIT_BODY( node ); 674 VISIT_BODY( node ); 753 675 } 754 676 755 677 template< typename pass_type > 756 678 void PassVisitor< pass_type >::visit( VoidType * node ) { 757 VISIT_BODY( node ); 679 VISIT_BODY( node ); 758 680 } 759 681 760 682 template< typename pass_type > 761 683 void PassVisitor< pass_type >::visit( BasicType * node ) { 762 VISIT_BODY( node ); 684 VISIT_BODY( node ); 763 685 } 764 686 765 687 template< typename pass_type > 766 688 void PassVisitor< pass_type >::visit( PointerType * node ) { 767 VISIT_BODY( node ); 689 VISIT_BODY( node ); 768 690 } 769 691 770 692 template< typename pass_type > 771 693 void PassVisitor< pass_type >::visit( ArrayType * node ) { 772 VISIT_BODY( node ); 694 VISIT_BODY( node ); 773 695 } 774 696 775 697 template< typename pass_type > 776 698 void PassVisitor< pass_type >::visit( FunctionType * node ) { 777 VISIT_BODY( node ); 699 VISIT_BODY( node ); 778 700 } 779 701 780 702 template< typename pass_type > 781 703 void PassVisitor< pass_type >::visit( StructInstType * node ) { 782 VISIT_BODY( node ); 704 VISIT_BODY( node ); 783 705 } 784 706 785 707 template< typename pass_type > 786 708 void PassVisitor< pass_type >::visit( UnionInstType * node ) { 787 VISIT_BODY( node ); 709 VISIT_BODY( node ); 788 710 } 789 711 790 712 template< typename pass_type > 791 713 void PassVisitor< pass_type >::visit( EnumInstType * node ) { 792 VISIT_BODY( node ); 714 VISIT_BODY( node ); 793 715 } 794 716 795 717 template< typename pass_type > 796 718 void PassVisitor< pass_type >::visit( TraitInstType * node ) { 797 VISIT_BODY( node ); 719 VISIT_BODY( node ); 798 720 } 799 721 800 722 template< typename pass_type > 801 723 void PassVisitor< pass_type >::visit( TypeInstType * node ) { 802 VISIT_BODY( node ); 724 VISIT_BODY( node ); 803 725 } 804 726 805 727 template< typename pass_type > 806 728 void PassVisitor< pass_type >::visit( TupleType * node ) { 807 VISIT_BODY( node ); 729 VISIT_BODY( node ); 808 730 } 809 731 810 732 template< typename pass_type > 811 733 void PassVisitor< pass_type >::visit( TypeofType * node ) { 812 VISIT_BODY( node ); 734 VISIT_BODY( node ); 813 735 } 814 736 815 737 template< typename pass_type > 816 738 void PassVisitor< pass_type >::visit( AttrType * node ) { 817 VISIT_BODY( node ); 739 VISIT_BODY( node ); 818 740 } 819 741 820 742 template< typename pass_type > 821 743 void PassVisitor< pass_type >::visit( VarArgsType * node ) { 822 VISIT_BODY( node ); 744 VISIT_BODY( node ); 823 745 } 824 746 825 747 template< typename pass_type > 826 748 void PassVisitor< pass_type >::visit( ZeroType * node ) { 827 VISIT_BODY( node ); 749 VISIT_BODY( node ); 828 750 } 829 751 830 752 template< typename pass_type > 831 753 void PassVisitor< pass_type >::visit( OneType * node ) { 832 VISIT_BODY( node ); 754 VISIT_BODY( node ); 833 755 } 834 756 … … 855 777 template< typename pass_type > 856 778 void PassVisitor< pass_type >::visit( ListInit * node ) { 857 VISIT_BODY( node ); 779 VISIT_BODY( node ); 858 780 } 859 781 860 782 template< typename pass_type > 861 783 void PassVisitor< pass_type >::visit( ConstructorInit * node ) { 862 VISIT_BODY( node ); 784 VISIT_BODY( node ); 863 785 } 864 786 865 787 template< typename pass_type > 866 788 void PassVisitor< pass_type >::visit( Subrange * node ) { 867 VISIT_BODY( node ); 789 VISIT_BODY( node ); 868 790 } 869 791 870 792 template< typename pass_type > 871 793 void PassVisitor< pass_type >::visit( Constant * node ) { 872 VISIT_BODY( node ); 794 VISIT_BODY( node ); 873 795 } 874 796 … … 921 843 922 844 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 > 923 855 Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) { 924 856 MUTATE_BODY( Statement, node ); … … 1056 988 1057 989 template< typename pass_type > 990 Expression * PassVisitor< pass_type >::mutate( UntypedValofExpr * node ) { 991 MUTATE_BODY( Expression, node ); 992 } 993 994 template< typename pass_type > 1058 995 Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) { 1059 996 MUTATE_BODY( Expression, node ); -
src/Common/PassVisitor.proto.h
r4c03e63 re1c1829 1 1 #pragma once 2 3 template<typename pass_type>4 class PassVisitor;5 2 6 3 typedef std::function<void( void * )> cleanup_func_t; … … 34 31 35 32 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 };54 33 55 34 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- … … 133 112 FIELD_PTR( std::list< Statement* >, stmtsToAddBefore ) 134 113 FIELD_PTR( std::list< Statement* >, stmtsToAddAfter ) 135 FIELD_PTR( std::list< Declaration* >, declsToAddBefore ) 136 FIELD_PTR( std::list< Declaration* >, declsToAddAfter ) 137 FIELD_PTR( bool_ref, visit_children ) 114 FIELD_PTR( bool, skip_children ) 138 115 FIELD_PTR( at_cleanup_t, at_cleanup ) 139 FIELD_PTR( PassVisitor<pass_type> * const, visitor ) -
src/GenPoly/Box.cc
r4c03e63 re1c1829 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 21 15:49:59201713 // Update Count : 34 612 // Last Modified On : Sat May 13 09:26:38 2017 13 // Update Count : 341 14 14 // 15 15 … … 62 62 namespace GenPoly { 63 63 namespace { 64 const std::list<Label> noLabels; 65 64 66 FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars ); 65 67 … … 341 343 Statement *makeAlignTo( Expression *lhs, Expression *rhs ) { 342 344 // check that the lhs is zeroed out to the level of rhs 343 Expression *ifCond = makeOp( "?&?", lhs, makeOp( "?-?", rhs, new ConstantExpr( Constant ::from_ulong( 1) ) ) );345 Expression *ifCond = makeOp( "?&?", lhs, makeOp( "?-?", rhs, new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), "1" ) ) ) ); 344 346 // if not aligned, increment to alignment 345 347 Expression *ifExpr = makeOp( "?+=?", lhs->clone(), makeOp( "?-?", rhs->clone(), ifCond->clone() ) ); … … 384 386 385 387 // initialize size and alignment to 0 and 1 (will have at least one member to re-edit size) 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) ) ) );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" ) ) ) ); 388 390 unsigned long n_members = 0; 389 391 bool firstMember = true; … … 441 443 442 444 // calculate union layout in function body 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) ) ) );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" ) ) ) ); 445 447 for ( std::list< Declaration* >::const_iterator member = unionDecl->get_members().begin(); member != unionDecl->get_members().end(); ++member ) { 446 448 DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ); … … 1564 1566 /// Returns an index expression into the offset array for a type 1565 1567 Expression *makeOffsetIndex( Type *objectType, long i ) { 1566 ConstantExpr *fieldIndex = new ConstantExpr( Constant::from_ulong( 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() ) ); 1567 1571 UntypedExpr *fieldOffset = new UntypedExpr( new NameExpr( "?[?]" ) ); 1568 1572 fieldOffset->get_args().push_back( new NameExpr( offsetofName( mangleType( objectType ) ) ) ); … … 1777 1781 // all union members are at offset zero 1778 1782 delete offsetofExpr; 1779 return new ConstantExpr( Constant ::from_ulong( 0) );1783 return new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), "0" ) ); 1780 1784 } else return offsetofExpr; 1781 1785 } -
src/GenPoly/CopyParams.cc
r4c03e63 re1c1829 45 45 46 46 CopyParams::CopyParams() : namer( "_cp" ) {} 47 48 static const std::list< Label > noLabels; 47 49 48 50 void CopyParams::visit( FunctionDecl *funcDecl ) { -
src/GenPoly/DeclMutator.cc
r4c03e63 re1c1829 9 9 // Author : Aaron B. Moss 10 10 // Created On : Fri Nov 27 14:44:00 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thu Jun 22 13:49:00 201713 // Update Count : 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 4 11:16:43 2016 13 // Update Count : 3 14 14 // 15 15 … … 20 20 21 21 namespace GenPoly { 22 namespace { 23 const std::list<Label> noLabels; 24 } 25 22 26 DeclMutator::DeclMutator() : Mutator(), declsToAdd(1), declsToAddAfter(1) {} 23 27 24 28 DeclMutator::~DeclMutator() {} 25 29 26 30 void DeclMutator::mutateDeclarationList( std::list< Declaration* > &decls ) { 27 31 for ( std::list< Declaration* >::iterator decl = decls.begin(); ; ++decl ) { … … 30 34 31 35 if ( decl == decls.end() ) break; 32 36 33 37 // run mutator on declaration 34 38 *decl = maybeMutate( *decl, *this ); … … 51 55 newBack->splice( newBack->end(), *back ); 52 56 declsToAdd.pop_back(); 53 57 54 58 back = declsToAddAfter.rbegin(); 55 59 newBack = back + 1; … … 62 66 CompoundStmt *compoundStmt = dynamic_cast< CompoundStmt* >(stmt); 63 67 if ( compoundStmt ) return mutate( compoundStmt ); 64 68 65 69 doBeginScope(); 66 70 67 71 // run mutator on statement 68 72 stmt = maybeMutate( stmt, *this ); … … 98 102 doBeginScope(); 99 103 100 104 101 105 for ( std::list< Statement* >::iterator stmt = stmts.begin(); ; ++stmt ) { 102 106 // add any new declarations after the previous statement … … 108 112 109 113 if ( stmt == stmts.end() ) break; 110 114 111 115 // run mutator on statement 112 116 *stmt = maybeMutate( *stmt, *this ); … … 119 123 declsToAdd.back().clear(); 120 124 } 121 125 122 126 doEndScope(); 123 127 } … … 135 139 return compoundStmt; 136 140 } 137 141 138 142 Statement* DeclMutator::mutate(IfStmt *ifStmt) { 139 143 ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) ); … … 142 146 return ifStmt; 143 147 } 144 148 145 149 Statement* DeclMutator::mutate(WhileStmt *whileStmt) { 146 150 whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) ); … … 148 152 return whileStmt; 149 153 } 150 154 151 155 Statement* DeclMutator::mutate(ForStmt *forStmt) { 152 156 mutateAll( forStmt->get_initialization(), *this ); … … 156 160 return forStmt; 157 161 } 158 162 159 163 Statement* DeclMutator::mutate(SwitchStmt *switchStmt) { 160 164 switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); … … 162 166 return switchStmt; 163 167 } 164 168 165 169 Statement* DeclMutator::mutate(CaseStmt *caseStmt) { 166 170 caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) ); … … 168 172 return caseStmt; 169 173 } 170 174 171 175 Statement* DeclMutator::mutate(TryStmt *tryStmt) { 172 176 tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) ); … … 175 179 return tryStmt; 176 180 } 177 181 178 182 Statement* DeclMutator::mutate(CatchStmt *catchStmt) { 179 183 catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) ); 180 catchStmt->set_cond( maybeMutate( catchStmt->get_cond(), *this ) );181 184 catchStmt->set_body( mutateStatement( catchStmt->get_body() ) ); 182 185 return catchStmt; -
src/GenPoly/Lvalue.cc
r4c03e63 re1c1829 35 35 namespace GenPoly { 36 36 namespace { 37 const std::list<Label> noLabels; 38 37 39 /// Replace uses of lvalue returns with appropriate pointers 38 40 class Pass1 : public Mutator { -
src/GenPoly/PolyMutator.cc
r4c03e63 re1c1829 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thu Jun 22 13:47:00 201713 // Update Count : 1 711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 4 11:26:22 2016 13 // Update Count : 16 14 14 // 15 15 … … 123 123 124 124 Statement * PolyMutator::mutate(TryStmt *tryStmt) { 125 tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );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 ) );128 127 return tryStmt; 129 128 } 130 129 131 130 Statement * PolyMutator::mutate(CatchStmt *cathStmt) { 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 ) ); 131 cathStmt->set_body( mutateStatement( cathStmt->get_body() ) ); 132 cathStmt->set_decl( maybeMutate( cathStmt->get_decl(), *this ) ); 135 133 return cathStmt; 136 134 } -
src/GenPoly/Specialize.cc
r4c03e63 re1c1829 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 specialization102 if ( dynamic_cast< ZeroType * >( actualType ) ) return false;103 101 FunctionType * aftype = getFunctionType( actualType ); 104 102 assertf( aftype, "formal type is a function type, but actual type is not." ); -
src/InitTweak/FixGlobalInit.cc
r4c03e63 re1c1829 26 26 27 27 namespace InitTweak { 28 namespace { 29 const std::list<Label> noLabels; 30 } 31 28 32 class GlobalFixer : public Visitor { 29 33 public: -
src/InitTweak/FixInit.cc
r4c03e63 re1c1829 10 10 // Created On : Wed Jan 13 16:29:30 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 21 17:35:05201713 // Update Count : 7 412 // Last Modified On : Fri Mar 17 09:13:47 2017 13 // Update Count : 71 14 14 // 15 15 … … 56 56 typedef std::unordered_map< int, int > UnqCount; 57 57 58 class InsertImplicitCalls : public WithTypeSubstitution{58 class InsertImplicitCalls { 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 PassVisitor 71 72 }; 72 73 … … 191 192 }; 192 193 193 class FixInit : public WithStmtsToAdd{194 class FixInit { 194 195 public: 195 196 /// expand each object declaration to use its constructor after it is declared. … … 199 200 200 201 std::list< Declaration * > staticDtorDecls; 202 std::list< Statement * > stmtsToAddAfter; // found by PassVisitor 201 203 }; 202 204 … … 724 726 // static bool __objName_uninitialized = true 725 727 BasicType * boolType = new BasicType( Type::Qualifiers(), BasicType::Bool ); 726 SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant ::from_int( 1) ), noDesignators );728 SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant( boolType->clone(), "1" ) ), noDesignators ); 727 729 ObjectDecl * isUninitializedVar = new ObjectDecl( objDecl->get_mangleName() + "_uninitialized", Type::StorageClasses( Type::Static ), LinkageSpec::Cforall, 0, boolType, boolInitExpr ); 728 730 isUninitializedVar->fixUniqueId(); … … 731 733 UntypedExpr * setTrue = new UntypedExpr( new NameExpr( "?=?" ) ); 732 734 setTrue->get_args().push_back( new VariableExpr( isUninitializedVar ) ); 733 setTrue->get_args().push_back( new ConstantExpr( Constant ::from_int( 0) ) );735 setTrue->get_args().push_back( new ConstantExpr( Constant( boolType->clone(), "0" ) ) ); 734 736 735 737 // generate body of if -
src/InitTweak/GenInit.cc
r4c03e63 re1c1829 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"29 23 30 24 #include "SynTree/Declaration.h" … … 37 31 #include "SymTab/Autogen.h" 38 32 #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
r4c03e63 re1c1829 474 474 public: 475 475 ConstExprChecker() : isConstExpr( true ) {} 476 477 using Visitor::visit;478 476 479 477 virtual void visit( __attribute((unused)) ApplicationExpr *applicationExpr ) { isConstExpr = false; } -
src/Parser/ExpressionNode.cc
r4c03e63 re1c1829 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 21 16:44:46201713 // Update Count : 5 4112 // Last Modified On : Wed May 17 21:31:01 2017 13 // Update Count : 527 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 intv; // converted integral value64 unsigned long long 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 , v) );120 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[Unsigned][size] ), str ) ); 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 );138 135 139 136 if ( checkI( str[last] ) ) { // imaginary ? … … 153 150 } // if 154 151 155 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str , v) );152 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, kind[complx][size] ), str ) ); 156 153 delete &str; // created by lex 157 154 return ret; … … 159 156 160 157 Expression *build_constantChar( const std::string & str ) { 161 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str , (unsigned long long int)(unsigned char)str[1]) );158 Expression * ret = new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::Char ), str ) ); 162 159 delete &str; // created by lex 163 160 return ret; … … 167 164 // string should probably be a primitive type 168 165 ArrayType *at = new ArrayType( emptyQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), 169 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 166 new ConstantExpr( Constant( new BasicType( emptyQualifiers, BasicType::UnsignedInt ), 167 toString( str.size()+1-2 ) ) ), // +1 for '\0' and -2 for '"' 170 168 false, false ); 171 // constant 0 is ignored for pure string value 172 ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); 169 ConstantExpr * ret = new ConstantExpr( Constant( at, str ) ); 173 170 delete &str; // created by lex 174 171 return ret; … … 176 173 177 174 Expression *build_constantZeroOne( const std::string & 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 ) ); 175 Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( emptyQualifiers ) : (Type*)new OneType( emptyQualifiers ), str ) ); 180 176 delete &str; // created by lex 181 177 return ret; … … 188 184 std::stringstream ss( str ); 189 185 ss >> a >> dot >> b; 190 UntypedMemberExpr * ret = new UntypedMemberExpr( new ConstantExpr( Constant::from_int( b ) ), new ConstantExpr( Constant::from_int( a ) ) ); 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 ) ) ) ); 191 189 delete &str; 192 190 return ret; … … 348 346 349 347 Expression *build_valexpr( StatementNode *s ) { 350 return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ));348 return new UntypedValofExpr( maybeMoveBuild< Statement >(s), nullptr ); 351 349 } 352 350 Expression *build_typevalue( DeclarationNode *decl ) { -
src/Parser/ParseNode.h
r4c03e63 re1c1829 415 415 result->location = cur->location; 416 416 * out++ = result; 417 } else {418 assertf(false, "buildList unknown type");419 417 } // if 420 418 } catch( SemanticError &e ) { -
src/Parser/StatementNode.cc
r4c03e63 re1c1829 168 168 169 169 Statement *build_resume_at( ExpressionNode *ctl, ExpressionNode *target ) { 170 (void)ctl; 171 (void)target; 172 assertf( false, "resume at (non-local throw) is not yet supported," ); 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 ); 173 174 } 174 175 175 176 Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) { 176 std::list< CatchStmt * > branches;177 buildMoveList< CatchStmt, StatementNode >( catch_stmt, branches );177 std::list< Statement * > branches; 178 buildMoveList< Statement, StatementNode >( catch_stmt, branches ); 178 179 CompoundStmt *tryBlock = safe_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt)); 179 180 FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) ); -
src/Parser/parseutility.cc
r4c03e63 re1c1829 10 10 // Created On : Sat May 16 15:30:39 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 21 15:33:41 201713 // Update Count : 512 // Last Modified On : Sun Aug 14 23:45:03 2016 13 // Update Count : 3 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" , (unsigned long long int)0) ) );28 comparison->get_args().push_back( new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0" ) ) ); 29 29 return new CastExpr( comparison, new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 30 30 } -
src/SymTab/Autogen.h
r4c03e63 re1c1829 10 10 // Created On : Sun May 17 21:53:34 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 21 17:25:26201713 // Update Count : 1412 // Last Modified On : Fri Mar 17 09:10:41 2017 13 // Update Count : 9 14 14 // 15 15 … … 25 25 26 26 namespace SymTab { 27 /// Generates assignment operators, constructors, and destructor for aggregate types as required28 void autogenerateRoutines( std::list< Declaration * > &translationUnit );27 /// Generates assignment operators, constructors, and destructor for aggregate types as required 28 void autogenerateRoutines( std::list< Declaration * > &translationUnit ); 29 29 30 /// returns true if obj's name is the empty string and it has a bitfield width31 bool isUnnamedBitfield( ObjectDecl * obj );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 /// size_t type - set when size_t typedef is seen. Useful in a few places,34 /// such as in determining array dimension type35 extern Type * SizeType;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 /// 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 >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 /// 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 one43 template< typename OutputIterator >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 // 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 ) );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 // do something special for unnamed members50 dstParam = new AddressExpr( dstParam );51 if ( addCast ) {52 // cast to T* with qualifiers removed, so that qualified objects can be constructed53 // and destructed with the same functions as non-qualified objects.54 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument55 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever56 // remove lvalue as a qualifier, this can change to57 // type->get_qualifiers() = Type::Qualifiers();58 assert( type );59 Type * castType = type->clone();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 castType->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic );62 castType->set_lvalue( true ); // xxx - might not need this63 dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) );64 }65 fExpr->get_args().push_back( dstParam );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 Statement * listInit = srcParam.buildListInit( fExpr );67 Statement * listInit = srcParam.buildListInit( fExpr ); 68 68 69 std::list< Expression * > args = *++srcParam;70 fExpr->get_args().splice( fExpr->get_args().end(), args );69 std::list< Expression * > args = *++srcParam; 70 fExpr->get_args().splice( fExpr->get_args().end(), args ); 71 71 72 *out++ = new ExprStmt( noLabels, fExpr );72 *out++ = new ExprStmt( noLabels, fExpr ); 73 73 74 srcParam.clearArrayIndices();74 srcParam.clearArrayIndices(); 75 75 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( "--?" ); 76 return listInit; 103 77 } 104 78 105 ObjectDecl *index = new ObjectDecl( indexName.newName(), Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), new SingleInit( begin, std::list<Expression*>() ) ); 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" ); 106 84 107 UntypedExpr *cond = new UntypedExpr( cmp ); 108 cond->get_args().push_back( new VariableExpr( index ) ); 109 cond->get_args().push_back( end ); 85 // for a flexible array member nothing is done -- user must define own assignment 86 if ( ! array->get_dimension() ) return ; 110 87 111 UntypedExpr *inc = new UntypedExpr( update ); 112 inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) ); 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 } 113 104 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; 105 ObjectDecl *index = new ObjectDecl( indexName.newName(), Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), new SingleInit( begin, std::list<Expression*>() ) ); 118 106 119 // srcParam must keep track of the array indices to build the120 // source parameter and/or array list initializer121 srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone());107 UntypedExpr *cond = new UntypedExpr( cmp ); 108 cond->get_args().push_back( new VariableExpr( index ) ); 109 cond->get_args().push_back( end ); 122 110 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 ); 111 UntypedExpr *inc = new UntypedExpr( update ); 112 inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) ); 126 113 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 ) ); 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; 133 118 134 *out++ = block; 135 } 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() ); 136 122 137 template< typename OutputIterator > 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 ); 126 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 ) ); 133 134 *out++ = block; 135 } 136 137 template< typename OutputIterator > 138 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 ); 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 } 144 145 } 145 }146 146 147 /// inserts into out a generated call expression to function fname with arguments dstParam148 /// and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. decl is the149 /// object being constructed. The function wraps constructor and destructor calls in an150 /// ImplicitCtorDtorStmt node.151 template< typename OutputIterator >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 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 accessed156 if ( isUnnamedBitfield( obj ) ) return;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 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 );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 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; 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 } 174 175 } 175 }176 176 } // namespace SymTab 177 177 #endif // AUTOGEN_H -
src/SymTab/Indexer.cc
r4c03e63 re1c1829 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 ); 495 500 } 496 501 -
src/SymTab/Indexer.h
r4c03e63 re1c1829 69 69 virtual void visit( ConstructorExpr * ctorExpr ); 70 70 virtual void visit( CompoundLiteralExpr *compLitExpr ); 71 virtual void visit( UntypedValofExpr *valofExpr ); 71 72 virtual void visit( RangeExpr *rangeExpr ); 72 73 virtual void visit( UntypedTupleExpr *tupleExpr ); -
src/SymTab/Validate.cc
r4c03e63 re1c1829 66 66 #include "ResolvExpr/typeops.h" 67 67 68 #include "SynTree/Attribute.h"69 68 #include "SynTree/Expression.h" 70 69 #include "SynTree/Mutator.h" … … 115 114 116 115 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers. 117 class EnumAndPointerDecay {118 public:119 v oid previsit( EnumDecl *aggregateDecl );120 v oid previsit( FunctionType *func );116 class EnumAndPointerDecayPass final : public Visitor { 117 typedef Visitor Parent; 118 virtual void visit( EnumDecl *aggregateDecl ); 119 virtual void visit( FunctionType *func ); 121 120 }; 122 121 … … 126 125 public: 127 126 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 private: 137 138 138 const Indexer *indexer; 139 139 … … 146 146 }; 147 147 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 ForallPointerDecayfinal : public Indexer {148 /// Replaces array and function types in forall lists by appropriate pointer type 149 class Pass3 final : public Indexer { 150 150 typedef Indexer Parent; 151 151 public: 152 152 using Parent::visit; 153 ForallPointerDecay( const Indexer *indexer );154 153 Pass3( const Indexer *indexer ); 154 private: 155 155 virtual void visit( ObjectDecl *object ) override; 156 156 virtual void visit( FunctionDecl *func ) override; … … 159 159 }; 160 160 161 class ReturnChecker : public WithScopes{161 class ReturnChecker { 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 ); 168 169 void previsit( ReturnStmt * returnStmt ); 169 170 170 171 typedef std::list< DeclarationWithType * > ReturnVals; 171 172 ReturnVals returnVals; 173 std::stack< ReturnVals > returnValsStack; 172 174 }; 173 175 … … 245 247 246 248 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 247 PassVisitor<EnumAndPointerDecay>epc;249 EnumAndPointerDecayPass epc; 248 250 LinkReferenceToTypes lrt( doDebug, 0 ); 249 ForallPointerDecay fpd( 0 );251 Pass3 pass3( 0 ); 250 252 CompoundLiteral compoundliteral; 251 253 PassVisitor<ValidateGenericParameters> genericParams; … … 259 261 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 260 262 Concurrency::applyKeywords( translationUnit ); 261 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay 263 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecayPass 262 264 Concurrency::implementMutexFuncs( translationUnit ); 263 265 Concurrency::implementThreadStarter( translationUnit ); 264 266 ReturnChecker::checkFunctionReturns( translationUnit ); 265 267 compoundliteral.mutateDeclarationList( translationUnit ); 266 acceptAll( translationUnit, fpd);268 acceptAll( translationUnit, pass3 ); 267 269 ArrayLength::computeLength( translationUnit ); 268 270 } 269 271 270 272 void validateType( Type *type, const Indexer *indexer ) { 271 PassVisitor<EnumAndPointerDecay>epc;273 EnumAndPointerDecayPass epc; 272 274 LinkReferenceToTypes lrt( false, indexer ); 273 ForallPointerDecay fpd( indexer );275 Pass3 pass3( indexer ); 274 276 type->accept( epc ); 275 277 type->accept( lrt ); 276 type->accept( fpd);278 type->accept( pass3 ); 277 279 } 278 280 … … 353 355 } 354 356 355 void EnumAndPointerDecay ::previsit( EnumDecl *enumDecl ) {357 void EnumAndPointerDecayPass::visit( EnumDecl *enumDecl ) { 356 358 // Set the type of each member of the enumeration to be EnumConstant 357 359 for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) { … … 360 362 obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) ); 361 363 } // for 364 Parent::visit( enumDecl ); 362 365 } 363 366 … … 366 369 void fixFunctionList( DWTList & dwts, FunctionType * func ) { 367 370 // the only case in which "void" is valid is where it is the only one in the list; then it should be removed 368 // entirely .other fix ups are handled by the FixFunction class371 // entirely other fix ups are handled by the FixFunction class 369 372 typedef typename DWTList::iterator DWTIterator; 370 373 DWTIterator begin( dwts.begin() ), end( dwts.end() ); … … 385 388 for ( ; i != end; ++i ) { 386 389 FixFunction fixer; 387 *i = (*i )->acceptMutator( fixer );390 *i = (*i )->acceptMutator( fixer ); 388 391 if ( fixer.get_isVoid() ) { 389 392 throw SemanticError( "invalid type void in function type ", func ); … … 394 397 } 395 398 396 void EnumAndPointerDecay ::previsit( FunctionType *func ) {399 void EnumAndPointerDecayPass::visit( FunctionType *func ) { 397 400 // Fix up parameters and return types 398 401 fixFunctionList( func->get_parameters(), func ); 399 402 fixFunctionList( func->get_returnVals(), func ); 403 Visitor::visit( func ); 400 404 } 401 405 … … 544 548 } 545 549 546 ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) : Indexer( false ) {550 Pass3::Pass3( const Indexer *other_indexer ) : Indexer( false ) { 547 551 if ( other_indexer ) { 548 552 indexer = other_indexer; … … 582 586 } 583 587 584 void ForallPointerDecay::visit( ObjectDecl *object ) {588 void Pass3::visit( ObjectDecl *object ) { 585 589 forallFixer( object->get_type() ); 586 590 if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) { … … 591 595 } 592 596 593 void ForallPointerDecay::visit( FunctionDecl *func ) {597 void Pass3::visit( FunctionDecl *func ) { 594 598 forallFixer( func->get_type() ); 595 599 Parent::visit( func ); … … 603 607 604 608 void ReturnChecker::previsit( FunctionDecl * functionDecl ) { 605 GuardValue( returnVals );609 returnValsStack.push( returnVals ); 606 610 returnVals = functionDecl->get_functionType()->get_returnVals(); 611 } 612 void ReturnChecker::postvisit( __attribute__((unused)) FunctionDecl * functionDecl ) { 613 returnVals = returnValsStack.top(); 614 returnValsStack.pop(); 607 615 } 608 616 … … 919 927 ret->set_name( toString( "_retval_", CodeGen::genName( functionDecl ) ) ); 920 928 } 921 ret->get_attributes().push_back( new Attribute( "unused" ) );922 929 } 923 930 } -
src/SynTree/Attribute.h
r4c03e63 re1c1829 40 40 }; 41 41 42 const std::list< Attribute * > noAttributes;43 44 42 #endif 45 43 -
src/SynTree/BaseSyntaxNode.h
r4c03e63 re1c1829 24 24 CodeLocation location; 25 25 26 virtual ~BaseSyntaxNode() {} 27 28 virtual void accept( Visitor & v ) = 0; 26 virtual void accept( Visitor & v ) = 0; // temporary -- needs to be here so that BaseSyntaxNode is polymorphic and can be dynamic_cast 29 27 }; 30 28 -
src/SynTree/Constant.cc
r4c03e63 re1c1829 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Th r Jun 22 10:11:00 201713 // Update Count : 2811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 30 15:18:38 2015 13 // Update Count : 12 14 14 // 15 15 … … 21 21 #include "Type.h" 22 22 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 ) {} 23 Constant::Constant( Type *type_, std::string value_ ) : type( type_ ), value( value_ ) {} 25 24 26 Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ){25 Constant::Constant( const Constant &other ) { 27 26 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 36 32 Constant Constant::from_int( int i ) { 37 return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ) , (unsigned long long int)i);33 return Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), std::to_string( i ) ); 38 34 } 39 35 40 36 Constant Constant::from_ulong( unsigned long i ) { 41 return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ) , (unsigned long long int)i);37 return Constant( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), std::to_string( i ) ); 42 38 } 43 39 44 40 Constant Constant::from_double( double d ) { 45 return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ) , d);41 return Constant( new BasicType( Type::Qualifiers(), BasicType::Double ), std::to_string( d ) ); 46 42 } 47 43 44 Constant *Constant::clone() const { assert( false ); return 0; } 45 48 46 void Constant::print( std::ostream &os ) const { 49 os << "(" << rep << " " << val.ival;47 os << "(" << value; 50 48 if ( type ) { 51 49 os << ": "; -
src/SynTree/Constant.h
r4c03e63 re1c1829 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Th r Jun 22 10:13:00 201713 // Update Count : 1511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 30 13:33:17 2016 13 // Update Count : 6 14 14 // 15 15 … … 23 23 class Constant { 24 24 public: 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 ); 25 Constant( Type *type, std::string value ); 26 Constant( const Constant &other ); 28 27 virtual ~Constant(); 29 28 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; }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; } 34 33 35 /// generates a boolean constant of the given bool36 static Constant from_bool( bool b );37 34 /// generates an integer constant of the given int 38 35 static Constant from_int( int i ); … … 42 39 static Constant from_double( double d ); 43 40 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; 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; 47 45 private: 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; 46 Type *type; 47 std::string value; 56 48 }; 57 49 -
src/SynTree/Expression.cc
r4c03e63 re1c1829 288 288 } 289 289 290 // CastExpr *CastExpr::clone() const { return 0; } 291 290 292 void CastExpr::print( std::ostream &os, int indent ) const { 291 293 os << "Cast of:" << std::endl << std::string( indent+2, ' ' ); … … 353 355 } 354 356 357 //// is this right? It's cloning the member, but the member is a declaration so probably shouldn't be cloned... 355 358 MemberExpr::MemberExpr( const MemberExpr &other ) : 356 359 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { … … 358 361 359 362 MemberExpr::~MemberExpr() { 360 // d on't delete the member declaration, since it points somewhere else in the tree363 // delete member; 361 364 delete aggregate; 362 365 } … … 588 591 } 589 592 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 590 603 RangeExpr::RangeExpr( Expression *low, Expression *high ) : low( low ), high( high ) {} 591 604 RangeExpr::RangeExpr( const RangeExpr &other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {} -
src/SynTree/Expression.h
r4c03e63 re1c1829 226 226 }; 227 227 228 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer. 229 /// Does not take ownership of member. 228 /// MemberExpr represents a member selection operation, e.g. q.p after processing by the expression analyzer 230 229 class MemberExpr : public Expression { 231 230 public: … … 248 247 }; 249 248 250 /// VariableExpr represents an expression that simply refers to the value of a named variable. 251 /// Does not take ownership of var. 249 /// VariableExpr represents an expression that simply refers to the value of a named variable 252 250 class VariableExpr : public Expression { 253 251 public: … … 600 598 }; 601 599 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 602 618 /// RangeExpr represents a range e.g. '3 ... 5' or '1~10' 603 619 class RangeExpr : public Expression { -
src/SynTree/Mutator.cc
r4c03e63 re1c1829 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Jun 22 13:43:00 201713 // Update Count : 2 412 // Last Modified On : Thu Mar 8 16:36:00 2017 13 // Update Count : 23 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 ) );165 164 return tryStmt; 166 165 } … … 168 167 Statement *Mutator::mutate( CatchStmt *catchStmt ) { 169 168 catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) ); 170 catchStmt->set_cond( maybeMutate( catchStmt->get_cond(), *this ) );171 169 catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) ); 172 170 return catchStmt; … … 382 380 } 383 381 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 384 388 Expression *Mutator::mutate( RangeExpr *rangeExpr ) { 385 389 rangeExpr->set_env( maybeMutate( rangeExpr->get_env(), *this ) ); -
src/SynTree/Mutator.h
r4c03e63 re1c1829 78 78 virtual Expression* mutate( ConstructorExpr *ctorExpr ); 79 79 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ); 80 virtual Expression* mutate( UntypedValofExpr *valofExpr ); 80 81 virtual Expression* mutate( RangeExpr *rangeExpr ); 81 82 virtual Expression* mutate( UntypedTupleExpr *tupleExpr ); -
src/SynTree/ObjectDecl.cc
r4c03e63 re1c1829 56 56 57 57 if ( init ) { 58 os << " with initializer " << std::endl;59 init->print( os, indent +2);60 os << std::endl << std::string(indent +2, ' ');58 os << " with initializer "; 59 init->print( os, indent ); 60 os << std::endl << std::string(indent, ' '); 61 61 os << "maybeConstructed? " << init->get_maybeConstructed(); 62 62 } // if -
src/SynTree/Statement.cc
r4c03e63 re1c1829 313 313 } 314 314 315 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list< CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) :315 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &_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< CatchStmt *>::const_iterator i = handlers.begin(); i != handlers.end(); i++)336 for ( std::list<Statement *>::const_iterator i = handlers.begin(); i != handlers.end(); i++) 337 337 (*i )->print( os, indent + 4 ); 338 338 -
src/SynTree/Statement.h
r4c03e63 re1c1829 315 315 class TryStmt : public Statement { 316 316 public: 317 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list< CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );317 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &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< CatchStmt *>& get_catchers() { return handlers; }323 std::list<Statement *>& get_catchers() { return handlers; } 324 324 325 325 FinallyStmt *get_finally() const { return finallyBlock; } … … 333 333 private: 334 334 CompoundStmt *block; 335 std::list< CatchStmt *> handlers;335 std::list<Statement *> handlers; 336 336 FinallyStmt *finallyBlock; 337 337 }; -
src/SynTree/Visitor.cc
r4c03e63 re1c1829 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu Jun 22 13:41:00 201713 // Update Count : 2 612 // Last Modified On : Thu Jun 8 16:31:00 2017 13 // Update Count : 25 14 14 // 15 15 … … 137 137 maybeAccept( tryStmt->get_block(), *this ); 138 138 acceptAll( tryStmt->get_catchers(), *this ); 139 maybeAccept( tryStmt->get_finally(), *this );140 139 } 141 140 142 141 void Visitor::visit( CatchStmt *catchStmt ) { 143 142 maybeAccept( catchStmt->get_decl(), *this ); 144 maybeAccept( catchStmt->get_cond(), *this );145 143 maybeAccept( catchStmt->get_body(), *this ); 146 144 } … … 301 299 maybeAccept( compLitExpr->get_result(), *this ); 302 300 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 ); 303 306 } 304 307 -
src/SynTree/Visitor.h
r4c03e63 re1c1829 81 81 virtual void visit( ConstructorExpr * ctorExpr ); 82 82 virtual void visit( CompoundLiteralExpr *compLitExpr ); 83 virtual void visit( UntypedValofExpr *valofExpr ); 83 84 virtual void visit( RangeExpr *rangeExpr ); 84 85 virtual void visit( UntypedTupleExpr *tupleExpr ); … … 162 163 } // if 163 164 } catch( SemanticError &e ) { 164 e.set_location( (*i)->location ); 165 e.set_location( (*i)->location ); 165 166 errors.append( e ); 166 167 } // try -
src/Tuples/TupleExpansion.cc
r4c03e63 re1c1829 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 21 17:35:04201713 // Update Count : 1 912 // Last Modified On : Thu Mar 16 08:05:17 2017 13 // Update Count : 15 14 14 // 15 15 … … 191 191 commaExpr->set_arg1( nullptr ); 192 192 } 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 ) );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 ) ); 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 ::from_int( 1) ) );198 Expression * assignFinished = UntypedExpr::createAssign( new VariableExpr(finished), new ConstantExpr( Constant( boolType->clone(), "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
r4c03e63 re1c1829 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 __attribute__ ((unused))int ___retval_f0__i_1;8 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 __attribute__ ((unused))int ___retval_f1__i_1;11 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 __attribute__ ((unused))int ___retval_f2__i_1;14 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 __attribute__ ((unused))int ___retval_f3__i_1;42 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 __attribute__ ((unused))int ___retval_f4__i_1;46 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 __attribute__ ((unused))int ___retval_f5__i_1;49 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 __attribute__ ((unused))int (*___retval_f6__PFi_i__1)(int __anonymous_object1);52 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 __attribute__ ((unused))int (*___retval_f7__PFi_ii__1)(int __a__i_1, int __b__i_1);55 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 __attribute__ ((unused))int *___retval_f8__Pi_1;58 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 __attribute__ ((unused))int *const ___retval_f9__CPi_1;61 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 __attribute__ ((unused))int *(*___retval_f10__PFPi_ii__1)(int __x__i_1, int __y__i_1);64 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 __attribute__ ((unused))int (*___retval_f11__PA0i_1)[];70 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 __attribute__ ((unused))int (*___retval_f12__PA0A0i_1)[][((unsigned int )10)];73 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 __attribute__ ((unused))int (*___retval_f13__PA0A0i_1)[][((unsigned int )10)];76 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 __attribute__ ((unused))int (*___retval_f14__PA0A0i_1)[][((unsigned int )10)];79 int (*___retval_f14__PA0A0i_1)[][((unsigned int )10)]; 80 80 } 81 81 const int __fred__FCi___1(){ 82 __attribute__ ((unused))const int ___retval_fred__Ci_1;82 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 __attribute__ ((unused))const int ___retval_f1__Ci_2;90 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 __attribute__ ((unused))const int ___retval_f2__Ci_2;93 const int ___retval_f2__Ci_2; 94 94 } 95 95 } -
src/tests/.expect/32/attributes.txt
r4c03e63 re1c1829 6 6 extern int printf(const char *__restrict __format, ...); 7 7 int __la__Fi___1(){ 8 __attribute__ ((unused))int ___retval_la__i_1;8 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 __attribute__ ((unused))int ___retval_f1__i_1;228 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 __attribute__ ((unused))int **const ___retval_f2__CPPi_1;232 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 __attribute__ ((unused))int (*___retval_f3__PA0i_1)[];236 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 __attribute__ ((unused))int (*___retval_f4__PFi_i__1)(int __anonymous_object4);240 int (*___retval_f4__PFi_i__1)(int __anonymous_object4); 241 241 } 242 242 int __vtr__Fi___1(){ 243 __attribute__ ((unused))int ___retval_vtr__i_1;243 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 __attribute__ ((unused))int ___retval_ipd1__i_1;253 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 __attribute__ ((unused))int ___retval_ipd2__i_1;257 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 __attribute__ ((unused))int ___retval_ipd3__i_1;261 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 __attribute__ ((unused))int ___retval_ipd4__i_1;265 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 __attribute__ ((unused))int ___retval_ad__i_1;275 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
r4c03e63 re1c1829 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 __attribute__ ((unused))int ___retval_main__i_1;672 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 __attribute__ ((unused))int ___retval_main__i_1;687 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
r4c03e63 re1c1829 85 85 __extension__ int j; 86 86 __extension__ int __fred__Fi_i__1(int __p__i_1){ 87 __attribute__ ((unused))int ___retval_fred__i_1;87 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 __attribute__ ((unused))int ___retval_mary__i_2;107 int ___retval_mary__i_2; 108 108 } 109 109 ((void)__extension__ sizeof(3)); -
src/tests/.expect/32/gccExtensions.txt
r4c03e63 re1c1829 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 __attribute__ ((unused))int ___retval_main__i_1;9 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 __attribute__ ((unused))int ___retval_f1__i_2;28 int ___retval_f1__i_2; 29 29 } 30 30 inline int __f2__Fi___2(){ 31 __attribute__ ((unused))int ___retval_f2__i_2;31 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 __attribute__ ((unused))int ___retval_main__i_1;184 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
r4c03e63 re1c1829 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 __attribute__ ((unused))int ___retval_f0__i_1;8 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 __attribute__ ((unused))int ___retval_f1__i_1;11 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 __attribute__ ((unused))int ___retval_f2__i_1;14 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 __attribute__ ((unused))int ___retval_f3__i_1;42 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 __attribute__ ((unused))int ___retval_f4__i_1;46 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 __attribute__ ((unused))int ___retval_f5__i_1;49 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 __attribute__ ((unused))int (*___retval_f6__PFi_i__1)(int __anonymous_object1);52 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 __attribute__ ((unused))int (*___retval_f7__PFi_ii__1)(int __a__i_1, int __b__i_1);55 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 __attribute__ ((unused))int *___retval_f8__Pi_1;58 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 __attribute__ ((unused))int *const ___retval_f9__CPi_1;61 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 __attribute__ ((unused))int *(*___retval_f10__PFPi_ii__1)(int __x__i_1, int __y__i_1);64 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 __attribute__ ((unused))int (*___retval_f11__PA0i_1)[];70 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 __attribute__ ((unused))int (*___retval_f12__PA0A0i_1)[][((long unsigned int )10)];73 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 __attribute__ ((unused))int (*___retval_f13__PA0A0i_1)[][((long unsigned int )10)];76 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 __attribute__ ((unused))int (*___retval_f14__PA0A0i_1)[][((long unsigned int )10)];79 int (*___retval_f14__PA0A0i_1)[][((long unsigned int )10)]; 80 80 } 81 81 const int __fred__FCi___1(){ 82 __attribute__ ((unused))const int ___retval_fred__Ci_1;82 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 __attribute__ ((unused))const int ___retval_f1__Ci_2;90 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 __attribute__ ((unused))const int ___retval_f2__Ci_2;93 const int ___retval_f2__Ci_2; 94 94 } 95 95 } -
src/tests/.expect/64/attributes.txt
r4c03e63 re1c1829 6 6 extern int printf(const char *__restrict __format, ...); 7 7 int __la__Fi___1(){ 8 __attribute__ ((unused))int ___retval_la__i_1;8 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 __attribute__ ((unused))int ___retval_f1__i_1;228 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 __attribute__ ((unused))int **const ___retval_f2__CPPi_1;232 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 __attribute__ ((unused))int (*___retval_f3__PA0i_1)[];236 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 __attribute__ ((unused))int (*___retval_f4__PFi_i__1)(int __anonymous_object4);240 int (*___retval_f4__PFi_i__1)(int __anonymous_object4); 241 241 } 242 242 int __vtr__Fi___1(){ 243 __attribute__ ((unused))int ___retval_vtr__i_1;243 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 __attribute__ ((unused))int ___retval_ipd1__i_1;253 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 __attribute__ ((unused))int ___retval_ipd2__i_1;257 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 __attribute__ ((unused))int ___retval_ipd3__i_1;261 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 __attribute__ ((unused))int ___retval_ipd4__i_1;265 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 __attribute__ ((unused))int ___retval_ad__i_1;275 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
r4c03e63 re1c1829 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 __attribute__ ((unused))int ___retval_main__i_1;672 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 __attribute__ ((unused))int ___retval_main__i_1;687 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
r4c03e63 re1c1829 85 85 __extension__ int j; 86 86 __extension__ int __fred__Fi_i__1(int __p__i_1){ 87 __attribute__ ((unused))int ___retval_fred__i_1;87 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 __attribute__ ((unused))int ___retval_mary__i_2;107 int ___retval_mary__i_2; 108 108 } 109 109 ((void)__extension__ sizeof(3)); -
src/tests/.expect/64/gccExtensions.txt
r4c03e63 re1c1829 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 __attribute__ ((unused))int ___retval_main__i_1;9 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 __attribute__ ((unused))int ___retval_f1__i_2;28 int ___retval_f1__i_2; 29 29 } 30 30 inline int __f2__Fi___2(){ 31 __attribute__ ((unused))int ___retval_f2__i_2;31 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 __attribute__ ((unused))int ___retval_main__i_1;184 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
r4c03e63 re1c1829 3 3 with parameters 4 4 double 5 returning 6 _retval_butThisIsAnError: Attribute with name: unused 7 double 8 with body 5 returning 6 _retval_butThisIsAnError: double 7 with body 9 8 CompoundStmt
Note:
See TracChangeset
for help on using the changeset viewer.