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

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

Issue 1596703002: Generate code UnlinkedConst / UnlinkedConstOperation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 | « pkg/analyzer/tool/summary/generate.dart ('k') | 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
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 /** 5 /**
6 * This file is an "idl" style description of the summary format. It is not 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 7 * executed directly; instead it is parsed and transformed into code that
8 * implements the summary format. 8 * implements the summary format.
9 * 9 *
10 * The code generation process introduces the following non-typical semantics: 10 * The code generation process introduces the following non-typical semantics:
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 */ 345 */
346 List<String> shows; 346 List<String> shows;
347 347
348 /** 348 /**
349 * List of names which are hidden. Empty if this is a `show` combinator. 349 * List of names which are hidden. Empty if this is a `show` combinator.
350 */ 350 */
351 List<String> hides; 351 List<String> hides;
352 } 352 }
353 353
354 /** 354 /**
355 * Unlinked summary information about a compile-time constant expression, or a
356 * potentially constant expression.
357 *
358 * Constant expressions are represented using a simple stack-based language
359 * where [operations] is a sequence of operations to execute starting with an
360 * empty stack. Once all operations have been executed, the stack should
361 * contain a single value which is the value of the constant. Note that some
362 * operations consume additional data from the other fields of this class.
363 */
364 class UnlinkedConst {
365 /**
366 * Sequence of operations to execute (starting with an empty stack) to form
367 * the constant value.
368 */
369 List<UnlinkedConstOperation> operations;
370
371 /**
372 * Sequence of 32-bit integers consumed by the operations `pushArgument`,
373 * `pushInt`, `shiftOr`, `concatenate`, `invokeConstructor`, `makeList`, and
374 * `makeMap`.
375 */
376 List<int> ints;
377
378 /**
379 * Sequence of 64-bit doubles consumed by the operation `pushDouble`.
380 */
381 List<double> doubles;
382
383 /**
384 * Sequence of strings consumed by the operations `pushString` and
385 * `invokeConstructor`.
386 */
387 List<String> strings;
388
389 /**
390 * Sequence of language constructs consumed by the operations
391 * `pushReference`, `invokeConstructor`, `makeList`, and `makeMap`. Note
392 * that in the case of `pushReference` (and sometimes `invokeConstructor` the
393 * actual entity being referred to may be something other than a type.
394 */
395 List<UnlinkedTypeRef> references;
396 }
397
398 /**
399 * Enum representing the various kinds of operations which may be performed to
400 * produce a constant value. These options are assumed to execute in the
401 * context of a stack which is initially empty.
402 */
403 enum UnlinkedConstOperation {
404 /**
405 * Push the value of the n-th constructor argument (where n is obtained from
406 * [UnlinkedConst.ints]) onto the stack.
407 */
408 pushArgument,
409
410 /**
411 * Push the next value from [UnlinkedConst.ints] (a 32-bit signed integer)
412 * onto the stack.
413 *
414 * Note that Dart supports integers larger than 32 bits; these are
415 * represented by composing 32 bit values using the [shiftOr] operation.
416 */
417 pushInt,
418
419 /**
420 * Pop the top value off the stack, which should be an integer. Multiply it
421 * by 2^32, "or" in the next value from [UnlinkedConst.ints] (which is
422 * interpreted as a 32-bit unsigned integer), and push the result back onto
423 * the stack.
424 */
425 shiftOr,
426
427 /**
428 * Push the next value from [UnlinkedConst.doubles] (a double precision
429 * floating point value) onto the stack.
430 */
431 pushDouble,
432
433 /**
434 * Push the constant `true` onto the stack.
435 */
436 pushTrue,
437
438 /**
439 * Push the constant `false` onto the stack.
440 */
441 pushFalse,
442
443 /**
444 * Push the next value from [UnlinkedConst.strings] onto the stack.
445 */
446 pushString,
447
448 /**
449 * Pop the top n values from the stack (where n is obtained from
450 * [UnlinkedConst.ints]), convert them to strings (if they aren't already),
451 * concatenate them into a single string, and push it back onto the stack.
452 *
453 * This operation is used to represent constants whose value is a literal
454 * string containing string interpolations.
455 */
456 concatenate,
457
458 /**
459 * Pop the top value from the stack, which should be a string, convert it to
460 * a symbol, and push it back onto the stack.
461 */
462 makeSymbol,
463
464 /**
465 * Push the constant `null` onto the stack.
466 */
467 pushNull,
468
469 /**
470 * Evaluate a (potentially qualified) identifier expression and push the
471 * resulting value onto the stack. The identifier to be evaluated is
472 * obtained from [UnlinkedConst.references].
473 *
474 * This operation is used to represent the following kinds of constants
475 * (which are indistinguishable from an unresolved AST alone):
476 *
477 * - A qualified reference to a static constant variable (e.g. `C.v`, where
478 * C is a class and `v` is a constant static variable in `C`).
479 * - An identifier expression referring to a constant variable.
480 * - A simple or qualified identifier denoting a class or type alias.
481 * - A simple or qualified identifier denoting a top-level function or a
482 * static method.
483 */
484 pushReference,
485
486 /**
487 * Pop the top n values from the stack (where n is obtained from
488 * [UnlinkedConst.ints]), use them to invoke a constant constructor whose
489 * name is obtained from [UnlinkedConst.strings], and whose class is obtained
490 * from [UnlinkedConst.references], and push the resulting value back onto
491 * the stack.
492 *
493 * Note that for an invocation of the form `const a.b(...)` (where no type
494 * arguments are specified), it is impossible to tell from the unresolved AST
495 * alone whether `a` is a class name and `b` is a constructor name, or `a` is
496 * a prefix name and `b` is a class name. In this case it is presumed that
497 * `a` is a prefix name and `b` is a class name.
498 *
499 * TODO(paulberry): figure out how to resolve this ambiguity in the
500 * "prelinked" part of the summary.
501 */
502 invokeConstructor,
503
504 /**
505 * Pop the top n values from the stack (where n is obtained from
506 * [UnlinkedConst.ints]), place them in a [List], and push the result back
507 * onto the stack. The type parameter for the [List] is obtained from
508 * [UnlinkedConst.references].
509 */
510 makeList,
511
512 /**
513 * Pop the top 2*n values from the stack (where n is obtained from
514 * [UnlinkedConst.ints]), interpret them as key/value pairs, place them in a
515 * [Map], and push the result back onto the stack. The two type parameters fo r
516 * the [Map] are obtained from [UnlinkedConst.references].
517 */
518 makeMap,
519
520 /**
521 * Pop the top 2 values from the stack, pass them to the predefined Dart
522 * function `identical`, and push the result back onto the stack.
523 */
524 identical,
525
526 /**
527 * Pop the top 2 values from the stack, evaluate `v1 == v2`, and push the
528 * result back onto the stack.
529 *
530 * This is also used to represent `v1 != v2`, by composition with [not].
531 */
532 equal,
533
534 /**
535 * Pop the top value from the stack, compute its boolean negation, and push
536 * the result back onto the stack.
537 */
538 not,
539
540 /**
541 * Pop the top 2 values from the stack, compute `v1 && v2`, and push the
542 * result back onto the stack.
543 */
544 and,
545
546 /**
547 * Pop the top 2 values from the stack, compute `v1 || v2`, and push the
548 * result back onto the stack.
549 */
550 or,
551
552 /**
553 * Pop the top value from the stack, compute its integer complement, and push
554 * the result back onto the stack.
555 */
556 complement,
557
558 /**
559 * Pop the top 2 values from the stack, compute `v1 ^ v2`, and push the
560 * result back onto the stack.
561 */
562 bitXor,
563
564 /**
565 * Pop the top 2 values from the stack, compute `v1 & v2`, and push the
566 * result back onto the stack.
567 */
568 bitAnd,
569
570 /**
571 * Pop the top 2 values from the stack, compute `v1 | v2`, and push the
572 * result back onto the stack.
573 */
574 bitOr,
575
576 /**
577 * Pop the top 2 values from the stack, compute `v1 >> v2`, and push the
578 * result back onto the stack.
579 */
580 bitShiftRight,
581
582 /**
583 * Pop the top 2 values from the stack, compute `v1 << v2`, and push the
584 * result back onto the stack.
585 */
586 bitShiftLeft,
587
588 /**
589 * Pop the top 2 values from the stack, compute `v1 + v2`, and push the
590 * result back onto the stack.
591 */
592 add,
593
594 /**
595 * Pop the top value from the stack, compute its integer negation, and push
596 * the result back onto the stack.
597 */
598 negate,
599
600 /**
601 * Pop the top 2 values from the stack, compute `v1 - v2`, and push the
602 * result back onto the stack.
603 */
604 subtract,
605
606 /**
607 * Pop the top 2 values from the stack, compute `v1 * v2`, and push the
608 * result back onto the stack.
609 */
610 multiply,
611
612 /**
613 * Pop the top 2 values from the stack, compute `v1 / v2`, and push the
614 * result back onto the stack.
615 */
616 divide,
617
618 /**
619 * Pop the top 2 values from the stack, compute `v1 ~/ v2`, and push the
620 * result back onto the stack.
621 */
622 floorDivide,
623
624 /**
625 * Pop the top 2 values from the stack, compute `v1 > v2`, and push the
626 * result back onto the stack.
627 */
628 greater,
629
630 /**
631 * Pop the top 2 values from the stack, compute `v1 < v2`, and push the
632 * result back onto the stack.
633 */
634 less,
635
636 /**
637 * Pop the top 2 values from the stack, compute `v1 >= v2`, and push the
638 * result back onto the stack.
639 */
640 greaterEqual,
641
642 /**
643 * Pop the top 2 values from the stack, compute `v1 <= v2`, and push the
644 * result back onto the stack.
645 */
646 lessEqual,
647
648 /**
649 * Pop the top 2 values from the stack, compute `v1 % v2`, and push the
650 * result back onto the stack.
651 */
652 modulo,
653
654 /**
655 * Pop the top 3 values from the stack, compute `v1 ? v2 : v3`, and push the
656 * result back onto the stack.
657 */
658 conditional,
659
660 /**
661 * Pop the top value from the stack, evaluate `v.length`, and push the result
662 * back onto the stack.
663 */
664 length,
665 }
666
667 /**
355 * Unlinked summary information about a documentation comment. 668 * Unlinked summary information about a documentation comment.
356 */ 669 */
357 class UnlinkedDocumentationComment { 670 class UnlinkedDocumentationComment {
358 /** 671 /**
359 * Text of the documentation comment, with '\r\n' replaced by '\n'. 672 * Text of the documentation comment, with '\r\n' replaced by '\n'.
360 * 673 *
361 * References appearing within the doc comment in square brackets are not 674 * References appearing within the doc comment in square brackets are not
362 * specially encoded. 675 * specially encoded.
363 */ 676 */
364 String text; 677 String text;
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 @informative 1341 @informative
1029 UnlinkedDocumentationComment documentationComment; 1342 UnlinkedDocumentationComment documentationComment;
1030 1343
1031 /** 1344 /**
1032 * Declared type of the variable. Note that when strong mode is enabled, the 1345 * Declared type of the variable. Note that when strong mode is enabled, the
1033 * actual type of the variable may be different due to type inference. 1346 * actual type of the variable may be different due to type inference.
1034 */ 1347 */
1035 UnlinkedTypeRef type; 1348 UnlinkedTypeRef type;
1036 1349
1037 /** 1350 /**
1351 * If [isConst] is true, and the variable has an initializer, the constant
1352 * expression in the initializer.
1353 */
1354 UnlinkedConst constExpr;
1355
1356 /**
1038 * Indicates whether the variable is declared using the `static` keyword. 1357 * Indicates whether the variable is declared using the `static` keyword.
1039 * 1358 *
1040 * Note that for top level variables, this flag is false, since they are not 1359 * Note that for top level variables, this flag is false, since they are not
1041 * declared using the `static` keyword (even though they are considered 1360 * declared using the `static` keyword (even though they are considered
1042 * static for semantic purposes). 1361 * static for semantic purposes).
1043 */ 1362 */
1044 bool isStatic; 1363 bool isStatic;
1045 1364
1046 /** 1365 /**
1047 * Indicates whether the variable is declared using the `final` keyword. 1366 * Indicates whether the variable is declared using the `final` keyword.
1048 */ 1367 */
1049 bool isFinal; 1368 bool isFinal;
1050 1369
1051 /** 1370 /**
1052 * Indicates whether the variable is declared using the `const` keyword. 1371 * Indicates whether the variable is declared using the `const` keyword.
1053 */ 1372 */
1054 bool isConst; 1373 bool isConst;
1055 1374
1056 /** 1375 /**
1057 * Indicates whether this variable lacks an explicit type declaration. 1376 * Indicates whether this variable lacks an explicit type declaration.
1058 */ 1377 */
1059 bool hasImplicitType; 1378 bool hasImplicitType;
1060 } 1379 }
OLDNEW
« no previous file with comments | « pkg/analyzer/tool/summary/generate.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698