Changes in src/Parser/ParseNode.h [f271bdd:5fcba14]
- File:
-
- 1 edited
-
src/Parser/ParseNode.h (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
rf271bdd r5fcba14 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Aug 4 09:39:40 201813 // Update Count : 8 5312 // Last Modified On : Mon Nov 27 17:33:35 2017 13 // Update Count : 824 14 14 // 15 15 … … 68 68 } 69 69 70 virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {}71 virtual void printList( std::ostream & os, int indent = 0 ) const {70 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 71 virtual void printList( std::ostream &os, int indent = 0 ) const { 72 72 print( os, indent ); 73 73 if ( next ) next->print( os, indent ); … … 77 77 78 78 ParseNode * next = nullptr; 79 conststd::string * name = nullptr;79 std::string * name = nullptr; 80 80 CodeLocation location = yylloc; 81 81 }; // ParseNode … … 87 87 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = nullptr ); 88 88 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = nullptr ); 89 InitializerNode( bool isDelete );90 89 ~InitializerNode(); 91 90 virtual InitializerNode * clone() const { assert( false ); return nullptr; } … … 99 98 bool get_maybeConstructed() const { return maybeConstructed; } 100 99 101 bool get_isDelete() const { return isDelete; }102 103 100 InitializerNode * next_init() const { return kids; } 104 101 105 void print( std::ostream & os, int indent = 0 ) const;102 void print( std::ostream &os, int indent = 0 ) const; 106 103 void printOneLine( std::ostream & ) const; 107 104 … … 113 110 InitializerNode * kids; 114 111 bool maybeConstructed; 115 bool isDelete;116 112 }; // InitializerNode 117 113 … … 127 123 ExpressionNode * set_extension( bool exten ) { extension = exten; return this; } 128 124 129 virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override { 130 os << expr.get(); 131 } 132 void printOneLine( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {} 133 134 Expression *get_expr() const { return expr.get(); } 125 virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override { 126 os << expr.get() << std::endl; 127 } 128 void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 129 135 130 template<typename T> 136 131 bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr.get()); } … … 172 167 }; 173 168 174 Expression * build_constantInteger( std::string & str ); // these 4 routines modify the string175 Expression * build_constantFloat( std::string & str );176 Expression * build_constantChar( std::string & str );177 Expression * build_constantStr( std::string & str );169 Expression * build_constantInteger( std::string &str ); 170 Expression * build_constantFloat( std::string &str ); 171 Expression * build_constantChar( std::string &str ); 172 Expression * build_constantStr( std::string &str ); 178 173 Expression * build_field_name_FLOATING_FRACTIONconstant( const std::string & str ); 179 174 Expression * build_field_name_FLOATING_DECIMALconstant( const std::string & str ); … … 184 179 185 180 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); 186 Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node );187 181 Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); 188 182 Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ); … … 215 209 enum Length { Short, Long, LongLong, NoLength }; 216 210 static const char * lengthNames[]; 217 enum Aggregate { Struct, Union, Exception,Trait, Coroutine, Monitor, Thread, NoAggregate };211 enum Aggregate { Struct, Union, Trait, Coroutine, Monitor, Thread, NoAggregate }; 218 212 static const char * aggregateNames[]; 219 213 enum TypeClass { Otype, Dtype, Ftype, Ttype, NoTypeClass }; … … 231 225 static DeclarationNode * newBuiltinType( BuiltinType ); 232 226 static DeclarationNode * newForall( DeclarationNode * ); 233 static DeclarationNode * newFromTypedef( const std::string * ); 234 static DeclarationNode * newFromGlobalScope(); 235 static DeclarationNode * newQualifiedType( DeclarationNode *, DeclarationNode * ); 236 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ); 227 static DeclarationNode * newFromTypedef( std::string * ); 228 static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle = false ); 237 229 static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 238 static DeclarationNode * newEnum( conststd::string * name, DeclarationNode * constants, bool body );239 static DeclarationNode * newEnumConstant( conststd::string * name, ExpressionNode * constant );240 static DeclarationNode * newName( conststd::string * );241 static DeclarationNode * newFromTypeGen( conststd::string *, ExpressionNode * params );242 static DeclarationNode * newTypeParam( TypeClass, conststd::string * );230 static DeclarationNode * newEnum( std::string * name, DeclarationNode * constants, bool body ); 231 static DeclarationNode * newEnumConstant( std::string * name, ExpressionNode * constant ); 232 static DeclarationNode * newName( std::string * ); 233 static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode * params ); 234 static DeclarationNode * newTypeParam( TypeClass, std::string * ); 243 235 static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts ); 244 236 static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params ); 245 static DeclarationNode * newTypeDecl( conststd::string * name, DeclarationNode * typeParams );237 static DeclarationNode * newTypeDecl( std::string * name, DeclarationNode * typeParams ); 246 238 static DeclarationNode * newPointer( DeclarationNode * qualifiers, OperKinds kind ); 247 239 static DeclarationNode * newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic ); … … 250 242 static DeclarationNode * newTuple( DeclarationNode * members ); 251 243 static DeclarationNode * newTypeof( ExpressionNode * expr ); 252 static DeclarationNode * newAttr( conststd::string *, ExpressionNode * expr ); // @ attributes253 static DeclarationNode * newAttr( conststd::string *, DeclarationNode * type ); // @ attributes254 static DeclarationNode * newAttribute( conststd::string *, ExpressionNode * expr = nullptr ); // gcc attributes244 static DeclarationNode * newAttr( std::string *, ExpressionNode * expr ); // @ attributes 245 static DeclarationNode * newAttr( std::string *, DeclarationNode * type ); // @ attributes 246 static DeclarationNode * newAttribute( std::string *, ExpressionNode * expr = nullptr ); // gcc attributes 255 247 static DeclarationNode * newAsmStmt( StatementNode * stmt ); // gcc external asm statement 256 static DeclarationNode * newStaticAssert( ExpressionNode * condition, Expression * message );257 248 258 249 DeclarationNode(); … … 271 262 DeclarationNode * addBitfield( ExpressionNode * size ); 272 263 DeclarationNode * addVarArgs(); 273 DeclarationNode * addFunctionBody( StatementNode * body, ExpressionNode * with = nullptr );264 DeclarationNode * addFunctionBody( StatementNode * body, StatementNode * with = nullptr ); 274 265 DeclarationNode * addOldDeclList( DeclarationNode * list ); 275 266 DeclarationNode * setBase( TypeData * newType ); … … 291 282 } 292 283 293 virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override;294 virtual void printList( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override;284 virtual void print( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override; 285 virtual void printList( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const override; 295 286 296 287 Declaration * build() const; 297 288 Type * buildType() const; 298 289 290 bool get_hasEllipsis() const; 299 291 LinkageSpec::Spec get_linkage() const { return linkage; } 300 292 DeclarationNode * extractAggregate() const; … … 304 296 bool get_extension() const { return extension; } 305 297 DeclarationNode * set_extension( bool exten ) { extension = exten; return this; } 306 307 bool get_inLine() const { return inLine; }308 DeclarationNode * set_inLine( bool inL ) { inLine = inL; return this; }309 298 public: 310 299 DeclarationNode * get_last() { return (DeclarationNode *)ParseNode::get_last(); } … … 325 314 Attr_t attr; 326 315 327 struct StaticAssert_t { 328 ExpressionNode * condition; 329 Expression * message; 330 }; 331 StaticAssert_t assert; 332 333 BuiltinType builtin = NoBuiltinType; 334 335 TypeData * type = nullptr; 336 337 bool inLine = false; 316 BuiltinType builtin; 317 318 TypeData * type; 319 338 320 Type::FuncSpecifiers funcSpecs; 339 321 Type::StorageClasses storageClasses; 340 322 341 ExpressionNode * bitfieldWidth = nullptr;323 ExpressionNode * bitfieldWidth; 342 324 std::unique_ptr<ExpressionNode> enumeratorValue; 343 bool hasEllipsis = false;325 bool hasEllipsis; 344 326 LinkageSpec::Spec linkage; 345 Expression * asmName = nullptr;327 Expression *asmName; 346 328 std::list< Attribute * > attributes; 347 InitializerNode * initializer = nullptr;329 InitializerNode * initializer; 348 330 bool extension = false; 349 331 std::string error; 350 StatementNode * asmStmt = nullptr;332 StatementNode * asmStmt; 351 333 352 334 static UniqueName anonymous; … … 382 364 virtual StatementNode * append_last_case( StatementNode * ); 383 365 384 virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override {366 virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override { 385 367 os << stmt.get() << std::endl; 386 368 } … … 391 373 Statement * build_expr( ExpressionNode * ctl ); 392 374 393 struct IfCt rl {394 IfCt rl( DeclarationNode * decl, ExpressionNode * condition ) :375 struct IfCtl { 376 IfCtl( DeclarationNode * decl, ExpressionNode * condition ) : 395 377 init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {} 396 378 … … 399 381 }; 400 382 401 struct ForCt rl {402 ForCt rl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :383 struct ForCtl { 384 ForCtl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) : 403 385 init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {} 404 ForCt rl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :386 ForCtl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) : 405 387 init( new StatementNode( decl ) ), condition( condition ), change( change ) {} 406 388 … … 410 392 }; 411 393 412 Expression * build_if_control( IfCtrl * ctl, std::list< Statement * > & init ); 413 Statement * build_if( IfCtrl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ); 414 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ); 394 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ); 395 Statement * build_switch( ExpressionNode * ctl, StatementNode * stmt ); 415 396 Statement * build_case( ExpressionNode * ctl ); 416 397 Statement * build_default(); 417 Statement * build_while( IfCtrl * ctl, StatementNode * stmt ); 418 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt ); 419 Statement * build_for( ForCtrl * forctl, StatementNode * stmt ); 398 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind = false ); 399 Statement * build_for( ForCtl * forctl, StatementNode * stmt ); 420 400 Statement * build_branch( BranchStmt::Type kind ); 421 401 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ); … … 429 409 Statement * build_finally( StatementNode * stmt ); 430 410 Statement * build_compound( StatementNode * first ); 431 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr ); 432 Statement * build_directive( std::string * directive ); 411 Statement * build_asmstmt( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr ); 433 412 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when ); 434 413 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing ); … … 440 419 441 420 template< typename SynTreeType, typename NodeType, template< typename, typename...> class Container, typename... Args > 442 void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > & outputList ) {443 SemanticError Exceptionerrors;421 void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > &outputList ) { 422 SemanticError errors; 444 423 std::back_insert_iterator< Container< SynTreeType *, Args... > > out( outputList ); 445 424 const NodeType * cur = firstNode; … … 454 433 assertf(false, "buildList unknown type"); 455 434 } // if 456 } catch( SemanticErrorException & e ) { 435 } catch( SemanticError &e ) { 436 e.set_location( cur->location ); 457 437 errors.append( e ); 458 438 } // try … … 465 445 466 446 // in DeclarationNode.cc 467 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList );468 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList );469 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList );447 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ); 448 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ); 449 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ); 470 450 471 451 template< typename SynTreeType, typename NodeType > 472 void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > & outputList ) {452 void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > &outputList ) { 473 453 buildList( firstNode, outputList ); 474 454 delete firstNode;
Note:
See TracChangeset
for help on using the changeset viewer.