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 4198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4209 return hash; | 4209 return hash; |
4210 } | 4210 } |
4211 } | 4211 } |
4212 | 4212 |
4213 // ------------------------------------------------------------------------ | 4213 // ------------------------------------------------------------------------ |
4214 // PROGRAM | 4214 // PROGRAM |
4215 // ------------------------------------------------------------------------ | 4215 // ------------------------------------------------------------------------ |
4216 | 4216 |
4217 /// A way to bundle up all the libraries in a program. | 4217 /// A way to bundle up all the libraries in a program. |
4218 class Program extends TreeNode { | 4218 class Program extends TreeNode { |
4219 final CanonicalName root = new CanonicalName.root(); | 4219 final CanonicalName root; |
Siggi Cherem (dart-lang)
2017/05/10 18:00:38
Question for Kevin on API design here:
- should w
Kevin Millikin (Google)
2017/05/11 08:22:55
Even without these changes, Program is already not
| |
4220 | 4220 |
4221 final List<Library> libraries; | 4221 final List<Library> libraries; |
4222 | 4222 |
4223 /// Map from a source file uri to a line-starts table and source code. | 4223 /// Map from a source file uri to a line-starts table and source code. |
4224 /// Given a source file uri and a offset in that file one can translate | 4224 /// Given a source file uri and a offset in that file one can translate |
4225 /// it to a line:column position in that file. | 4225 /// it to a line:column position in that file. |
4226 final Map<String, Source> uriToSource; | 4226 final Map<String, Source> uriToSource; |
4227 | 4227 |
4228 /// Reference to the main method in one of the libraries. | 4228 /// Reference to the main method in one of the libraries. |
4229 Reference mainMethodName; | 4229 Reference mainMethodName; |
4230 | 4230 |
4231 Program([List<Library> libraries, Map<String, Source> uriToSource]) | 4231 Program( |
4232 : libraries = libraries ?? <Library>[], | 4232 {CanonicalName nameRoot, |
4233 List<Library> libraries, | |
4234 Map<String, Source> uriToSource}) | |
4235 : root = nameRoot ?? new CanonicalName.root(), | |
4236 libraries = libraries ?? <Library>[], | |
4233 uriToSource = uriToSource ?? <String, Source>{} { | 4237 uriToSource = uriToSource ?? <String, Source>{} { |
4234 setParents(this.libraries, this); | 4238 setParents(this.libraries, this); |
4235 } | 4239 } |
4236 | 4240 |
4237 void computeCanonicalNames() { | 4241 void computeCanonicalNames() { |
4238 for (var library in libraries) { | 4242 for (var library in libraries) { |
4243 if (library.canonicalName != null) continue; | |
Kevin Millikin (Google)
2017/05/11 08:22:55
Keep in mind that this approach of skipping librar
scheglov
2017/05/11 18:31:25
OK, I rolled this back.
| |
4239 root.getChildFromUri(library.importUri).bindTo(library.reference); | 4244 root.getChildFromUri(library.importUri).bindTo(library.reference); |
4240 library.computeCanonicalNames(); | 4245 library.computeCanonicalNames(); |
4241 } | 4246 } |
4242 } | 4247 } |
4243 | 4248 |
4244 void unbindCanonicalNames() { | 4249 void unbindCanonicalNames() { |
4245 root.unbindAll(); | 4250 root.unbindAll(); |
4246 } | 4251 } |
4247 | 4252 |
4248 Procedure get mainMethod => mainMethodName?.asProcedure; | 4253 Procedure get mainMethod => mainMethodName?.asProcedure; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4480 /// typedef has not been assigned a canonical name yet. | 4485 /// typedef has not been assigned a canonical name yet. |
4481 /// | 4486 /// |
4482 /// Returns `null` if the typedef is `null`. | 4487 /// Returns `null` if the typedef is `null`. |
4483 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) { | 4488 CanonicalName getCanonicalNameOfTypedef(Typedef typedef_) { |
4484 if (typedef_ == null) return null; | 4489 if (typedef_ == null) return null; |
4485 if (typedef_.canonicalName == null) { | 4490 if (typedef_.canonicalName == null) { |
4486 throw '$typedef_ has no canonical name'; | 4491 throw '$typedef_ has no canonical name'; |
4487 } | 4492 } |
4488 return typedef_.canonicalName; | 4493 return typedef_.canonicalName; |
4489 } | 4494 } |
OLD | NEW |