Changes in src/Parser/ParseNode.h [ac71a86:e82aa9df]
- File:
-
- 1 edited
-
src/Parser/ParseNode.h (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
rac71a86 re82aa9df 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 18 23:48:37201613 // Update Count : 5 4212 // Last Modified On : Mon Aug 15 14:52:12 2016 13 // Update Count : 512 14 14 // 15 15 … … 22 22 #include <memory> 23 23 24 #include "Common/utility.h" 24 25 #include "Parser/LinkageSpec.h" 25 26 #include "SynTree/Type.h" 26 27 #include "SynTree/Expression.h" 27 28 #include "SynTree/Statement.h" 29 //#include "SynTree/Declaration.h" 30 #include "Common/UniqueName.h" 28 31 #include "SynTree/Label.h" 29 #include "Common/utility.h"30 #include "Common/UniqueName.h"31 32 32 33 class StatementNode; … … 36 37 class InitializerNode; 37 38 38 //############################################################################## 39 39 // Builder 40 40 class ParseNode { 41 41 public: 42 ParseNode() {}; 43 ParseNode( const std::string *name ) : name( *name ) { assert( false ); delete name; } 44 ParseNode( const std::string &name ) : name( name ) { assert( false ); } 45 virtual ~ParseNode() { delete next; }; 46 virtual ParseNode *clone() const = 0; 42 ParseNode(); 43 ParseNode( const std::string * ); 44 ParseNode( const std::string & ); // for copy constructing subclasses 45 virtual ~ParseNode(); 47 46 48 47 ParseNode *get_next() const { return next; } 49 48 ParseNode *set_next( ParseNode *newlink ) { next = newlink; return this; } 50 ParseNode *get_last() { 51 ParseNode *current; 52 for ( current = this; current->get_next() != 0; current = current->get_next() ); 53 return current; 54 } 55 ParseNode *set_last( ParseNode *newlast ) { 56 if ( newlast != 0 ) get_last()->set_next( newlast ); 57 return this; 58 } 49 ParseNode *get_last(); 50 ParseNode *set_last( ParseNode * ); 51 52 virtual ParseNode *clone() const { return 0; }; 59 53 60 54 const std::string &get_name() const { return name; } 61 55 void set_name( const std::string &newValue ) { name = newValue; } 62 56 63 virtual void print( std::ostream &os, int indent = 0 ) const {} 64 virtual void printList( std::ostream &os, int indent = 0 ) const {} 65 private: 57 virtual void print( std::ostream &os, int indent = 0 ) const; 58 virtual void printList( std::ostream &os, int indent = 0 ) const; 59 60 ParseNode &operator,( ParseNode & ); 61 protected: 62 std::string name; 66 63 static int indent_by; 67 68 ParseNode *next = nullptr; 69 std::string name; 70 }; // ParseNode 64 ParseNode *next; 65 }; 71 66 72 67 //############################################################################## … … 77 72 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); 78 73 ~InitializerNode(); 79 virtual InitializerNode *clone() const { assert( false ); return nullptr; }80 74 81 75 ExpressionNode *get_expression() const { return expr; } … … 103 97 //############################################################################## 104 98 105 class ExpressionNode final: public ParseNode {99 class ExpressionNode : public ParseNode { 106 100 public: 107 101 ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {} … … 109 103 ExpressionNode( const ExpressionNode &other ); 110 104 virtual ~ExpressionNode() {} 111 virtual ExpressionNode *clone() const { assert( false ); return nullptr; } 105 106 virtual ExpressionNode *clone() const { return 0; } 112 107 113 108 bool get_extension() const { return extension; } 114 109 ExpressionNode *set_extension( bool exten ) { extension = exten; return this; } 115 110 116 void print( std::ostream &os, int indent = 0 ) const {} 117 void printOneLine( std::ostream &os, int indent = 0 ) const {} 118 119 template<typename T> 120 bool isExpressionType() const { 121 return nullptr != dynamic_cast<T>(expr.get()); 122 } 123 124 Expression *build() const { return const_cast<ExpressionNode*>(this)->expr.release(); } 111 virtual void print( std::ostream &os, int indent = 0 ) const {} 112 virtual void printOneLine( std::ostream &os, int indent = 0 ) const {} 113 114 virtual Expression *build() const { return expr; } 125 115 private: 126 116 bool extension = false; 127 std::unique_ptr<Expression>expr;117 Expression *expr; 128 118 }; 129 119 130 120 template< typename T > 131 struct maybeBuild_t< Expression, T> {121 struct maybeBuild_t<Expression, T> { 132 122 static inline Expression * doit( const T *orig ) { 133 123 if ( orig ) { … … 136 126 return p; 137 127 } else { 138 return nullptr;128 return 0; 139 129 } // if 140 130 } … … 156 146 }; 157 147 158 Expression *build_constantInteger( conststd::string &str );159 Expression *build_constantFloat( conststd::string &str );160 Expression *build_constantChar( conststd::string &str );161 ConstantExpr *build_constantStr( conststd::string &str );148 Expression *build_constantInteger( std::string &str ); 149 Expression *build_constantFloat( std::string &str ); 150 Expression *build_constantChar( std::string &str ); 151 ConstantExpr *build_constantStr( std::string &str ); 162 152 163 153 NameExpr *build_varref( const std::string *name, bool labelp = false ); … … 238 228 static DeclarationNode *newBuiltinType( BuiltinType ); 239 229 240 DeclarationNode();241 ~DeclarationNode();242 DeclarationNode *clone() const;243 244 230 DeclarationNode *addQualifiers( DeclarationNode *); 245 231 DeclarationNode *copyStorageClasses( DeclarationNode *); … … 266 252 DeclarationNode *cloneBaseType( DeclarationNode *newdecl ); 267 253 268 DeclarationNode *appendList( DeclarationNode *node ) { 269 return (DeclarationNode *)set_last( node ); 270 } 271 254 DeclarationNode *appendList( DeclarationNode * ); 255 256 DeclarationNode *clone() const; 272 257 void print( std::ostream &os, int indent = 0 ) const; 273 258 void printList( std::ostream &os, int indent = 0 ) const; … … 278 263 bool get_hasEllipsis() const; 279 264 const std::string &get_name() const { return name; } 280 LinkageSpec:: Specget_linkage() const { return linkage; }265 LinkageSpec::Type get_linkage() const { return linkage; } 281 266 DeclarationNode *extractAggregate() const; 282 267 ExpressionNode *get_enumeratorValue() const { return enumeratorValue; } … … 284 269 bool get_extension() const { return extension; } 285 270 DeclarationNode *set_extension( bool exten ) { extension = exten; return this; } 271 272 DeclarationNode(); 273 ~DeclarationNode(); 286 274 private: 287 //StorageClass buildStorageClass() const;288 //bool buildFuncSpecifier( StorageClass key ) const;275 StorageClass buildStorageClass() const; 276 bool buildFuncSpecifier( StorageClass key ) const; 289 277 290 278 TypeData *type; 291 279 std::string name; 292 // std::list< StorageClass > storageClasses; 293 StorageClass storageClass; 294 bool isInline, isNoreturn; 280 std::list< StorageClass > storageClasses; 295 281 std::list< std::string > attributes; 296 282 ExpressionNode *bitfieldWidth; … … 298 284 InitializerNode *initializer; 299 285 bool hasEllipsis; 300 LinkageSpec:: Speclinkage;286 LinkageSpec::Type linkage; 301 287 bool extension = false; 302 std::string error;303 288 304 289 static UniqueName anonymous; … … 309 294 //############################################################################## 310 295 311 class StatementNode final: public ParseNode {296 class StatementNode : public ParseNode { 312 297 public: 313 298 StatementNode() { stmt = nullptr; } … … 316 301 virtual ~StatementNode() {} 317 302 318 virtual StatementNode *clone() const final{ assert( false ); return nullptr; }319 Statement *build() const { return const_cast<StatementNode*>(this)->stmt.release(); }303 virtual StatementNode *clone() const { assert( false ); return nullptr; } 304 virtual Statement *build() const { return stmt; } 320 305 321 306 virtual StatementNode *add_label( const std::string * name ) { 322 307 stmt->get_labels().emplace_back( *name ); 323 delete name;324 308 return this; 325 309 } … … 330 314 virtual void printList( std::ostream &os, int indent = 0 ) {} 331 315 private: 332 std::unique_ptr<Statement>stmt;316 Statement *stmt; 333 317 }; // StatementNode 334 318 … … 367 351 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) { 368 352 SemanticError errors; 369 std::back_insert_iterator< std::list< SynTreeType * > > out( outputList );353 std::back_insert_iterator< std::list< SynTreeType *> > out( outputList ); 370 354 const NodeType *cur = firstNode; 371 355 372 356 while ( cur ) { 373 357 try { 374 // SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type>( cur ) );375 SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type>( cur ) );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 ) ); 376 360 if ( result ) { 377 361 *out++ = result; … … 381 365 errors.append( e ); 382 366 } // try 383 cur = dynamic_cast< NodeType * >( cur->get_next() );367 cur = dynamic_cast< NodeType *>( cur->get_next() ); 384 368 } // while 385 369 if ( ! errors.isEmpty() ) { … … 390 374 // in DeclarationNode.cc 391 375 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ); 392 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList );376 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList ); 393 377 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ); 394 395 template< typename SynTreeType, typename NodeType >396 void buildMoveList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {397 buildList(firstNode, outputList);398 delete firstNode;399 }400 401 378 402 379 #endif // PARSENODE_H
Note:
See TracChangeset
for help on using the changeset viewer.