Changeset 7880579
- Timestamp:
- Aug 16, 2016, 8:59:49 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 0da3e2c, 13e3b50, 7527e63
- Parents:
- b1848a0
- Location:
- src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rb1848a0 r7880579 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 15 14:30:25 201613 // Update Count : 17 212 // Last Modified On : Mon Aug 15 20:48:55 2016 13 // Update Count : 178 14 14 // 15 15 … … 49 49 newnode->name = name; 50 50 newnode->storageClasses = storageClasses; 51 //PAB newnode->bitfieldWidth = maybeClone( bitfieldWidth );52 51 newnode->bitfieldWidth = bitfieldWidth; 53 52 newnode->hasEllipsis = hasEllipsis; 54 53 newnode->initializer = initializer; 55 newnode-> next = maybeClone( next);54 newnode->set_next( maybeClone( get_next() ) ); 56 55 newnode->linkage = linkage; 57 56 return newnode; … … 284 283 newnode->type->array->dimension = size; 285 284 newnode->type->array->isStatic = isStatic; 286 if ( newnode->type->array->dimension == 0 || dynamic_cast< ConstantExpr *>( newnode->type->array->dimension->build() ) ) {285 if ( newnode->type->array->dimension == 0 || dynamic_cast< ConstantExpr * >( newnode->type->array->dimension->build() ) ) { 287 286 newnode->type->array->isVarLen = false; 288 287 } else { … … 776 775 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ) { 777 776 SemanticError errors; 778 std::back_insert_iterator< std::list< Declaration * > > out( outputList );777 std::back_insert_iterator< std::list< Declaration * > > out( outputList ); 779 778 const DeclarationNode *cur = firstNode; 780 779 while ( cur ) { … … 794 793 errors.append( e ); 795 794 } // try 796 cur = dynamic_cast< DeclarationNode *>( cur->get_next() );795 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 797 796 } // while 798 797 if ( ! errors.isEmpty() ) { … … 801 800 } 802 801 803 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ) {802 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ) { 804 803 SemanticError errors; 805 std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );804 std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList ); 806 805 const DeclarationNode *cur = firstNode; 807 806 while ( cur ) { … … 817 816 Declaration *decl = cur->build(); 818 817 if ( decl ) { 819 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {818 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( decl ) ) { 820 819 *out++ = dwt; 821 } else if ( StructDecl *agg = dynamic_cast< StructDecl * >( decl ) ) {820 } else if ( StructDecl *agg = dynamic_cast< StructDecl * >( decl ) ) { 822 821 StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 823 822 *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); 824 823 delete agg; 825 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl * >( decl ) ) {824 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl * >( decl ) ) { 826 825 UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 827 826 *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); … … 831 830 errors.append( e ); 832 831 } // try 833 cur = dynamic_cast< DeclarationNode * >( cur->get_next() );832 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 834 833 } // while 835 834 if ( ! errors.isEmpty() ) { … … 838 837 } 839 838 840 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ) {839 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ) { 841 840 SemanticError errors; 842 std::back_insert_iterator< std::list< Type * > > out( outputList );841 std::back_insert_iterator< std::list< Type * > > out( outputList ); 843 842 const DeclarationNode *cur = firstNode; 844 843 while ( cur ) { … … 848 847 errors.append( e ); 849 848 } // try 850 cur = dynamic_cast< DeclarationNode * >( cur->get_next() );849 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 851 850 } // while 852 851 if ( ! errors.isEmpty() ) { -
src/Parser/ExpressionNode.cc
rb1848a0 r7880579 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 15 14:30:42201613 // Update Count : 49 012 // Last Modified On : Tue Aug 16 00:09:20 2016 13 // Update Count : 495 14 14 // 15 15 … … 32 32 using namespace std; 33 33 34 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other. name), extension( other.extension ) {}34 ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.get_name() ), extension( other.extension ) {} 35 35 36 36 //############################################################################## … … 166 166 } // build_constantStr 167 167 168 //##############################################################################169 170 168 NameExpr * build_varref( const string *name, bool labelp ) { 171 169 return new NameExpr( *name, nullptr ); 172 170 } 173 174 //##############################################################################175 171 176 172 static const char *OperName[] = { … … 184 180 }; 185 181 186 //##############################################################################187 188 182 Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) { 189 183 Type *targetType = decl_node->buildType(); 190 184 if ( dynamic_cast< VoidType * >( targetType ) ) { 191 185 delete targetType; 192 return new CastExpr( maybeBuild< Expression>(expr_node) );186 return new CastExpr( maybeBuild< Expression >(expr_node) ); 193 187 } else { 194 return new CastExpr( maybeBuild< Expression>(expr_node), targetType );188 return new CastExpr( maybeBuild< Expression >(expr_node), targetType ); 195 189 } // if 196 190 } 197 191 198 192 Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member ) { 199 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeBuild< Expression>(expr_node) );193 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), maybeBuild< Expression >(expr_node) ); 200 194 delete member; 201 195 return ret; … … 204 198 Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member ) { 205 199 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) ); 206 deref->get_args().push_back( maybeBuild< Expression>(expr_node) );200 deref->get_args().push_back( maybeBuild< Expression >(expr_node) ); 207 201 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref ); 208 202 delete member; … … 211 205 212 206 Expression *build_addressOf( ExpressionNode *expr_node ) { 213 return new AddressExpr( maybeBuild< Expression>(expr_node) );207 return new AddressExpr( maybeBuild< Expression >(expr_node) ); 214 208 } 215 209 Expression *build_sizeOfexpr( ExpressionNode *expr_node ) { 216 return new SizeofExpr( maybeBuild< Expression>(expr_node) );210 return new SizeofExpr( maybeBuild< Expression >(expr_node) ); 217 211 } 218 212 Expression *build_sizeOftype( DeclarationNode *decl_node ) { … … 220 214 } 221 215 Expression *build_alignOfexpr( ExpressionNode *expr_node ) { 222 return new AlignofExpr( maybeBuild< Expression>(expr_node) );216 return new AlignofExpr( maybeBuild< Expression >(expr_node) ); 223 217 } 224 218 Expression *build_alignOftype( DeclarationNode *decl_node ) { … … 230 224 231 225 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) { 232 return new LogicalExpr( notZeroExpr( maybeBuild< Expression>(expr_node1) ), notZeroExpr( maybeBuild<Expression>(expr_node2) ), kind );226 return new LogicalExpr( notZeroExpr( maybeBuild< Expression >(expr_node1) ), notZeroExpr( maybeBuild< Expression >(expr_node2) ), kind ); 233 227 } 234 228 235 229 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) { 236 std::list< Expression *> args;237 args.push_back( maybeBuild< Expression>(expr_node) );230 std::list< Expression * > args; 231 args.push_back( maybeBuild< Expression >(expr_node) ); 238 232 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 239 233 } 240 234 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) { 241 std::list< Expression *> args;242 args.push_back( new AddressExpr( maybeBuild< Expression>(expr_node) ) );235 std::list< Expression * > args; 236 args.push_back( new AddressExpr( maybeBuild< Expression >(expr_node) ) ); 243 237 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 244 238 } 245 239 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 246 std::list< Expression *> args;247 args.push_back( maybeBuild< Expression>(expr_node1) );248 args.push_back( maybeBuild< Expression>(expr_node2) );240 std::list< Expression * > args; 241 args.push_back( maybeBuild< Expression >(expr_node1) ); 242 args.push_back( maybeBuild< Expression >(expr_node2) ); 249 243 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 250 244 } 251 245 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 252 std::list< Expression *> args;253 args.push_back( new AddressExpr( maybeBuild< Expression>(expr_node1) ) );254 args.push_back( maybeBuild< Expression>(expr_node2) );246 std::list< Expression * > args; 247 args.push_back( new AddressExpr( maybeBuild< Expression >(expr_node1) ) ); 248 args.push_back( maybeBuild< Expression >(expr_node2) ); 255 249 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 256 250 } 257 251 258 252 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) { 259 return new ConditionalExpr( notZeroExpr( maybeBuild< Expression>(expr_node1) ), maybeBuild<Expression>(expr_node2), maybeBuild<Expression>(expr_node3) );253 return new ConditionalExpr( notZeroExpr( maybeBuild< Expression >(expr_node1) ), maybeBuild< Expression >(expr_node2), maybeBuild< Expression >(expr_node3) ); 260 254 } 261 255 262 256 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 263 return new CommaExpr( maybeBuild< Expression>(expr_node1), maybeBuild<Expression>(expr_node2) );257 return new CommaExpr( maybeBuild< Expression >(expr_node1), maybeBuild< Expression >(expr_node2) ); 264 258 } 265 259 266 260 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) { 267 return new AttrExpr( var, maybeBuild< Expression>(expr_node) );261 return new AttrExpr( var, maybeBuild< Expression >(expr_node) ); 268 262 } 269 263 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) { … … 278 272 279 273 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ) { 280 std::list< Expression *> args;274 std::list< Expression * > args; 281 275 282 276 buildList( expr_node, args ); 283 return new UntypedExpr( maybeBuild< Expression>(function), args, nullptr );277 return new UntypedExpr( maybeBuild< Expression >(function), args, nullptr ); 284 278 } 285 279 286 280 Expression *build_range( ExpressionNode * low, ExpressionNode *high ) { 287 Expression *low_cexpr = maybeBuild< Expression>( low );288 Expression *high_cexpr = maybeBuild< Expression>( high );281 Expression *low_cexpr = maybeBuild< Expression >( low ); 282 Expression *high_cexpr = maybeBuild< Expression >( high ); 289 283 return new RangeExpr( low_cexpr, high_cexpr ); 290 284 } 291 285 292 //##############################################################################293 294 286 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) { 295 return new AsmExpr( maybeBuild< Expression >( inout ), constraint, maybeBuild<Expression>(operand) ); 296 } 297 298 //############################################################################## 299 300 //void LabelNode::print( std::ostream &os, int indent ) const {} 301 302 //void LabelNode::printOneLine( std::ostream &os, int indent ) const {} 303 304 //############################################################################## 287 return new AsmExpr( maybeBuild< Expression >( inout ), constraint, maybeBuild< Expression >(operand) ); 288 } 305 289 306 290 Expression *build_valexpr( StatementNode *s ) { 307 return new UntypedValofExpr( maybeBuild<Statement>(s), nullptr ); 308 } 309 310 //############################################################################## 311 291 return new UntypedValofExpr( maybeBuild< Statement >(s), nullptr ); 292 } 312 293 Expression *build_typevalue( DeclarationNode *decl ) { 313 294 return new TypeExpr( decl->buildType() ); 314 295 } 315 296 316 //##############################################################################317 318 297 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) { 319 Declaration * newDecl = maybeBuild< Declaration>(decl_node); // compound literal type298 Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type 320 299 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type 321 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild< Initializer>(kids) );300 return new CompoundLiteralExpr( newDeclWithType->get_type(), maybeBuild< Initializer >(kids) ); 322 301 // these types do not have associated type information 323 302 } else if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( newDecl ) ) { 324 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild< Initializer>(kids) );303 return new CompoundLiteralExpr( new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() ), maybeBuild< Initializer >(kids) ); 325 304 } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( newDecl ) ) { 326 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild< Initializer>(kids) );305 return new CompoundLiteralExpr( new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() ), maybeBuild< Initializer >(kids) ); 327 306 } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( newDecl ) ) { 328 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild< Initializer>(kids) );307 return new CompoundLiteralExpr( new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ), maybeBuild< Initializer >(kids) ); 329 308 } else { 330 309 assert( false ); -
src/Parser/InitializerNode.cc
rb1848a0 r7880579 10 10 // Created On : Sat May 16 13:20:24 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Aug 13 18:55:11201613 // Update Count : 1812 // Last Modified On : Mon Aug 15 18:27:02 2016 13 // Update Count : 20 14 14 // 15 15 … … 25 25 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) { 26 26 if ( aggrp ) 27 kids = dynamic_cast< InitializerNode * >( get_next() );27 kids = dynamic_cast< InitializerNode * >( get_next() ); 28 28 29 29 if ( kids != 0 ) … … 37 37 38 38 if ( aggrp ) 39 kids = dynamic_cast< InitializerNode * >( get_next() );39 kids = dynamic_cast< InitializerNode * >( get_next() ); 40 40 41 41 if ( kids != 0 ) … … 82 82 //assert( next_init() != 0 ); 83 83 84 std::list< Initializer * > initlist;85 buildList< Initializer, InitializerNode>( next_init(), initlist );84 std::list< Initializer * > initlist; 85 buildList< Initializer, InitializerNode >( next_init(), initlist ); 86 86 87 std::list< Expression * > designlist;87 std::list< Expression * > designlist; 88 88 89 89 if ( designator != 0 ) { 90 buildList< Expression, ExpressionNode>( designator, designlist );90 buildList< Expression, ExpressionNode >( designator, designlist ); 91 91 } // if 92 92 93 93 return new ListInit( initlist, designlist, maybeConstructed ); 94 94 } else { 95 std::list< Expression * > designators;95 std::list< Expression * > designators; 96 96 97 97 if ( designator != 0 ) 98 buildList< Expression, ExpressionNode>( designator, designators );98 buildList< Expression, ExpressionNode >( designator, designators ); 99 99 100 100 if ( get_expression() != 0) 101 return new SingleInit( maybeBuild< Expression>( get_expression() ), designators, maybeConstructed );101 return new SingleInit( maybeBuild< Expression >( get_expression() ), designators, maybeConstructed ); 102 102 } // if 103 103 -
src/Parser/ParseNode.cc
rb1848a0 r7880579 10 10 // Created On : Sat May 16 13:26:29 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 15 14:49:06201613 // Update Count : 9912 // Last Modified On : Tue Aug 16 08:42:29 2016 13 // Update Count : 107 14 14 // 15 15 … … 17 17 using namespace std; 18 18 19 // Builder20 19 int ParseNode::indent_by = 4; 21 20 22 ParseNode::ParseNode() : next( 0) {};23 ParseNode::ParseNode( const string *name ) : name( *name ), next( 0) { delete name; }24 ParseNode::ParseNode( const string &name ) : name( name ), next( 0) { }21 ParseNode::ParseNode() : next( nullptr ) {}; 22 ParseNode::ParseNode( const string *name ) : name( *name ), next( nullptr ) { delete name; } 23 ParseNode::ParseNode( const string &name ) : name( name ), next( nullptr ) { } 25 24 26 25 ParseNode::~ParseNode() { … … 41 40 } 42 41 43 void ParseNode::print( std::ostream &os, int indent ) const {}44 45 46 42 void ParseNode::printList( std::ostream &os, int indent ) const { 47 43 print( os, indent ); -
src/Parser/ParseNode.h
rb1848a0 r7880579 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 15 14:52:12201613 // Update Count : 5 1212 // Last Modified On : Tue Aug 16 08:37:47 2016 13 // Update Count : 527 14 14 // 15 15 … … 22 22 #include <memory> 23 23 24 #include "Common/utility.h"25 24 #include "Parser/LinkageSpec.h" 26 25 #include "SynTree/Type.h" 27 26 #include "SynTree/Expression.h" 28 27 #include "SynTree/Statement.h" 29 //#include "SynTree/Declaration.h" 28 #include "SynTree/Label.h" 29 #include "Common/utility.h" 30 30 #include "Common/UniqueName.h" 31 #include "SynTree/Label.h"32 31 33 32 class StatementNode; … … 37 36 class InitializerNode; 38 37 39 // Builder 38 //############################################################################## 39 40 40 class ParseNode { 41 41 public: … … 44 44 ParseNode( const std::string & ); // for copy constructing subclasses 45 45 virtual ~ParseNode(); 46 virtual ParseNode *clone() const { assert( false ); return nullptr; }; 46 47 47 48 ParseNode *get_next() const { return next; } … … 50 51 ParseNode *set_last( ParseNode * ); 51 52 52 virtual ParseNode *clone() const { return 0; };53 54 53 const std::string &get_name() const { return name; } 55 54 void set_name( const std::string &newValue ) { name = newValue; } 56 55 57 virtual void print( std::ostream &os, int indent = 0 ) const ;56 virtual void print( std::ostream &os, int indent = 0 ) const {} 58 57 virtual void printList( std::ostream &os, int indent = 0 ) const; 59 60 ParseNode &operator,( ParseNode & ); 61 protected: 58 private: 59 static int indent_by; 60 61 ParseNode *next; 62 62 std::string name; 63 static int indent_by; 64 ParseNode *next; 65 }; 63 }; // ParseNode 66 64 67 65 //############################################################################## … … 104 102 virtual ~ExpressionNode() {} 105 103 106 virtual ExpressionNode *clone() const { return 0; }104 virtual ExpressionNode *clone() const { assert( false ); return nullptr; } 107 105 108 106 bool get_extension() const { return extension; } … … 119 117 120 118 template< typename T > 121 struct maybeBuild_t< Expression, T> {119 struct maybeBuild_t< Expression, T > { 122 120 static inline Expression * doit( const T *orig ) { 123 121 if ( orig ) { … … 126 124 return p; 127 125 } else { 128 return 0;126 return nullptr; 129 127 } // if 130 128 } … … 228 226 static DeclarationNode *newBuiltinType( BuiltinType ); 229 227 228 DeclarationNode(); 229 ~DeclarationNode(); 230 DeclarationNode *clone() const; 231 230 232 DeclarationNode *addQualifiers( DeclarationNode *); 231 233 DeclarationNode *copyStorageClasses( DeclarationNode *); … … 254 256 DeclarationNode *appendList( DeclarationNode * ); 255 257 256 DeclarationNode *clone() const;257 258 void print( std::ostream &os, int indent = 0 ) const; 258 259 void printList( std::ostream &os, int indent = 0 ) const; … … 269 270 bool get_extension() const { return extension; } 270 271 DeclarationNode *set_extension( bool exten ) { extension = exten; return this; } 271 272 DeclarationNode();273 ~DeclarationNode();274 272 private: 275 273 StorageClass buildStorageClass() const; … … 351 349 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) { 352 350 SemanticError errors; 353 std::back_insert_iterator< std::list< SynTreeType * > > out( outputList );351 std::back_insert_iterator< std::list< SynTreeType * > > out( outputList ); 354 352 const NodeType *cur = firstNode; 355 353 356 354 while ( cur ) { 357 355 try { 358 // SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild<typename std::result_of<decltype(&NodeType::build)(NodeType)>::type>( cur ) );359 SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild<typename std::pointer_traits<decltype(cur->build())>::element_type>( cur ) );356 // SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) ); 357 SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) ); 360 358 if ( result ) { 361 359 *out++ = result; … … 365 363 errors.append( e ); 366 364 } // try 367 cur = dynamic_cast< NodeType * >( cur->get_next() );365 cur = dynamic_cast< NodeType * >( cur->get_next() ); 368 366 } // while 369 367 if ( ! errors.isEmpty() ) { … … 374 372 // in DeclarationNode.cc 375 373 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ); 376 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList );374 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ); 377 375 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ); 378 376 -
src/Parser/Parser.cc
rb1848a0 r7880579 10 10 // Created On : Sat May 16 14:54:28 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Mar 21 18:04:47201613 // Update Count : 512 // Last Modified On : Mon Aug 15 17:44:22 2016 13 // Update Count : 7 14 14 // 15 15 -
src/Parser/Parser.h
rb1848a0 r7880579 10 10 // Created On : Sat May 16 14:56:50 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 16 14:58:56 201513 // Update Count : 212 // Last Modified On : Mon Aug 15 16:33:22 2016 13 // Update Count : 3 14 14 // 15 15 -
src/Parser/StatementNode.cc
rb1848a0 r7880579 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 15 14:40:05201613 // Update Count : 3 1712 // Last Modified On : Mon Aug 15 20:47:11 2016 13 // Update Count : 322 14 14 // 15 15 … … 32 32 if ( agg ) { 33 33 StatementNode *nextStmt = new StatementNode( new DeclStmt( noLabels, maybeBuild< Declaration >( decl ) ) ); 34 next = nextStmt;34 set_next( nextStmt ); 35 35 if ( decl->get_next() ) { 36 next->set_next( new StatementNode( dynamic_cast<DeclarationNode *>(decl->get_next()) ) );36 get_next()->set_next( new StatementNode( dynamic_cast< DeclarationNode * >(decl->get_next()) ) ); 37 37 decl->set_next( 0 ); 38 38 } // if 39 39 } else { 40 40 if ( decl->get_next() ) { 41 next = new StatementNode( dynamic_cast<DeclarationNode *>( decl->get_next() ) );41 set_next(new StatementNode( dynamic_cast< DeclarationNode * >( decl->get_next() ) ) ); 42 42 decl->set_next( 0 ); 43 43 } // if 44 44 agg = decl; 45 45 } // if 46 stmt = new DeclStmt( noLabels, maybeBuild< Declaration>(agg) );46 stmt = new DeclStmt( noLabels, maybeBuild< Declaration >(agg) ); 47 47 } else { 48 48 assert( false ); … … 54 54 // find end of list and maintain previous pointer 55 55 for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) { 56 StatementNode *node = dynamic_cast< StatementNode *>(curr);56 StatementNode *node = dynamic_cast< StatementNode * >(curr); 57 57 assert( node ); 58 assert( dynamic_cast< CaseStmt *>(node->stmt) );58 assert( dynamic_cast< CaseStmt * >(node->stmt) ); 59 59 prev = curr; 60 60 } // for 61 61 // convert from StatementNode list to Statement list 62 StatementNode *node = dynamic_cast< StatementNode *>(prev);63 std::list< Statement *> stmts;62 StatementNode *node = dynamic_cast< StatementNode * >(prev); 63 std::list< Statement * > stmts; 64 64 buildList( stmt, stmts ); 65 65 // splice any new Statements to end of current Statements 66 CaseStmt * caseStmt = dynamic_cast< CaseStmt *>(node->stmt);66 CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt); 67 67 caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts ); 68 68 return this; … … 80 80 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ) { 81 81 Statement *thenb, *elseb = 0; 82 std::list< Statement *> branches;83 buildList< Statement, StatementNode>( then_stmt, branches );82 std::list< Statement * > branches; 83 buildList< Statement, StatementNode >( then_stmt, branches ); 84 84 assert( branches.size() == 1 ); 85 85 thenb = branches.front(); 86 86 87 87 if ( else_stmt ) { 88 std::list< Statement *> branches;89 buildList< Statement, StatementNode>( else_stmt, branches );88 std::list< Statement * > branches; 89 buildList< Statement, StatementNode >( else_stmt, branches ); 90 90 assert( branches.size() == 1 ); 91 91 elseb = branches.front(); 92 92 } // if 93 return new IfStmt( noLabels, notZeroExpr( maybeBuild< Expression>(ctl) ), thenb, elseb );93 return new IfStmt( noLabels, notZeroExpr( maybeBuild< Expression >(ctl) ), thenb, elseb ); 94 94 } 95 95 96 96 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ) { 97 std::list< Statement *> branches;98 buildList< Statement, StatementNode>( stmt, branches );97 std::list< Statement * > branches; 98 buildList< Statement, StatementNode >( stmt, branches ); 99 99 assert( branches.size() >= 0 ); // size == 0 for switch (...) {}, i.e., no declaration or statements 100 return new SwitchStmt( noLabels, maybeBuild< Expression>(ctl), branches );100 return new SwitchStmt( noLabels, maybeBuild< Expression >(ctl), branches ); 101 101 } 102 102 Statement *build_case( ExpressionNode *ctl ) { 103 std::list< Statement *> branches;104 return new CaseStmt( noLabels, maybeBuild< Expression>(ctl), branches );103 std::list< Statement * > branches; 104 return new CaseStmt( noLabels, maybeBuild< Expression >(ctl), branches ); 105 105 } 106 106 Statement *build_default() { 107 std::list< Statement *> branches;107 std::list< Statement * > branches; 108 108 return new CaseStmt( noLabels, nullptr, branches, true ); 109 109 } 110 110 111 111 Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind ) { 112 std::list< Statement *> branches;113 buildList< Statement, StatementNode>( stmt, branches );112 std::list< Statement * > branches; 113 buildList< Statement, StatementNode >( stmt, branches ); 114 114 assert( branches.size() == 1 ); 115 return new WhileStmt( noLabels, notZeroExpr( maybeBuild< Expression>(ctl) ), branches.front(), kind );115 return new WhileStmt( noLabels, notZeroExpr( maybeBuild< Expression >(ctl) ), branches.front(), kind ); 116 116 } 117 117 118 118 Statement *build_for( ForCtl *forctl, StatementNode *stmt ) { 119 std::list< Statement *> branches;120 buildList< Statement, StatementNode>( stmt, branches );119 std::list< Statement * > branches; 120 buildList< Statement, StatementNode >( stmt, branches ); 121 121 assert( branches.size() == 1 ); 122 122 123 std::list< Statement *> init;123 std::list< Statement * > init; 124 124 if ( forctl->init != 0 ) { 125 125 buildList( forctl->init, init ); … … 128 128 Expression *cond = 0; 129 129 if ( forctl->condition != 0 ) 130 cond = notZeroExpr( maybeBuild< Expression>(forctl->condition) );130 cond = notZeroExpr( maybeBuild< Expression >(forctl->condition) ); 131 131 132 132 Expression *incr = 0; 133 133 if ( forctl->change != 0 ) 134 incr = maybeBuild< Expression>(forctl->change);134 incr = maybeBuild< Expression >(forctl->change); 135 135 136 136 delete forctl; … … 142 142 } 143 143 Statement *build_computedgoto( ExpressionNode *ctl ) { 144 return new BranchStmt( noLabels, maybeBuild< Expression>(ctl), BranchStmt::Goto );144 return new BranchStmt( noLabels, maybeBuild< Expression >(ctl), BranchStmt::Goto ); 145 145 } 146 146 147 147 Statement *build_return( ExpressionNode *ctl ) { 148 std::list< Expression *> exps;148 std::list< Expression * > exps; 149 149 buildList( ctl, exps ); 150 150 return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr ); 151 151 } 152 152 Statement *build_throw( ExpressionNode *ctl ) { 153 std::list< Expression *> exps;153 std::list< Expression * > exps; 154 154 buildList( ctl, exps ); 155 155 return new ReturnStmt( noLabels, exps.size() > 0 ? exps.back() : nullptr, true ); … … 157 157 158 158 Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ) { 159 std::list< Statement *> branches;160 buildList< Statement, StatementNode>( catch_stmt, branches );161 CompoundStmt *tryBlock = dynamic_cast< CompoundStmt *>(maybeBuild<Statement>(try_stmt));159 std::list< Statement * > branches; 160 buildList< Statement, StatementNode >( catch_stmt, branches ); 161 CompoundStmt *tryBlock = dynamic_cast< CompoundStmt * >(maybeBuild< Statement >(try_stmt)); 162 162 assert( tryBlock ); 163 FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt *>(maybeBuild<Statement>(finally_stmt) );163 FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeBuild< Statement >(finally_stmt) ); 164 164 return new TryStmt( noLabels, tryBlock, branches, finallyBlock ); 165 165 } 166 166 Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny ) { 167 std::list< Statement *> branches;168 buildList< Statement, StatementNode>( stmt, branches );167 std::list< Statement * > branches; 168 buildList< Statement, StatementNode >( stmt, branches ); 169 169 assert( branches.size() == 1 ); 170 return new CatchStmt( noLabels, maybeBuild< Declaration>(decl), branches.front(), catchAny );170 return new CatchStmt( noLabels, maybeBuild< Declaration >(decl), branches.front(), catchAny ); 171 171 } 172 172 Statement *build_finally( StatementNode *stmt ) { 173 std::list< Statement *> branches;174 buildList< Statement, StatementNode>( stmt, branches );173 std::list< Statement * > branches; 174 buildList< Statement, StatementNode >( stmt, branches ); 175 175 assert( branches.size() == 1 ); 176 return new FinallyStmt( noLabels, dynamic_cast< CompoundStmt *>( branches.front() ) );176 return new FinallyStmt( noLabels, dynamic_cast< CompoundStmt * >( branches.front() ) ); 177 177 } 178 178 -
src/Parser/TypeData.cc
rb1848a0 r7880579 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Aug 13 18:38:41201613 // Update Count : 5912 // Last Modified On : Mon Aug 15 20:48:52 2016 13 // Update Count : 62 14 14 // 15 15 … … 182 182 break; 183 183 case Array: 184 //PAB newtype->array->dimension = maybeClone( array->dimension );185 184 newtype->array->dimension = array->dimension; 186 185 newtype->array->isVarLen = array->isVarLen; … … 489 488 decl = new FunctionDecl( name, sc, linkage, buildFunction(), body, isInline, isNoreturn ); 490 489 } else { 491 // std::list< Label> ls;492 decl = new FunctionDecl( name, sc, linkage, buildFunction(), new CompoundStmt( std::list< Label>() ), isInline, isNoreturn );490 // std::list< Label > ls; 491 decl = new FunctionDecl( name, sc, linkage, buildFunction(), new CompoundStmt( std::list< Label >() ), isInline, isNoreturn ); 493 492 } // if 494 493 } else { … … 909 908 buildList( enumeration->constants, ret->get_members() ); 910 909 std::list< Declaration * >::iterator members = ret->get_members().begin(); 911 for ( const DeclarationNode *cur = enumeration->constants; cur != NULL; cur = dynamic_cast< DeclarationNode *>( cur->get_next() ), ++members ) {910 for ( const DeclarationNode *cur = enumeration->constants; cur != NULL; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 912 911 if ( cur->get_enumeratorValue() != NULL ) { 913 ObjectDecl *member = dynamic_cast< ObjectDecl *>(*members);912 ObjectDecl *member = dynamic_cast< ObjectDecl * >(*members); 914 913 member->set_init( new SingleInit( maybeBuild< Expression >( cur->get_enumeratorValue() ), std::list< Expression * >() ) ); 915 914 } // if -
src/Parser/TypedefTable.cc
rb1848a0 r7880579 10 10 // Created On : Sat May 16 15:20:13 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 13 16:57:30201613 // Update Count : 2 412 // Last Modified On : Mon Aug 15 18:24:42 2016 13 // Update Count : 25 14 14 // 15 15 … … 64 64 tableType::iterator curPos = table.find( identifier ); 65 65 if ( curPos == table.end()) { 66 list< Entry> newList;66 list< Entry > newList; 67 67 newList.push_front( newEntry ); 68 68 table[identifier] = newList; 69 69 } else { 70 list< Entry>::iterator listPos = (*curPos ).second.begin();70 list< Entry >::iterator listPos = (*curPos ).second.begin(); 71 71 while ( listPos != (*curPos ).second.end() && listPos->scope > scope ) { 72 72 listPos++; … … 127 127 debugPrint( "Leaving scope " << currentScope << endl ); 128 128 for ( tableType::iterator i = table.begin(); i != table.end(); ) { 129 list< Entry> &declList = (*i).second;129 list< Entry > &declList = (*i).second; 130 130 while ( ! declList.empty() && declList.front().scope == currentScope ) { 131 131 declList.pop_front(); … … 157 157 for ( tableType::const_iterator i = table.begin(); i != table.end(); i++) { 158 158 debugPrint( (*i ).first << ": " ); 159 list< Entry> declList = (*i).second;160 for ( list< Entry>::const_iterator j = declList.begin(); j != declList.end(); j++ ) {159 list< Entry > declList = (*i).second; 160 for ( list< Entry >::const_iterator j = declList.begin(); j != declList.end(); j++ ) { 161 161 debugPrint( "(" << (*j).scope << " " << (*j).kind << ") " ); 162 162 } -
src/Parser/TypedefTable.h
rb1848a0 r7880579 10 10 // Created On : Sat May 16 15:24:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 13 16:59:56201613 // Update Count : 2 712 // Last Modified On : Mon Aug 15 18:25:04 2016 13 // Update Count : 28 14 14 // 15 15 … … 39 39 }; 40 40 41 typedef std::map< std::string, std::list<Entry> > tableType;41 typedef std::map< std::string, std::list< Entry > > tableType; 42 42 tableType table; 43 43 -
src/main.cc
rb1848a0 r7880579 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Aug 6 16:17:41201613 // Update Count : 2 1012 // Last Modified On : Mon Aug 15 17:58:57 2016 13 // Update Count : 220 14 14 // 15 15 16 16 #include <iostream> 17 17 #include <fstream> 18 #include <cstdlib>19 #include <cstdio>20 18 #include <getopt.h> 21 19 #include "Parser/Parser.h" 22 #include "Parser/ParseNode.h"23 #include "Parser/LinkageSpec.h"24 20 #include "SynTree/Declaration.h" 25 21 #include "SynTree/Visitor.h" … … 43 39 #include "InitTweak/GenInit.h" 44 40 #include "InitTweak/FixInit.h" 45 //#include "Explain/GenProlog.h"46 //#include "Try/Visit.h"47 41 48 42 #include "Common/SemanticError.h" … … 384 378 std::list< Declaration * > decls; 385 379 if ( noprotop ) { 386 filter( translationUnit.begin(), translationUnit.end(), 387 std::back_inserter( decls ), notPrelude ); 380 filter( translationUnit.begin(), translationUnit.end(), std::back_inserter( decls ), notPrelude ); 388 381 } else { 389 382 decls = translationUnit;
Note: See TracChangeset
for help on using the changeset viewer.