Skip to content

Commit

Permalink
Version 3.1.0-36.0.dev
Browse files Browse the repository at this point in the history
Merge fe01a20 into dev
  • Loading branch information
Dart CI committed Apr 24, 2023
2 parents a1c1e0d + fe01a20 commit 87ab2d2
Show file tree
Hide file tree
Showing 907 changed files with 11,530 additions and 5,214 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ vars = {

# co19 is a cipd package. Use update.sh in tests/co19[_2] to update these
# hashes.
"co19_rev": "c01fbd751c060650b6582523a7751b83777026c3",
"co19_rev": "4b8157719cdcb99ee7380c920551786b6383f961",
# This line prevents conflicts when both packages are rolled simultaneously.
"co19_2_rev": "ae846ed2a987a2d2dbe4b9e9c68448a21f91ef5b",

Expand Down
10 changes: 10 additions & 0 deletions pkg/_fe_analyzer_shared/lib/src/parser/forwarding_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,11 @@ class ForwardingListener implements Listener {
listener?.handleParenthesizedCondition(token, case_, when);
}

@override
void beginPattern(Token token) {
listener?.beginPattern(token);
}

@override
void beginPatternGuard(Token when) {
listener?.beginPatternGuard(when);
Expand All @@ -1892,6 +1897,11 @@ class ForwardingListener implements Listener {
listener?.handleRecordPattern(token, count);
}

@override
void endPattern(Token token) {
listener?.endPattern(token);
}

@override
void endPatternGuard(Token token) {
listener?.endPatternGuard(token);
Expand Down
10 changes: 10 additions & 0 deletions pkg/_fe_analyzer_shared/lib/src/parser/listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1944,6 +1944,11 @@ class Listener implements UnescapeErrorListener {
logEvent("ParenthesizedCondition");
}

/// Starts a pattern
void beginPattern(Token token) {
logEvent("Pattern");
}

/// Starts a pattern guard, the expression that follows the 'when' keyword
void beginPatternGuard(Token when) {
logEvent("PatternGuard");
Expand All @@ -1969,6 +1974,11 @@ class Listener implements UnescapeErrorListener {
logEvent("RecordPattern");
}

/// Ends a pattern
void endPattern(Token token) {
logEvent("Pattern");
}

/// End a pattern guard, the expression that follows the 'when' keyword
void endPatternGuard(Token token) {
logEvent("PatternGuard");
Expand Down
7 changes: 6 additions & 1 deletion pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9676,12 +9676,16 @@ class Parser {
{int precedence = 1}) {
assert(precedence >= 1);
assert(precedence <= SELECTOR_PRECEDENCE);
listener.beginPattern(token);
Token start = token.next!;
token = parsePrimaryPattern(token, patternContext);
while (true) {
Token next = token.next!;
int tokenLevel = _computePrecedence(next, forPattern: true);
if (tokenLevel < precedence) return token;
if (tokenLevel < precedence) {
listener.endPattern(token);
return token;
}
switch (next.lexeme) {
// castPattern ::= primaryPattern 'as' type
case 'as':
Expand Down Expand Up @@ -9724,6 +9728,7 @@ class Parser {
break;
default:
// Some other operator that doesn't belong in a pattern
listener.endPattern(token);
return token;
}
// None of the pattern types handled by the switch above are valid inside
Expand Down
10 changes: 10 additions & 0 deletions pkg/analyzer/lib/src/fasta/ast_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,11 @@ class AstBuilder extends StackListener {
push(mixinToken ?? NullValues.Token);
}

@override
void beginPattern(Token token) {
debugEvent("Pattern");
}

@override
void beginPatternGuard(Token when) {
debugEvent("PatternGuard");
Expand Down Expand Up @@ -2910,6 +2915,11 @@ class AstBuilder extends StackListener {
);
}

@override
void endPattern(Token token) {
debugEvent("Pattern");
}

@override
void endPatternGuard(Token when) {
debugEvent("PatternGuard");
Expand Down
114 changes: 100 additions & 14 deletions pkg/front_end/lib/src/fasta/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2714,6 +2714,94 @@ class BodyBuilder extends StackListenerImpl
]));
}

@override
void beginPattern(Token token) {
debugEvent("Pattern");
if (token.lexeme == "||") {
createAndEnterLocalScope(
debugName: "rhs of a binary-or pattern",
kind: ScopeKind.orPatternRight);
} else {
createAndEnterLocalScope(debugName: "pattern", kind: ScopeKind.pattern);
}
}

@override
void endPattern(Token token) {
debugEvent("Pattern");
assert(checkState(token, [
unionOfKinds([
ValueKinds.Expression,
ValueKinds.Generator,
ValueKinds.ProblemBuilder,
ValueKinds.Pattern,
]),
ValueKinds.Scope,
]));
Object pattern = pop()!;
ScopeKind scopeKind = scope.kind;

exitLocalScope(expectedScopeKinds: const [
ScopeKind.pattern,
ScopeKind.orPatternRight
]);

// Bring the variables into the enclosing pattern scope, unless that was
// the scope of the RHS of a binary-or pattern. In the latter case, the
// joint variables will be declared in the enclosing scope instead later in
// the process.
//
// Here we only handle the visibility of the pattern declared variables
// within the pattern itself, so we declare the pattern variables in the
// enclosing scope only if that enclosing scope is a pattern scope as well,
// that is, if its kind is [ScopeKind.pattern] or
// [ScopeKind.orPatternRight].
bool enclosingScopeIsPatternScope = scope.kind == ScopeKind.pattern ||
scope.kind == ScopeKind.orPatternRight;
if (scopeKind != ScopeKind.orPatternRight && enclosingScopeIsPatternScope) {
if (pattern is Pattern) {
for (VariableDeclaration variable in pattern.declaredVariables) {
declareVariable(variable, scope);
}
}
}

push(pattern);
}

@override
void beginBinaryPattern(Token token) {
debugEvent("BinaryPattern");
assert(checkState(token, [
unionOfKinds([
ValueKinds.Expression,
ValueKinds.Generator,
ValueKinds.ProblemBuilder,
ValueKinds.Pattern,
]),
ValueKinds.Scope,
]));

// In case of the binary-or pattern, its LHS and RHS should contain
// declarations of the variables with matching names, and we need to put
// them into separate scopes to avoid the naming conflict. For that, we're
// exiting the scope for the LHS, and the scope for the RHS will be created
// when the RHS will be parsed. Additionally, since it's the first time
// we're realizing that it's the binary-or pattern, we need to create the
// enclosing scope for its joint variables as well.
if (token.lexeme == "||") {
Object lhsPattern = pop()!;

// Exit the scope of the LHS.
exitLocalScope(expectedScopeKinds: const [ScopeKind.pattern]);

createAndEnterLocalScope(
debugName: "joint variables of binary-or patterns",
kind: ScopeKind.pattern);
push(lhsPattern);
}
}

@override
void endBinaryPattern(Token token) {
debugEvent("BinaryPattern");
Expand Down Expand Up @@ -2768,12 +2856,17 @@ class BodyBuilder extends StackListenerImpl
noLength);
}
}
List<VariableDeclaration> jointVariables = [
for (VariableDeclaration leftVariable in left.declaredVariables)
forest.createVariableDeclaration(
leftVariable.fileOffset, leftVariable.name!)
];
for (VariableDeclaration variable in jointVariables) {
declareVariable(variable, scope);
typeInferrer.assignedVariables.declare(variable);
}
push(forest.createOrPattern(token.charOffset, left, right,
orPatternJointVariables: [
for (VariableDeclaration leftVariable in left.declaredVariables)
forest.createVariableDeclaration(
leftVariable.fileOffset, leftVariable.name!)
]));
orPatternJointVariables: jointVariables));
break;
default:
internalProblem(
Expand Down Expand Up @@ -3585,7 +3678,6 @@ class BodyBuilder extends StackListenerImpl
debugName: "if-case-head", kind: ScopeKind.ifCaseHead);
for (VariableDeclaration variable in pattern.declaredVariables) {
declareVariable(variable, scope);
typeInferrer.assignedVariables.declare(variable);
}
}

Expand Down Expand Up @@ -3620,7 +3712,6 @@ class BodyBuilder extends StackListenerImpl
for (VariableDeclaration variable
in patternGuard.pattern.declaredVariables) {
declareVariable(variable, scope);
typeInferrer.assignedVariables.declare(variable);
}
Scope thenScope = scope.createNestedScope(
debugName: "then body", kind: ScopeKind.statementLocalScope);
Expand Down Expand Up @@ -4098,7 +4189,6 @@ class BodyBuilder extends StackListenerImpl
pop(); // Metadata.
for (VariableDeclaration variable in pattern.declaredVariables) {
declareVariable(variable, scope);
typeInferrer.assignedVariables.declare(variable);
}
Scope forScope = scope.createNestedScope(
debugName: "pattern-for internal variables",
Expand Down Expand Up @@ -6642,7 +6732,6 @@ class BodyBuilder extends StackListenerImpl
for (VariableDeclaration variable
in patternGuard.pattern.declaredVariables) {
declareVariable(variable, scope);
typeInferrer.assignedVariables.declare(variable);
}
Scope thenScope = scope.createNestedScope(
debugName: "then-control-flow", kind: ScopeKind.ifElement);
Expand Down Expand Up @@ -7281,7 +7370,6 @@ class BodyBuilder extends StackListenerImpl
for (VariableDeclaration variable in pattern.declaredVariables) {
variable.isFinal |= isFinal;
declareVariable(variable, scope);
typeInferrer.assignedVariables.declare(variable);
}
}

Expand Down Expand Up @@ -7957,7 +8045,6 @@ class BodyBuilder extends StackListenerImpl
if (pattern is Pattern) {
for (VariableDeclaration variable in pattern.declaredVariables) {
declareVariable(variable, scope);
typeInferrer.assignedVariables.declare(variable);
}
}
push(constantContext);
Expand Down Expand Up @@ -7998,7 +8085,6 @@ class BodyBuilder extends StackListenerImpl
if (pattern is Pattern) {
for (VariableDeclaration variable in pattern.declaredVariables) {
declareVariable(variable, scope);
typeInferrer.assignedVariables.declare(variable);
}
}
}
Expand Down Expand Up @@ -8277,7 +8363,6 @@ class BodyBuilder extends StackListenerImpl
if (pattern is Pattern) {
for (VariableDeclaration variable in pattern.declaredVariables) {
declareVariable(variable, scope);
typeInferrer.assignedVariables.declare(variable);
}
}
push(pattern);
Expand Down Expand Up @@ -9455,6 +9540,8 @@ class BodyBuilder extends StackListenerImpl
Modifier.validateVarFinalOrConst(keyword?.lexeme) == finalMask);
pattern = forest.createVariablePattern(
variable.charOffset, patternType, declaredVariable);
declareVariable(declaredVariable, scope);
typeInferrer.assignedVariables.declare(declaredVariable);
}
push(pattern);
}
Expand Down Expand Up @@ -9543,7 +9630,6 @@ class BodyBuilder extends StackListenerImpl
variable.isFinal = isFinal;
variable.hasDeclaredInitializer = true;
declareVariable(variable, scope);
typeInferrer.assignedVariables.declare(variable);
}
// TODO(johnniwinther,cstefantsova): Handle metadata.
pop(NullValues.Metadata) as List<Expression>?;
Expand Down
10 changes: 10 additions & 0 deletions pkg/front_end/lib/src/fasta/kernel/macro/annotation_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,11 @@ class _MacroListener implements Listener {
_unknown();
}

@override
void beginPattern(Token token) {
_unhandled();
}

@override
void beginPatternGuard(Token token) {
_unhandled();
Expand All @@ -2100,6 +2105,11 @@ class _MacroListener implements Listener {
_unsupported();
}

@override
void endPattern(Token token) {
_unhandled();
}

@override
void endPatternGuard(Token token) {
_unhandled();
Expand Down
11 changes: 11 additions & 0 deletions pkg/front_end/lib/src/fasta/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ enum ScopeKind {
/// should be visible in the scope of the function itself.
namedFunctionExpression,

/// The scope of the RHS of a binary-or pattern
///
/// It is utilized for separating the branch-local variables from the joint
/// variables of the overall binary-or pattern.
orPatternRight,

/// The scope of a pattern
///
/// It contains the variables associated with pattern variable declarations.
pattern,

/// Local scope of a statement, such as the body of a while loop
statementLocalScope,

Expand Down
Loading

0 comments on commit 87ab2d2

Please sign in to comment.