| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart2js.parser.partial_elements; | 5 library dart2js.parser.partial_elements; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/resolution.dart' show ParsingContext, Resolution; | 8 import '../common/resolution.dart' show ParsingContext, Resolution; |
| 9 import '../elements/resolution_types.dart' show ResolutionDynamicType; | 9 import '../elements/resolution_types.dart' show ResolutionDynamicType; |
| 10 import '../elements/elements.dart' | 10 import '../elements/elements.dart' |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 _position = ElementX.findNameToken( | 78 _position = ElementX.findNameToken( |
| 79 beginToken, | 79 beginToken, |
| 80 modifiers.isFactory || isGenerativeConstructor, | 80 modifiers.isFactory || isGenerativeConstructor, |
| 81 name, | 81 name, |
| 82 enclosingElement.name); | 82 enclosingElement.name); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool get hasNode => cachedNode != null; | 85 bool get hasNode => cachedNode != null; |
| 86 | 86 |
| 87 FunctionExpression get node { | 87 FunctionExpression get node { |
| 88 assert(invariant(this, cachedNode != null, | 88 assert(cachedNode != null, |
| 89 message: "Node has not been computed for $this.")); | 89 failedAt(this, "Node has not been computed for $this.")); |
| 90 return cachedNode; | 90 return cachedNode; |
| 91 } | 91 } |
| 92 | 92 |
| 93 FunctionExpression parseNode(ParsingContext parsing) { | 93 FunctionExpression parseNode(ParsingContext parsing) { |
| 94 if (cachedNode != null) return cachedNode; | 94 if (cachedNode != null) return cachedNode; |
| 95 parseFunction(Parser p) { | 95 parseFunction(Parser p) { |
| 96 if (isClassMember && modifiers.isFactory) { | 96 if (isClassMember && modifiers.isFactory) { |
| 97 p.parseFactoryMethod(beginToken); | 97 p.parseFactoryMethod(beginToken); |
| 98 } else if (isClassMember) { | 98 } else if (isClassMember) { |
| 99 p.parseMember(beginToken); | 99 p.parseMember(beginToken); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 return cachedNode; | 334 return cachedNode; |
| 335 } else { | 335 } else { |
| 336 assert(metadata is ErrorNode); | 336 assert(metadata is ErrorNode); |
| 337 return metadata; | 337 return metadata; |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 | 340 |
| 341 bool get hasNode => cachedNode != null; | 341 bool get hasNode => cachedNode != null; |
| 342 | 342 |
| 343 Node get node { | 343 Node get node { |
| 344 assert(invariant(this, hasNode)); | 344 assert(hasNode, failedAt(this)); |
| 345 return cachedNode; | 345 return cachedNode; |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 | 348 |
| 349 class PartialClassElement extends ClassElementX with PartialElement { | 349 class PartialClassElement extends ClassElementX with PartialElement { |
| 350 ClassNode cachedNode; | 350 ClassNode cachedNode; |
| 351 | 351 |
| 352 PartialClassElement( | 352 PartialClassElement( |
| 353 String name, Token beginToken, Token endToken, Element enclosing, int id) | 353 String name, Token beginToken, Token endToken, Element enclosing, int id) |
| 354 : super(name, enclosing, id, STATE_NOT_STARTED) { | 354 : super(name, enclosing, id, STATE_NOT_STARTED) { |
| 355 this.beginToken = beginToken; | 355 this.beginToken = beginToken; |
| 356 this.endToken = endToken; | 356 this.endToken = endToken; |
| 357 } | 357 } |
| 358 | 358 |
| 359 void set supertypeLoadState(int state) { | 359 void set supertypeLoadState(int state) { |
| 360 assert(state == STATE_NOT_STARTED || state == supertypeLoadState + 1); | 360 assert(state == STATE_NOT_STARTED || state == supertypeLoadState + 1); |
| 361 assert(state <= STATE_DONE); | 361 assert(state <= STATE_DONE); |
| 362 super.supertypeLoadState = state; | 362 super.supertypeLoadState = state; |
| 363 } | 363 } |
| 364 | 364 |
| 365 void set resolutionState(int state) { | 365 void set resolutionState(int state) { |
| 366 assert(state == STATE_NOT_STARTED || state == resolutionState + 1); | 366 assert(state == STATE_NOT_STARTED || state == resolutionState + 1); |
| 367 assert(state <= STATE_DONE); | 367 assert(state <= STATE_DONE); |
| 368 super.resolutionState = state; | 368 super.resolutionState = state; |
| 369 } | 369 } |
| 370 | 370 |
| 371 bool get hasNode => cachedNode != null; | 371 bool get hasNode => cachedNode != null; |
| 372 | 372 |
| 373 ClassNode get node { | 373 ClassNode get node { |
| 374 assert(invariant(this, cachedNode != null, | 374 assert(cachedNode != null, |
| 375 message: "Node has not been computed for $this.")); | 375 failedAt(this, "Node has not been computed for $this.")); |
| 376 return cachedNode; | 376 return cachedNode; |
| 377 } | 377 } |
| 378 | 378 |
| 379 ClassNode parseNode(ParsingContext parsing) { | 379 ClassNode parseNode(ParsingContext parsing) { |
| 380 if (cachedNode != null) return cachedNode; | 380 if (cachedNode != null) return cachedNode; |
| 381 DiagnosticReporter reporter = parsing.reporter; | 381 DiagnosticReporter reporter = parsing.reporter; |
| 382 reporter.withCurrentElement(this, () { | 382 reporter.withCurrentElement(this, () { |
| 383 parsing.measure(() { | 383 parsing.measure(() { |
| 384 MemberListener listener = new MemberListener( | 384 MemberListener listener = new MemberListener( |
| 385 parsing.getScannerOptionsFor(this), reporter, this); | 385 parsing.getScannerOptionsFor(this), reporter, this); |
| 386 Parser parser = new ClassElementParser(listener); | 386 Parser parser = new ClassElementParser(listener); |
| 387 try { | 387 try { |
| 388 Token token = parser.parseTopLevelDeclaration(beginToken); | 388 Token token = parser.parseTopLevelDeclaration(beginToken); |
| 389 assert(identical(token, endToken.next)); | 389 assert(identical(token, endToken.next)); |
| 390 cachedNode = listener.popNode(); | 390 cachedNode = listener.popNode(); |
| 391 assert(invariant( | 391 assert( |
| 392 reporter.spanFromToken(beginToken), listener.nodes.isEmpty, | 392 listener.nodes.isEmpty, |
| 393 message: "Non-empty listener stack: ${listener.nodes}")); | 393 failedAt(reporter.spanFromToken(beginToken), |
| 394 "Non-empty listener stack: ${listener.nodes}")); |
| 394 } on ParserError { | 395 } on ParserError { |
| 395 // TODO(ahe): Often, a ParserError is thrown while parsing the class | 396 // TODO(ahe): Often, a ParserError is thrown while parsing the class |
| 396 // body. This means that the stack actually contains most of the | 397 // body. This means that the stack actually contains most of the |
| 397 // information synthesized below. Consider rewriting the parser so | 398 // information synthesized below. Consider rewriting the parser so |
| 398 // endClassDeclaration is called before parsing the class body. | 399 // endClassDeclaration is called before parsing the class body. |
| 399 Identifier name = new Identifier(findMyName(beginToken)); | 400 Identifier name = new Identifier(findMyName(beginToken)); |
| 400 NodeList typeParameters = null; | 401 NodeList typeParameters = null; |
| 401 Node supertype = null; | 402 Node supertype = null; |
| 402 NodeList interfaces = listener.makeNodeList(0, null, null, ","); | 403 NodeList interfaces = listener.makeNodeList(0, null, null, ","); |
| 403 Token extendsKeyword = null; | 404 Token extendsKeyword = null; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } on ParserError catch (e) { | 455 } on ParserError catch (e) { |
| 455 partial.hasParseError = true; | 456 partial.hasParseError = true; |
| 456 return new ErrorNode(element.position, e.message); | 457 return new ErrorNode(element.position, e.message); |
| 457 } | 458 } |
| 458 Node node = listener.popNode(); | 459 Node node = listener.popNode(); |
| 459 assert(listener.nodes.isEmpty); | 460 assert(listener.nodes.isEmpty); |
| 460 return node; | 461 return node; |
| 461 }); | 462 }); |
| 462 }); | 463 }); |
| 463 } | 464 } |
| OLD | NEW |