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 13 matching lines...) Expand all Loading... |
24 ConstructorElementX, | 24 ConstructorElementX, |
25 DeclarationSite, | 25 DeclarationSite, |
26 ElementX, | 26 ElementX, |
27 GetterElementX, | 27 GetterElementX, |
28 MetadataAnnotationX, | 28 MetadataAnnotationX, |
29 MethodElementX, | 29 MethodElementX, |
30 SetterElementX, | 30 SetterElementX, |
31 TypedefElementX, | 31 TypedefElementX, |
32 VariableList; | 32 VariableList; |
33 import '../elements/visitor.dart' show ElementVisitor; | 33 import '../elements/visitor.dart' show ElementVisitor; |
34 import '../tokens/token.dart' show Token; | 34 import 'package:dart_scanner/dart_scanner.dart' show Token; |
35 import '../tokens/token_constants.dart' as Tokens show EOF_TOKEN; | 35 import 'package:dart_scanner/dart_scanner.dart' as Tokens show EOF_TOKEN; |
36 import '../tree/tree.dart'; | 36 import '../tree/tree.dart'; |
37 import 'class_element_parser.dart' show ClassElementParser; | 37 import 'package:dart_parser/dart_parser.dart' |
38 import 'listener.dart' show ParserError; | 38 show ClassMemberParser, Parser, ParserError; |
39 import 'member_listener.dart' show MemberListener; | 39 import 'member_listener.dart' show MemberListener; |
40 import 'node_listener.dart' show NodeListener; | 40 import 'node_listener.dart' show NodeListener; |
41 import 'parser.dart' show Parser; | |
42 | 41 |
43 abstract class PartialElement implements DeclarationSite { | 42 abstract class PartialElement implements DeclarationSite { |
44 Token beginToken; | 43 Token beginToken; |
45 Token endToken; | 44 Token endToken; |
46 | 45 |
47 bool hasParseError = false; | 46 bool hasParseError = false; |
48 | 47 |
49 bool get isMalformed => hasParseError; | 48 bool get isMalformed => hasParseError; |
50 | 49 |
51 DeclarationSite get declarationSite => this; | 50 DeclarationSite get declarationSite => this; |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 return cachedNode; | 366 return cachedNode; |
368 } | 367 } |
369 | 368 |
370 ClassNode parseNode(ParsingContext parsing) { | 369 ClassNode parseNode(ParsingContext parsing) { |
371 if (cachedNode != null) return cachedNode; | 370 if (cachedNode != null) return cachedNode; |
372 DiagnosticReporter reporter = parsing.reporter; | 371 DiagnosticReporter reporter = parsing.reporter; |
373 reporter.withCurrentElement(this, () { | 372 reporter.withCurrentElement(this, () { |
374 parsing.measure(() { | 373 parsing.measure(() { |
375 MemberListener listener = new MemberListener( | 374 MemberListener listener = new MemberListener( |
376 parsing.getScannerOptionsFor(this), reporter, this); | 375 parsing.getScannerOptionsFor(this), reporter, this); |
377 Parser parser = new ClassElementParser(listener); | 376 Parser parser = new ClassMemberParser(listener); |
378 try { | 377 try { |
379 Token token = parser.parseTopLevelDeclaration(beginToken); | 378 Token token = parser.parseTopLevelDeclaration(beginToken); |
380 assert(identical(token, endToken.next)); | 379 assert(identical(token, endToken.next)); |
381 cachedNode = listener.popNode(); | 380 cachedNode = listener.popNode(); |
382 assert(invariant(beginToken, listener.nodes.isEmpty, | 381 assert(invariant(reporter.spanFromToken(beginToken), |
383 message: "Non-empty listener stack: ${listener.nodes}")); | 382 listener.nodes.isEmpty, |
| 383 message: "Non-empty listener stack: ${listener.nodes}")); |
384 } on ParserError { | 384 } on ParserError { |
385 // TODO(ahe): Often, a ParserError is thrown while parsing the class | 385 // TODO(ahe): Often, a ParserError is thrown while parsing the class |
386 // body. This means that the stack actually contains most of the | 386 // body. This means that the stack actually contains most of the |
387 // information synthesized below. Consider rewriting the parser so | 387 // information synthesized below. Consider rewriting the parser so |
388 // endClassDeclaration is called before parsing the class body. | 388 // endClassDeclaration is called before parsing the class body. |
389 Identifier name = new Identifier(findMyName(beginToken)); | 389 Identifier name = new Identifier(findMyName(beginToken)); |
390 NodeList typeParameters = null; | 390 NodeList typeParameters = null; |
391 Node supertype = null; | 391 Node supertype = null; |
392 NodeList interfaces = listener.makeNodeList(0, null, null, ","); | 392 NodeList interfaces = listener.makeNodeList(0, null, null, ","); |
393 Token extendsKeyword = null; | 393 Token extendsKeyword = null; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 NodeListener listener = new NodeListener( | 436 NodeListener listener = new NodeListener( |
437 parsing.getScannerOptionsFor(element), reporter, unit); | 437 parsing.getScannerOptionsFor(element), reporter, unit); |
438 listener.memberErrors = listener.memberErrors.prepend(false); | 438 listener.memberErrors = listener.memberErrors.prepend(false); |
439 try { | 439 try { |
440 if (partial.hasParseError) { | 440 if (partial.hasParseError) { |
441 listener.suppressParseErrors = true; | 441 listener.suppressParseErrors = true; |
442 } | 442 } |
443 doParse(new Parser(listener)); | 443 doParse(new Parser(listener)); |
444 } on ParserError catch (e) { | 444 } on ParserError catch (e) { |
445 partial.hasParseError = true; | 445 partial.hasParseError = true; |
446 return new ErrorNode(element.position, e.reason); | 446 return new ErrorNode(element.position, e.kind, e.arguments); |
447 } | 447 } |
448 Node node = listener.popNode(); | 448 Node node = listener.popNode(); |
449 assert(listener.nodes.isEmpty); | 449 assert(listener.nodes.isEmpty); |
450 return node; | 450 return node; |
451 }); | 451 }); |
452 }); | 452 }); |
453 } | 453 } |
OLD | NEW |