mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
[kernel] FileUriExpression node
Change-Id: I8ea3cbeb17d555cebd6d693fbf2bb3148e9f2db3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114321 Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
70a7cbf49d
commit
0242f0c724
|
@ -4945,6 +4945,12 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
|||
throw UnsupportedError("Instance creation");
|
||||
}
|
||||
|
||||
@override
|
||||
js_ast.Expression visitFileUriExpression(FileUriExpression node) {
|
||||
// Only occurs inside unevaluated constants.
|
||||
throw UnsupportedError("File URI expression");
|
||||
}
|
||||
|
||||
@override
|
||||
js_ast.Expression visitIsExpression(IsExpression node) {
|
||||
return _emitIsExpression(node.operand, node.type);
|
||||
|
|
|
@ -1854,6 +1854,7 @@ original
|
|||
originally
|
||||
originate
|
||||
originated
|
||||
originates
|
||||
originating
|
||||
origins
|
||||
orphan
|
||||
|
|
Binary file not shown.
|
@ -143,7 +143,7 @@ type CanonicalName {
|
|||
|
||||
type ComponentFile {
|
||||
UInt32 magic = 0x90ABCDEF;
|
||||
UInt32 formatVersion = 30;
|
||||
UInt32 formatVersion = 31;
|
||||
List<String> problemsAsJson; // Described in problems.md.
|
||||
Library[] libraries;
|
||||
UriSource sourceMap;
|
||||
|
@ -760,6 +760,13 @@ type InstanceCreation extends Expression {
|
|||
List<Expression> unusedArguments;
|
||||
}
|
||||
|
||||
type FileUriExpression extends Expression {
|
||||
Byte tag = 116;
|
||||
UriReference fileUri;
|
||||
FileOffset fileOffset;
|
||||
Expression expression;
|
||||
}
|
||||
|
||||
type IsExpression extends Expression {
|
||||
Byte tag = 37;
|
||||
FileOffset fileOffset;
|
||||
|
|
|
@ -3540,7 +3540,7 @@ class MapConcatenation extends Expression {
|
|||
|
||||
/// Create an instance directly from the field values.
|
||||
///
|
||||
/// This expression arises from const constructor calls when one or more field
|
||||
/// These expressions arise from const constructor calls when one or more field
|
||||
/// initializing expressions, field initializers, assert initializers or unused
|
||||
/// arguments contain unevaluated expressions. They only ever occur within
|
||||
/// unevaluated constants in constant expressions.
|
||||
|
@ -3592,6 +3592,43 @@ class InstanceCreation extends Expression {
|
|||
}
|
||||
}
|
||||
|
||||
/// A marker indicating that a subexpression originates in a different source
|
||||
/// file than the surrounding context.
|
||||
///
|
||||
/// These expressions arise from inlining of const variables during constant
|
||||
/// evaluation. They only ever occur within unevaluated constants in constant
|
||||
/// expressions.
|
||||
class FileUriExpression extends Expression implements FileUriNode {
|
||||
/// The URI of the source file in which the subexpression is located.
|
||||
/// Can be different from the file containing the [FileUriExpression].
|
||||
Uri fileUri;
|
||||
|
||||
Expression expression;
|
||||
|
||||
FileUriExpression(this.expression, this.fileUri) {
|
||||
expression.parent = this;
|
||||
}
|
||||
|
||||
DartType getStaticType(TypeEnvironment types) =>
|
||||
expression.getStaticType(types);
|
||||
|
||||
R accept<R>(ExpressionVisitor<R> v) => v.visitFileUriExpression(this);
|
||||
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) =>
|
||||
v.visitFileUriExpression(this, arg);
|
||||
|
||||
visitChildren(Visitor v) {
|
||||
expression.accept(v);
|
||||
}
|
||||
|
||||
transformChildren(Transformer v) {
|
||||
expression = expression.accept<TreeNode>(v)..parent = this;
|
||||
}
|
||||
|
||||
Location _getLocationInEnclosingFile(int offset) {
|
||||
return _getLocationInComponent(enclosingComponent, fileUri, offset);
|
||||
}
|
||||
}
|
||||
|
||||
/// Expression of form `x is T`.
|
||||
class IsExpression extends Expression {
|
||||
Expression operand;
|
||||
|
|
|
@ -1664,6 +1664,11 @@ class BinaryBuilder {
|
|||
return new InstanceCreation(classReference, typeArguments, fieldValues,
|
||||
asserts, unusedArguments)
|
||||
..fileOffset = offset;
|
||||
case Tag.FileUriExpression:
|
||||
Uri fileUri = readUriReference();
|
||||
int offset = readOffset();
|
||||
return new FileUriExpression(readExpression(), fileUri)
|
||||
..fileOffset = offset;
|
||||
case Tag.IsExpression:
|
||||
int offset = readOffset();
|
||||
return new IsExpression(readExpression(), readDartType())
|
||||
|
|
|
@ -1569,6 +1569,14 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
|
|||
writeNodeList(node.unusedArguments);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitFileUriExpression(FileUriExpression node) {
|
||||
writeByte(Tag.FileUriExpression);
|
||||
writeUriReference(node.fileUri);
|
||||
writeOffset(node.fileOffset);
|
||||
writeNode(node.expression);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitIsExpression(IsExpression node) {
|
||||
writeByte(Tag.IsExpression);
|
||||
|
|
|
@ -81,6 +81,7 @@ class Tag {
|
|||
static const int ConstMapLiteral = 59;
|
||||
static const int SetLiteral = 109;
|
||||
static const int ConstSetLiteral = 110;
|
||||
static const int FileUriExpression = 116;
|
||||
|
||||
// Statements
|
||||
static const int ExpressionStatement = 61;
|
||||
|
@ -127,6 +128,8 @@ class Tag {
|
|||
/// 112 is occupied by [SetConcatenation] (expression).
|
||||
/// 113 is occupied by [MapConcatenation] (expression).
|
||||
/// 114 is occupied by [InstanceCreation] (expression).
|
||||
/// 115 is occupied by [Extension].
|
||||
/// 116 is occupied by [FileUriExpression] (expression).
|
||||
|
||||
static const int SpecializedTagHighBit = 0x80; // 10000000
|
||||
static const int SpecializedTagMask = 0xF8; // 11111000
|
||||
|
@ -143,7 +146,7 @@ class Tag {
|
|||
/// Internal version of kernel binary format.
|
||||
/// Bump it when making incompatible changes in kernel binaries.
|
||||
/// Keep in sync with runtime/vm/kernel_binary.h, pkg/kernel/binary.md.
|
||||
static const int BinaryFormatVersion = 30;
|
||||
static const int BinaryFormatVersion = 31;
|
||||
}
|
||||
|
||||
abstract class ConstantTag {
|
||||
|
|
|
@ -222,6 +222,10 @@ class CloneVisitor implements TreeVisitor<TreeNode> {
|
|||
node.unusedArguments.map(clone).toList());
|
||||
}
|
||||
|
||||
visitFileUriExpression(FileUriExpression node) {
|
||||
return new FileUriExpression(clone(node.expression), _activeFileUri);
|
||||
}
|
||||
|
||||
visitIsExpression(IsExpression node) {
|
||||
return new IsExpression(clone(node.operand), visitType(node.type));
|
||||
}
|
||||
|
|
|
@ -1437,6 +1437,10 @@ class Printer extends Visitor<Null> {
|
|||
writeSymbol('}');
|
||||
}
|
||||
|
||||
visitFileUriExpression(FileUriExpression node) {
|
||||
writeExpression(node.expression);
|
||||
}
|
||||
|
||||
visitIsExpression(IsExpression node) {
|
||||
writeExpression(node.operand, Precedence.BITWISE_OR);
|
||||
writeSpaced('is');
|
||||
|
|
|
@ -395,6 +395,12 @@ class TextSerializationVerifier implements Visitor<void> {
|
|||
node.visitChildren(this);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitFileUriExpression(FileUriExpression node) {
|
||||
storeLastSeenUriAndOffset(node);
|
||||
node.visitChildren(this);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSymbolConstant(SymbolConstant node) {
|
||||
storeLastSeenUriAndOffset(node);
|
||||
|
|
|
@ -724,6 +724,11 @@ class TypeCheckingVisitor
|
|||
return new InterfaceType(node.classNode, node.typeArguments);
|
||||
}
|
||||
|
||||
@override
|
||||
DartType visitFileUriExpression(FileUriExpression node) {
|
||||
return visitExpression(node.expression);
|
||||
}
|
||||
|
||||
@override
|
||||
DartType visitStringLiteral(StringLiteral node) {
|
||||
return environment.stringType;
|
||||
|
|
|
@ -43,6 +43,7 @@ abstract class ExpressionVisitor<R> {
|
|||
R visitSetConcatenation(SetConcatenation node) => defaultExpression(node);
|
||||
R visitMapConcatenation(MapConcatenation node) => defaultExpression(node);
|
||||
R visitInstanceCreation(InstanceCreation node) => defaultExpression(node);
|
||||
R visitFileUriExpression(FileUriExpression node) => defaultExpression(node);
|
||||
R visitIsExpression(IsExpression node) => defaultExpression(node);
|
||||
R visitAsExpression(AsExpression node) => defaultExpression(node);
|
||||
R visitSymbolLiteral(SymbolLiteral node) => defaultExpression(node);
|
||||
|
@ -170,6 +171,7 @@ class TreeVisitor<R>
|
|||
R visitSetConcatenation(SetConcatenation node) => defaultExpression(node);
|
||||
R visitMapConcatenation(MapConcatenation node) => defaultExpression(node);
|
||||
R visitInstanceCreation(InstanceCreation node) => defaultExpression(node);
|
||||
R visitFileUriExpression(FileUriExpression node) => defaultExpression(node);
|
||||
R visitIsExpression(IsExpression node) => defaultExpression(node);
|
||||
R visitAsExpression(AsExpression node) => defaultExpression(node);
|
||||
R visitSymbolLiteral(SymbolLiteral node) => defaultExpression(node);
|
||||
|
@ -685,6 +687,8 @@ abstract class ExpressionVisitor1<R, T> {
|
|||
defaultExpression(node, arg);
|
||||
R visitInstanceCreation(InstanceCreation node, T arg) =>
|
||||
defaultExpression(node, arg);
|
||||
R visitFileUriExpression(FileUriExpression node, T arg) =>
|
||||
defaultExpression(node, arg);
|
||||
R visitIsExpression(IsExpression node, T arg) => defaultExpression(node, arg);
|
||||
R visitAsExpression(AsExpression node, T arg) => defaultExpression(node, arg);
|
||||
R visitSymbolLiteral(SymbolLiteral node, T arg) =>
|
||||
|
|
|
@ -98,6 +98,7 @@ RawInstance* ConstantEvaluator::EvaluateExpression(intptr_t offset,
|
|||
case kSetConcatenation:
|
||||
case kMapConcatenation:
|
||||
case kInstanceCreation:
|
||||
case kFileUriExpression:
|
||||
// These only occur inside unevaluated constants, so if we decide to
|
||||
// remove support for late evaluation of environment constants from
|
||||
// dill files in the VM, an implementation here will not be necessary.
|
||||
|
|
|
@ -1164,8 +1164,9 @@ Fragment StreamingFlowGraphBuilder::BuildExpression(TokenPosition* position) {
|
|||
case kSetConcatenation:
|
||||
case kMapConcatenation:
|
||||
case kInstanceCreation:
|
||||
// Collection concatenation and instance creation operations are removed
|
||||
// by the constant evaluator.
|
||||
case kFileUriExpression:
|
||||
// Collection concatenation, instance creation operations and
|
||||
// in-expression URI changes are removed by the constant evaluator.
|
||||
UNREACHABLE();
|
||||
break;
|
||||
case kIsExpression:
|
||||
|
|
|
@ -461,8 +461,9 @@ void KernelFingerprintHelper::CalculateExpressionFingerprint() {
|
|||
case kSetConcatenation:
|
||||
case kMapConcatenation:
|
||||
case kInstanceCreation:
|
||||
// Collection concatenation and instance creation operations are removed
|
||||
// by the constant evaluator.
|
||||
case kFileUriExpression:
|
||||
// Collection concatenation, instance creation operations and
|
||||
// in-expression URI changes are removed by the constant evaluator.
|
||||
UNREACHABLE();
|
||||
break;
|
||||
case kIsExpression:
|
||||
|
|
|
@ -2248,8 +2248,9 @@ void KernelReaderHelper::SkipExpression() {
|
|||
case kSetConcatenation:
|
||||
case kMapConcatenation:
|
||||
case kInstanceCreation:
|
||||
// Collection concatenation and instance creation operations are removed
|
||||
// by the constant evaluator.
|
||||
case kFileUriExpression:
|
||||
// Collection concatenation, instance creation operations and
|
||||
// in-expression URI changes are removed by the constant evaluator.
|
||||
UNREACHABLE();
|
||||
break;
|
||||
case kIsExpression:
|
||||
|
|
|
@ -789,8 +789,9 @@ void ScopeBuilder::VisitExpression() {
|
|||
case kSetConcatenation:
|
||||
case kMapConcatenation:
|
||||
case kInstanceCreation:
|
||||
// Collection concatenation and instance creation operations are removed
|
||||
// by the constant evaluator.
|
||||
case kFileUriExpression:
|
||||
// Collection concatenation, instance creation operations and
|
||||
// in-expression URI changes are removed by the constant evaluator.
|
||||
UNREACHABLE();
|
||||
break;
|
||||
case kIsExpression:
|
||||
|
|
|
@ -20,7 +20,7 @@ static const uint32_t kMagicProgramFile = 0x90ABCDEFu;
|
|||
|
||||
// Both version numbers are inclusive.
|
||||
static const uint32_t kMinSupportedKernelFormatVersion = 18;
|
||||
static const uint32_t kMaxSupportedKernelFormatVersion = 30;
|
||||
static const uint32_t kMaxSupportedKernelFormatVersion = 31;
|
||||
|
||||
// Keep in sync with package:kernel/lib/binary/tag.dart
|
||||
#define KERNEL_TAG_LIST(V) \
|
||||
|
@ -67,6 +67,7 @@ static const uint32_t kMaxSupportedKernelFormatVersion = 30;
|
|||
V(SetConcatenation, 112) \
|
||||
V(MapConcatenation, 113) \
|
||||
V(InstanceCreation, 114) \
|
||||
V(FileUriExpression, 116) \
|
||||
V(IsExpression, 37) \
|
||||
V(AsExpression, 38) \
|
||||
V(StringLiteral, 39) \
|
||||
|
|
Loading…
Reference in a new issue