Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Side by Side Diff: pkg/analyzer/tool/summary/idl.dart

Issue 1410383004: Introduce an "idl"-like format description for analyzer summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * This file is an "idl" style description of the summary format. It is not
7 * executed directly; instead it is parsed and transformed into code that
8 * implements the summary format.
9 *
10 * The code generation process introduces the following non-typical semantics:
11 * - Fields of type List have a default value of the empty list.
12 * - Fields of type int have a default value of zero.
13 * - Fields of type String have a defauld value of ''.
14 *
15 * Terminology used in this document:
16 * - "Unlinked" refers to information that can be determined from reading the
17 * .dart file for the library itself (including all parts) and no other
18 * files.
19 * - "Prelinked" refers to information that can be determined from reading the
20 * unlinked information for the library itself and the unlinked information
21 * for all direct imports (plus the transitive closure of exports reachable
22 * from those direct imports).
23 * - "Linked" refers to information that can be determined only from reading
24 * the unlinked and prelinked information for the library itself and the
25 * transitive closure of its imports.
26 *
27 * TODO(paulberry): currently the summary format only contains unlinked and
28 * prelinked information.
29 *
30 * Except as otherwise noted, synthetic elements are not stored in the summary;
31 * they are re-synthesized at the time the summary is read.
32 */
33 library analyzer.tool.summary.idl;
34
35 /**
36 * Annotation describing information which is not part of Dart semantics; in
37 * other words, if this information (or any information it refers to) changes,
38 * static analysis and runtime behavior of the library are unaffected.
39 *
40 * TODO(paulberry): some informative information is currently missing from the
41 * summary format.
42 */
43 const informative = null;
44
45 /**
46 * Annotation describing information which is not part of the public API to a
47 * library; in other words, if this information (or any information it refers
48 * to) changes, libraries outside this one are unaffected.
49 *
50 * TODO(paulberry): currently the summary format does not contain private
51 * information.
52 */
53 const private = null;
54
55 /**
56 * Annotation used to mark possible values of a "flags" field. These will be
57 * transformed into static constants.
58 */
59 class Flag {
scheglov 2015/10/20 00:20:22 Is it an enumeration, a bitfield or both?
Paul Berry 2015/10/20 15:54:09 Kind of a mishmash of both. I guess it's not very
60 final String name;
61 final int value;
62 final String comment;
63
64 const Flag(this.name, this.value, this.comment);
65 }
66
67 /**
68 * Information about a dependency that exists between one library and another
69 * due to an "import" declaration.
70 */
71 class PrelinkedDependency {
72 /**
73 * The relative URI used to import one library from the other.
74 */
75 String uri;
76 }
77
78 /**
79 * Pre-linked summary of a library.
80 */
81 class PrelinkedLibrary {
82 /**
83 * The unlinked library summary.
84 */
85 UnlinkedLibrary unlinked;
86
87 /**
88 * The libraries that this library depends on (either via an explicit import
89 * statement or via the implicit dependencies on `dart:core` and
90 * `dart:async`). The first element of this array is a pseudo-dependency
91 * representing the library itself (it is also used for "dynamic").
92 *
93 * TODO(paulberry): consider removing this entirely and just using
94 * [UnlinkedLibrary.imports].
95 */
96 List<PrelinkedDependency> dependencies;
97
98 /**
99 * For each import in [UnlinkedLibrary.imports], an index into [dependencies]
100 * of the library being imported.
101 *
102 * TODO(paulberry): if [dependencies] is removed, this can be removed as
103 * well, since there will effectively be a one-to-one mapping.
104 */
105 List<int> importDependencies;
106
107 /**
108 * For each reference in [UnlinkedLibrary.references], information about how
109 * that reference is resolved.
110 */
111 List<PrelinkedReference> references;
112 }
113
114 /**
115 * Information about the resolution of an [UnlinkedReference].
116 */
117 class PrelinkedReference {
118 /**
119 * Index into [LibraryElement.dependencies] indicating which imported library
Brian Wilkerson 2015/10/20 18:07:14 "LibraryElement" --> "UnlinkedLibrary"?
Paul Berry 2015/10/20 18:46:20 Whoops, thanks. I forgot to update this when I ma
120 * declares the entity being referred to.
Brian Wilkerson 2015/10/20 18:07:14 It isn't clear whether indexes like this one are z
Paul Berry 2015/10/20 18:46:20 You're right, this isn't particularly clear. In a
121 */
122 int dependency;
123
124 @Flag('CLASS', 0, 'Indicates that the thing being referred to is a class')
Brian Wilkerson 2015/10/20 18:07:14 Does "class" here include "enum", or should that b
Paul Berry 2015/10/20 18:46:20 It includes enum.
125 @Flag('TYPEDEF', 1, 'Indicates that the thing being referred to is a typedef')
126 @Flag('OTHER', 2,
127 'Indicates that the thing being referred to is a variable or executable')
128 @Flag('UNRESOLVED', 3,
129 'Indicates that the thing being referred to was not found')
130 int flags;
Brian Wilkerson 2015/10/20 18:07:14 Another possibility here would be to declare 'bool
Paul Berry 2015/10/20 18:46:20 I like this idea. I will experiment with this in
131 }
132
133 /**
134 * Unlinked summary information about a class declaration.
135 */
136 class UnlinkedClass {
137 /**
138 * Name of the class.
139 */
140 String name;
141
142 /**
143 * Index into [UnlinkedLibrary.units] indicating which compilation unit the
144 * class is declared in.
145 */
146 @informative
147 int unit;
148
149 /**
150 * Type parameters of the class, if any.
151 */
152 List<UnlinkedTypeParam> typeParameters;
153
154 /**
155 * Supertype of the class, or `null` if the class doesn't explicitly declare
156 * a supertype.
Brian Wilkerson 2015/10/20 18:07:14 Or if the class is `Object` and hence has no super
Paul Berry 2015/10/20 18:46:20 Correct.
157 */
158 UnlinkedTypeRef supertype;
159
160 /**
161 * Mixins appering in a `with` clause, if any.
162 */
163 List<UnlinkedTypeRef> mixins;
164
165 /**
166 * Interfaces appearing in an `implements` clause, if any.
167 */
168 List<UnlinkedTypeRef> interfaces;
169
170 /**
171 * Field declarations contained in the class.
172 */
173 List<UnlinkedVariable> fields;
174
175 /**
176 * Executable objects (methods, getters, and setters) contained in the class.
177 */
178 List<UnlinkedExecutable> executables;
179
180 @Flag(
181 'ABSTRACT', 1, 'Set if the class is declared with the `abstract` keyword')
182 @Flag('MIXIN_APP', 2,
183 'Set if the class is declared using mixin appliation syntax')
184 int flags;
185 }
186
187 /**
188 * Unlinked summary information about a `show` or `hide` combinator in an
189 * import or export declaration.
190 */
191 class UnlinkedCombinator {
192 /**
193 * List of names which are shown. Empty if this is a `hide` combinator.
194 */
195 List<String> shows;
196
197 /**
198 * List of names which are hidden. Empty if this is a `show` combinator.
199 */
200 List<String> hides;
201 }
202
203 /**
204 * Unlinked summary information about an enum declaration.
205 */
206 class UnlinkedEnum {
207 /**
208 * Name of the enum type.
209 */
210 String name;
211
212 /**
213 * Values listed in the enum declaration.
Brian Wilkerson 2015/10/20 18:07:14 Presumably in declaration order? (It isn't clear w
Paul Berry 2015/10/20 18:46:20 Yes, this one has to be in declaration order becau
214 */
215 List<UnlinkedEnumValue> values;
216
217 /**
218 * Index into [UnlinkedLibrary.units] indicating which compilation unit the
219 * enum is declared in.
220 */
221 @informative
222 int unit;
223 }
224
225 /**
226 * Unlinked summary information about a single enumerated value in an enum
227 * declaration.
228 */
229 class UnlinkedEnumValue {
230 /**
231 * Name of the enumerated value.
232 */
233 String name;
234 }
235
236 /**
237 * Unlinked summary information about a function, method, getter, or setter
238 * declaration.
239 */
240 class UnlinkedExecutable {
241 /**
242 * Name of the executable. For setters, this includes the trailing "=". For
243 * named constructors, this excludes the class name and excludes the ".".
244 * For unnamed constructors, this is the empty string.
245 */
246 String name;
247
248 /**
249 * Index into [UnlinkedLibrary.units] indicating which compilation unit the
250 * executable is declared in. Zero for executables which are nested inside
251 * another declaration (i.e. local functions and method declarations).
252 */
253 @informative
254 int unit;
255
256 /**
257 * Type parameters of the executable, if any. Empty if support for generic
258 * method syntax is disabled.
259 */
260 List<UnlinkedTypeParam> typeParameters;
261
262 /**
263 * Declared return type of the executable. Absent if the return type is
264 * `void`. Note that when strong mode is enabled, the actual return type may
265 * be different due to type inference.
266 */
267 UnlinkedTypeRef returnType;
268
269 /**
270 * Parameters of the executable, if any. Note that getters have no
271 * parameters, and setters have a single parameter.
Brian Wilkerson 2015/10/20 18:07:14 Do getters have an empty list, or `null`?
Paul Berry 2015/10/20 18:46:20 In keeping with protobuf semantics, I'm planning t
272 */
273 List<UnlinkedParam> parameters;
274
275 @Flag('FUNCTION', 0,
276 'Indicates that the declaration is for a function or method')
277 @Flag('GETTER', 1, 'Indicates that the declaration is for a getter')
278 @Flag('SETTER', 2, 'Indicates that the declaration is for a setter')
279 @Flag('CONSTRUCTOR', 3, 'Indicates that the declaration is for a constructor')
280 @Flag('ABSTRACT', 4, 'Set if the declaration lacks a function body')
281 @Flag('STATIC', 8, 'Set if the declaration includes the `static` keyword')
282 @Flag('CONST', 16,
283 'Set if the declaration includes the `const` keyword (constructors only)')
284 @Flag('FACTORY', 32,
285 'Set if the declaration includes the `factory` keyword (constructors only) ')
286 int flags;
287 }
288
289 /**
290 * Unlinked summary information about an export declaration.
291 */
292 class UnlinkedExport {
293 /**
294 * Relative URI used to reference the exported library.
Brian Wilkerson 2015/10/20 18:07:14 I assume that "Relative URI" (here and below) real
Paul Berry 2015/10/20 18:46:20 Correct.
295 */
296 String uri;
297
298 /**
299 * Combinators contained in this import declaration.
300 */
301 List<UnlinkedCombinator> combinators;
302 }
303
304 /**
305 * Unlinked summary information about an import declaration.
306 */
307 class UnlinkedImport {
308 /**
309 * Relative URI used to reference the imported library.
310 */
311 String uri;
312
313 /**
314 * Offset of the "import" keyword. Zero for implicit imports.
scheglov 2015/10/20 00:20:22 AFAIK we use -1 for synthetic elements. It is poss
Paul Berry 2015/10/20 15:54:09 Acknowledged. That's why I have an "IMPLICIT" fla
315 */
316 @informative
317 int offset;
318
319 /**
320 * Index into [UnlinkedLibrary.prefixes] of the prefix declared by this
321 * import declaration, or zero if this import declaration declares no prefix.
322 *
323 * Note that multiple imports can declare the same prefix.
324 */
325 int prefix;
326
327 /**
328 * Combinators contained in this import declaration.
329 */
330 List<UnlinkedCombinator> combinators;
331
332 @Flag('DEFERRED', 1, 'Set if this declaration uses the `deferred` keyword')
333 @Flag('IMPLICIT', 2, 'Set if this is an implicit import')
334 int flags;
335 }
336
337 /**
338 * Unlinked summary of an entire library.
339 */
340 class UnlinkedLibrary {
341 /**
342 * Top level and prefixed names referred to by this library.
343 */
344 List<UnlinkedReference> references;
345
346 /**
347 * Information about the units constituting this library. The first unit
348 * listed is always the defining compilation unit.
349 */
350 List<UnlinkedUnit> units;
351
352 /**
353 * Name of the library (from a "library" declaration, if present).
354 */
355 String name;
356
357 /**
358 * Classes declared in the library.
359 */
360 List<UnlinkedClass> classes;
361
362 /**
363 * Enums declared in the library.
364 */
365 List<UnlinkedEnum> enums;
366
367 /**
368 * Top level executable objects (functions, getters, and setters) declared in
369 * the library.
370 */
371 List<UnlinkedExecutable> executables;
372
373 /**
374 * Export declarations in the library.
375 */
376 List<UnlinkedExport> exports;
377
378 /**
379 * Import declarations in the library.
380 */
381 List<UnlinkedImport> imports;
382
383 /**
384 * Typedefs declared in the library.
385 */
386 List<UnlinkedTypedef> typedefs;
387
388 /**
389 * Top level variables declared in the library.
390 */
391 List<UnlinkedVariable> variables;
392
393 /**
394 * Prefixes introduced by import declarations. The first element in this
395 * array is a pseudo-prefix used by references made with no prefix.
396 */
397 List<UnlinkedPrefix> prefixes;
398 }
399
400 /**
401 * Unlinked summary information about a function parameter.
402 */
403 class UnlinkedParam {
404 /**
405 * Name of the parameter.
406 */
407 String name;
408
409 /**
410 * If this is a function-typed parameter, the declared return type.
411 * Otherwise, the declared type. Absent if this is a function-typed
412 * parameter and the declared return type is `void`. Note that when strong
413 * mode is enabled, the actual type may be different due to type inference.
414 */
415 UnlinkedTypeRef type;
416
417 /**
418 * If this is a function-typed parameter, the parameters of the function
419 * type.
420 */
421 List<UnlinkedParam> parameters;
422
423 @Flag('REQUIRED', 0, 'Indicates that this is a required parameter')
424 @Flag(
425 'POSITIONAL', 1, 'Indicates that this is a positional optional parameter')
426 @Flag('NAMED', 2, 'Indicates that this is a named optional parameter')
427 @Flag('FUNCTION_TYPED', 4, 'Set if this is a function-typed parameter')
428 @Flag('INITIALIZING_FORMAL', 8,
429 'Set if this is an initializing formal parameter')
430 int flags;
431 }
432
433 class UnlinkedPrefix {
434 /**
435 * The name of the prefix, or the empty string in the case of the
436 * pseudo-prefix which represents "no prefix".
437 */
438 String name;
439 }
440
441 /**
442 * Unlinked summary information about a name referred to in one library that
443 * might be defined in another.
444 */
445 class UnlinkedReference {
446 /**
447 * Name of the entity being referred to.
448 */
449 String name;
450
451 /**
452 * Prefix used to refer to the entity. This is an index into
453 * [UnlinkedLibrary.prefixes].
454 */
455 int prefix;
456 }
457
458 /**
459 * Unlinked summary information about a typedef declaration.
460 */
461 class UnlinkedTypedef {
462 /**
463 * Name of the typedef.
464 */
465 String name;
466
467 /**
468 * Index into [UnlinkedLibrary.units] indicating which compilation unit the
469 * typedef is declared in.
470 */
471 @informative
472 int unit;
473
474 /**
475 * Type parameters of the typedef, if any.
476 */
477 List<UnlinkedTypeParam> typeParameters;
478
479 /**
480 * Return type of the typedef. Absent if the return type is `void`.
481 */
482 UnlinkedTypeRef returnType;
483
484 /**
485 * Parameters of the executable, if any.
486 */
487 List<UnlinkedParam> parameters;
488 }
489
490 /**
491 * Unlinked summary information about a type parameter declaration.
492 */
493 class UnlinkedTypeParam {
494 /**
495 * Name of the type parameter.
496 */
497 String name;
498
499 /**
500 * Bound of the type parameter, if a bound is explicitly declared. Otherwise
501 * null.
502 */
503 UnlinkedTypeRef bound;
504 }
505
506 /**
507 * Unlinked summary information about a reference to a type.
508 */
509 class UnlinkedTypeRef {
510 /**
511 * Index into [UnlinkedLibrary.references] for the type being referred to, or
512 * zero if this is a reference to a type parameter.
513 */
514 int reference;
515
516 /**
517 * If this is a reference to a type parameter, one-based index into
518 * [UnlinkedClass.typeParameters] or [UnlinkedTypedef.typeParameters] for the
519 * parameter being referenced. Otherwise zero.
520 *
521 * If generic method syntax is enabled, this may also be a one-based index
522 * into [UnlinkedExecutable.typeParameters]. Note that this creates an
523 * ambiguity since it allows executables with type parameters to be nested
524 * inside other declarations with type parameters (which might themselves be
525 * executables). The ambiguity is resolved by considering this to be a
526 * one-based index into a list that concatenates all type parameters that are
527 * in scope, listing the outermost type parameters first.
528 */
529 int paramReference;
530
531 /**
532 * If this is an instantiation of a generic type, the type arguments used to
533 * instantiate it. Trailing type arguments of type `dynamic` are omitted.
534 */
535 List<UnlinkedTypeRef> typeArguments;
536 }
537
538 /**
539 * Unlinked summary information about a compilation unit ("part file"). Note
540 * that since a declaration can be moved from one part file to another without
541 * changing semantics, the declarations themselves aren't stored here; they are
542 * stored in [UnlinkedLibrary] and they refer to [UnlinkedUnit]s via an index
543 * into [UnlinkedLibrary.units].
544 */
545 class UnlinkedUnit {
546 /**
547 * String used in the defining compilation unit to reference the part file.
548 * Empty for the defining compilation unit itself.
549 */
550 String uri;
551 }
552
553 /**
554 * Unlinked summary information about a top level variable, local variable, or
555 * a field.
556 */
557 class UnlinkedVariable {
558 /**
559 * Name of the variable.
560 */
561 String name;
562
563 /**
564 * Index into [UnlinkedLibrary.units] indicating which compilation unit the
565 * variable is declared in. Zero for variables which are nested inside
566 * another declaration (i.e. local variables and fields).
567 */
568 @informative
569 int unit;
570
571 /**
572 * Declared type of the variable. Note that when strong mode is enabled, the
573 * actual type of the variable may be different due to type inference.
574 */
575 UnlinkedTypeRef type;
576
577 @Flag('STATIC', 1, 'Set if the declaration includes the `static` keyword')
578 @Flag('FINAL', 2, 'Set if the declaration includes the `final` keyword')
579 @Flag('CONST', 4, 'Set if the declaration includes the `const` keyword')
580 int flags;
581 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698