| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// ----------------------------------------------------------------------- | 5 /// ----------------------------------------------------------------------- |
| 6 /// ERROR HANDLING | 6 /// ERROR HANDLING |
| 7 /// ----------------------------------------------------------------------- | 7 /// ----------------------------------------------------------------------- |
| 8 /// | 8 /// |
| 9 /// As a rule of thumb, errors that can be detected statically are handled by | 9 /// As a rule of thumb, errors that can be detected statically are handled by |
| 10 /// the frontend, typically by translating the erroneous code into a 'throw' or | 10 /// the frontend, typically by translating the erroneous code into a 'throw' or |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 /// other than [ClassLevel.Body]. Members in an external library have no | 262 /// other than [ClassLevel.Body]. Members in an external library have no |
| 263 /// body, but have their typed interface present. | 263 /// body, but have their typed interface present. |
| 264 /// | 264 /// |
| 265 /// If the libary is non-external, then its classes are at [ClassLevel.Body] | 265 /// If the libary is non-external, then its classes are at [ClassLevel.Body] |
| 266 /// and all members are loaded. | 266 /// and all members are loaded. |
| 267 bool isExternal; | 267 bool isExternal; |
| 268 | 268 |
| 269 String name; | 269 String name; |
| 270 final List<Expression> annotations; | 270 final List<Expression> annotations; |
| 271 final List<LibraryDependency> dependencies; | 271 final List<LibraryDependency> dependencies; |
| 272 @informative |
| 273 final List<LibraryPart> parts; |
| 272 final List<Typedef> typedefs; | 274 final List<Typedef> typedefs; |
| 273 final List<Class> classes; | 275 final List<Class> classes; |
| 274 final List<Procedure> procedures; | 276 final List<Procedure> procedures; |
| 275 final List<Field> fields; | 277 final List<Field> fields; |
| 276 | 278 |
| 277 Library(this.importUri, | 279 Library(this.importUri, |
| 278 {this.name, | 280 {this.name, |
| 279 this.isExternal: false, | 281 this.isExternal: false, |
| 280 List<Expression> annotations, | 282 List<Expression> annotations, |
| 281 List<LibraryDependency> dependencies, | 283 List<LibraryDependency> dependencies, |
| 284 List<LibraryPart> parts, |
| 282 List<Typedef> typedefs, | 285 List<Typedef> typedefs, |
| 283 List<Class> classes, | 286 List<Class> classes, |
| 284 List<Procedure> procedures, | 287 List<Procedure> procedures, |
| 285 List<Field> fields, | 288 List<Field> fields, |
| 286 this.fileUri, | 289 this.fileUri, |
| 287 Reference reference}) | 290 Reference reference}) |
| 288 : this.annotations = annotations ?? <Expression>[], | 291 : this.annotations = annotations ?? <Expression>[], |
| 289 this.dependencies = dependencies ?? <LibraryDependency>[], | 292 this.dependencies = dependencies ?? <LibraryDependency>[], |
| 293 this.parts = parts ?? <LibraryPart>[], |
| 290 this.typedefs = typedefs ?? <Typedef>[], | 294 this.typedefs = typedefs ?? <Typedef>[], |
| 291 this.classes = classes ?? <Class>[], | 295 this.classes = classes ?? <Class>[], |
| 292 this.procedures = procedures ?? <Procedure>[], | 296 this.procedures = procedures ?? <Procedure>[], |
| 293 this.fields = fields ?? <Field>[], | 297 this.fields = fields ?? <Field>[], |
| 294 super(reference) { | 298 super(reference) { |
| 295 setParents(this.dependencies, this); | 299 setParents(this.dependencies, this); |
| 300 setParents(this.parts, this); |
| 296 setParents(this.typedefs, this); | 301 setParents(this.typedefs, this); |
| 297 setParents(this.classes, this); | 302 setParents(this.classes, this); |
| 298 setParents(this.procedures, this); | 303 setParents(this.procedures, this); |
| 299 setParents(this.fields, this); | 304 setParents(this.fields, this); |
| 300 } | 305 } |
| 301 | 306 |
| 302 /// Returns the top-level fields and procedures defined in this library. | 307 /// Returns the top-level fields and procedures defined in this library. |
| 303 /// | 308 /// |
| 304 /// This getter is for convenience, not efficiency. Consider manually | 309 /// This getter is for convenience, not efficiency. Consider manually |
| 305 /// iterating the members to speed up code in production. | 310 /// iterating the members to speed up code in production. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 for (var class_ in classes) { | 351 for (var class_ in classes) { |
| 347 canonicalName.getChild(class_.name).bindTo(class_.reference); | 352 canonicalName.getChild(class_.name).bindTo(class_.reference); |
| 348 class_.computeCanonicalNames(); | 353 class_.computeCanonicalNames(); |
| 349 } | 354 } |
| 350 } | 355 } |
| 351 | 356 |
| 352 void addDependency(LibraryDependency node) { | 357 void addDependency(LibraryDependency node) { |
| 353 dependencies.add(node..parent = this); | 358 dependencies.add(node..parent = this); |
| 354 } | 359 } |
| 355 | 360 |
| 361 void addPart(LibraryPart node) { |
| 362 parts.add(node..parent = this); |
| 363 } |
| 364 |
| 356 accept(TreeVisitor v) => v.visitLibrary(this); | 365 accept(TreeVisitor v) => v.visitLibrary(this); |
| 357 | 366 |
| 358 visitChildren(Visitor v) { | 367 visitChildren(Visitor v) { |
| 359 visitList(dependencies, v); | 368 visitList(dependencies, v); |
| 369 visitList(parts, v); |
| 360 visitList(typedefs, v); | 370 visitList(typedefs, v); |
| 361 visitList(classes, v); | 371 visitList(classes, v); |
| 362 visitList(procedures, v); | 372 visitList(procedures, v); |
| 363 visitList(fields, v); | 373 visitList(fields, v); |
| 364 } | 374 } |
| 365 | 375 |
| 366 transformChildren(Transformer v) { | 376 transformChildren(Transformer v) { |
| 367 transformList(dependencies, v, this); | 377 transformList(dependencies, v, this); |
| 378 transformList(parts, v, this); |
| 368 transformList(typedefs, v, this); | 379 transformList(typedefs, v, this); |
| 369 transformList(classes, v, this); | 380 transformList(classes, v, this); |
| 370 transformList(procedures, v, this); | 381 transformList(procedures, v, this); |
| 371 transformList(fields, v, this); | 382 transformList(fields, v, this); |
| 372 } | 383 } |
| 373 | 384 |
| 374 static int _libraryIdCounter = 0; | 385 static int _libraryIdCounter = 0; |
| 375 int _libraryId = ++_libraryIdCounter; | 386 int _libraryId = ++_libraryIdCounter; |
| 376 | 387 |
| 377 int compareTo(Library other) => _libraryId - other._libraryId; | 388 int compareTo(Library other) => _libraryId - other._libraryId; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 visitList(annotations, v); | 467 visitList(annotations, v); |
| 457 visitList(combinators, v); | 468 visitList(combinators, v); |
| 458 } | 469 } |
| 459 | 470 |
| 460 transformChildren(Transformer v) { | 471 transformChildren(Transformer v) { |
| 461 transformList(annotations, v, this); | 472 transformList(annotations, v, this); |
| 462 transformList(combinators, v, this); | 473 transformList(combinators, v, this); |
| 463 } | 474 } |
| 464 } | 475 } |
| 465 | 476 |
| 477 /// A part declaration in a library. |
| 478 /// |
| 479 /// part <url>; |
| 480 /// |
| 481 /// optionally with metadata. |
| 482 class LibraryPart extends TreeNode { |
| 483 final List<Expression> annotations; |
| 484 final String fileUri; |
| 485 |
| 486 LibraryPart(List<Expression> annotations, String fileUri) |
| 487 : this.byReference(annotations, fileUri); |
| 488 |
| 489 LibraryPart.byReference(this.annotations, this.fileUri) { |
| 490 setParents(annotations, this); |
| 491 } |
| 492 |
| 493 void addAnnotation(Expression annotation) { |
| 494 annotations.add(annotation..parent = this); |
| 495 } |
| 496 |
| 497 accept(TreeVisitor v) => v.visitLibraryPart(this); |
| 498 |
| 499 visitChildren(Visitor v) { |
| 500 visitList(annotations, v); |
| 501 } |
| 502 |
| 503 transformChildren(Transformer v) { |
| 504 transformList(annotations, v, this); |
| 505 } |
| 506 } |
| 507 |
| 466 /// A `show` or `hide` clause for an import or export. | 508 /// A `show` or `hide` clause for an import or export. |
| 467 class Combinator extends TreeNode { | 509 class Combinator extends TreeNode { |
| 468 bool isShow; | 510 bool isShow; |
| 469 final List<String> names; | 511 final List<String> names; |
| 470 | 512 |
| 471 LibraryDependency get dependency => parent; | 513 LibraryDependency get dependency => parent; |
| 472 | 514 |
| 473 Combinator(this.isShow, this.names); | 515 Combinator(this.isShow, this.names); |
| 474 Combinator.show(this.names) : isShow = true; | 516 Combinator.show(this.names) : isShow = true; |
| 475 Combinator.hide(this.names) : isShow = false; | 517 Combinator.hide(this.names) : isShow = false; |
| (...skipping 4215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4691 if (typedef_.canonicalName == null) { | 4733 if (typedef_.canonicalName == null) { |
| 4692 throw '$typedef_ has no canonical name'; | 4734 throw '$typedef_ has no canonical name'; |
| 4693 } | 4735 } |
| 4694 return typedef_.canonicalName; | 4736 return typedef_.canonicalName; |
| 4695 } | 4737 } |
| 4696 | 4738 |
| 4697 /// Annotation describing information which is not part of Dart semantics; in | 4739 /// Annotation describing information which is not part of Dart semantics; in |
| 4698 /// other words, if this information (or any information it refers to) changes, | 4740 /// other words, if this information (or any information it refers to) changes, |
| 4699 /// static analysis and runtime behavior of the library are unaffected. | 4741 /// static analysis and runtime behavior of the library are unaffected. |
| 4700 const informative = null; | 4742 const informative = null; |
| OLD | NEW |