mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
Introduce AstFactory.compilationUnit2 with a required featureSet argument.
Change-Id: I8d709fcb9be1b3a89e617a0c7b35f47813787f06 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99966 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
3d0825da5d
commit
37f915543f
10 changed files with 99 additions and 46 deletions
|
@ -1,3 +1,9 @@
|
|||
## (not yet released)
|
||||
* Deprecated `AstFactory.compilationUnit`. In a future analyzer release, this
|
||||
method will be changed so that all its parameters are named parameters.
|
||||
Clients wishing to prepare for this should switch to using
|
||||
`AstFactory.compilationUnit2`.
|
||||
|
||||
## 0.36.2
|
||||
* Bug fixes: #36724.
|
||||
|
||||
|
|
|
@ -156,6 +156,7 @@ abstract class AstFactory {
|
|||
/// in the compilation unit. The list of [directives] can be `null` if there
|
||||
/// are no directives in the compilation unit. The list of [declarations] can
|
||||
/// be `null` if there are no declarations in the compilation unit.
|
||||
@Deprecated('Use compilationUnit2')
|
||||
CompilationUnit compilationUnit(
|
||||
Token beginToken,
|
||||
ScriptTag scriptTag,
|
||||
|
@ -164,6 +165,22 @@ abstract class AstFactory {
|
|||
Token endToken,
|
||||
[FeatureSet featureSet]);
|
||||
|
||||
/// Returns a newly created compilation unit to have the given directives and
|
||||
/// declarations. The [scriptTag] can be `null` (or omitted) if there is no
|
||||
/// script tag in the compilation unit. The list of [declarations] can be
|
||||
/// `null` (or omitted) if there are no directives in the compilation unit.
|
||||
/// The list of `declarations` can be `null` (or omitted) if there are no
|
||||
/// declarations in the compilation unit. The [featureSet] can be `null` if
|
||||
/// the set of features for this compilation unit is not known (this
|
||||
/// restricts what analysis can be done of the compilation unit).
|
||||
CompilationUnit compilationUnit2(
|
||||
{@required Token beginToken,
|
||||
ScriptTag scriptTag,
|
||||
List<Directive> directives,
|
||||
List<CompilationUnitMember> declarations,
|
||||
@required Token endToken,
|
||||
@required FeatureSet featureSet});
|
||||
|
||||
/// Returns a newly created conditional expression.
|
||||
ConditionalExpression conditionalExpression(
|
||||
Expression condition,
|
||||
|
|
|
@ -654,7 +654,8 @@ class FileState {
|
|||
|
||||
CompilationUnit _createEmptyCompilationUnit(FeatureSet featureSet) {
|
||||
var token = new Token.eof(0);
|
||||
return astFactory.compilationUnit(token, null, [], [], token, featureSet)
|
||||
return astFactory.compilationUnit2(
|
||||
beginToken: token, endToken: token, featureSet: featureSet)
|
||||
..lineInfo = new LineInfo(const <int>[0]);
|
||||
}
|
||||
|
||||
|
|
|
@ -179,6 +179,7 @@ class AstFactoryImpl extends AstFactory {
|
|||
new CommentReferenceImpl(newKeyword, identifier);
|
||||
|
||||
@override
|
||||
@deprecated
|
||||
CompilationUnit compilationUnit(
|
||||
Token beginToken,
|
||||
ScriptTag scriptTag,
|
||||
|
@ -189,6 +190,17 @@ class AstFactoryImpl extends AstFactory {
|
|||
new CompilationUnitImpl(beginToken, scriptTag, directives, declarations,
|
||||
endToken, featureSet);
|
||||
|
||||
@override
|
||||
CompilationUnit compilationUnit2(
|
||||
{Token beginToken,
|
||||
ScriptTag scriptTag,
|
||||
List<Directive> directives,
|
||||
List<CompilationUnitMember> declarations,
|
||||
Token endToken,
|
||||
FeatureSet featureSet}) =>
|
||||
new CompilationUnitImpl(beginToken, scriptTag, directives, declarations,
|
||||
endToken, featureSet);
|
||||
|
||||
@override
|
||||
ConditionalExpression conditionalExpression(
|
||||
Expression condition,
|
||||
|
|
|
@ -285,13 +285,13 @@ class AstCloner
|
|||
|
||||
@override
|
||||
CompilationUnit visitCompilationUnit(CompilationUnit node) {
|
||||
CompilationUnit clone = astFactory.compilationUnit(
|
||||
cloneToken(node.beginToken),
|
||||
cloneNode(node.scriptTag),
|
||||
cloneNodeList(node.directives),
|
||||
cloneNodeList(node.declarations),
|
||||
cloneToken(node.endToken),
|
||||
node.featureSet);
|
||||
CompilationUnit clone = astFactory.compilationUnit2(
|
||||
beginToken: cloneToken(node.beginToken),
|
||||
scriptTag: cloneNode(node.scriptTag),
|
||||
directives: cloneNodeList(node.directives),
|
||||
declarations: cloneNodeList(node.declarations),
|
||||
endToken: cloneToken(node.endToken),
|
||||
featureSet: node.featureSet);
|
||||
clone.lineInfo = node.lineInfo;
|
||||
return clone;
|
||||
}
|
||||
|
@ -2643,13 +2643,13 @@ class IncrementalAstCloner
|
|||
|
||||
@override
|
||||
CompilationUnit visitCompilationUnit(CompilationUnit node) {
|
||||
CompilationUnitImpl copy = astFactory.compilationUnit(
|
||||
_mapToken(node.beginToken),
|
||||
_cloneNode(node.scriptTag),
|
||||
_cloneNodeList(node.directives),
|
||||
_cloneNodeList(node.declarations),
|
||||
_mapToken(node.endToken),
|
||||
node.featureSet);
|
||||
CompilationUnitImpl copy = astFactory.compilationUnit2(
|
||||
beginToken: _mapToken(node.beginToken),
|
||||
scriptTag: _cloneNode(node.scriptTag),
|
||||
directives: _cloneNodeList(node.directives),
|
||||
declarations: _cloneNodeList(node.declarations),
|
||||
endToken: _mapToken(node.endToken),
|
||||
featureSet: node.featureSet);
|
||||
copy.lineInfo = node.lineInfo;
|
||||
copy.declaredElement = node.declaredElement;
|
||||
return copy;
|
||||
|
|
|
@ -506,8 +506,13 @@ class AstBuilder extends StackListener {
|
|||
Token beginToken = pop();
|
||||
checkEmpty(endToken.charOffset);
|
||||
|
||||
CompilationUnitImpl unit = ast.compilationUnit(beginToken, scriptTag,
|
||||
directives, declarations, endToken, _featureSet) as CompilationUnitImpl;
|
||||
CompilationUnitImpl unit = ast.compilationUnit2(
|
||||
beginToken: beginToken,
|
||||
scriptTag: scriptTag,
|
||||
directives: directives,
|
||||
declarations: declarations,
|
||||
endToken: endToken,
|
||||
featureSet: _featureSet) as CompilationUnitImpl;
|
||||
unit.languageVersion = languageVersion;
|
||||
unit.isNonNullable = enableNonNullable;
|
||||
push(unit);
|
||||
|
|
|
@ -1936,8 +1936,8 @@ class Parser {
|
|||
} on _TooDeepTreeError {
|
||||
_reportErrorForToken(ParserErrorCode.STACK_OVERFLOW, _currentToken);
|
||||
Token eof = new Token.eof(0);
|
||||
return astFactory.compilationUnit(
|
||||
eof, null, null, null, eof, _featureSet);
|
||||
return astFactory.compilationUnit2(
|
||||
beginToken: eof, endToken: eof, featureSet: _featureSet);
|
||||
}
|
||||
if (member != null) {
|
||||
declarations.add(member);
|
||||
|
@ -1986,8 +1986,13 @@ class Parser {
|
|||
// }
|
||||
}
|
||||
}
|
||||
return astFactory.compilationUnit(firstToken, scriptTag, directives,
|
||||
declarations, _currentToken, _featureSet);
|
||||
return astFactory.compilationUnit2(
|
||||
beginToken: firstToken,
|
||||
scriptTag: scriptTag,
|
||||
directives: directives,
|
||||
declarations: declarations,
|
||||
endToken: _currentToken,
|
||||
featureSet: _featureSet);
|
||||
}
|
||||
|
||||
/// Parse a compilation unit member. The [commentAndMetadata] is the metadata
|
||||
|
@ -2437,12 +2442,20 @@ class Parser {
|
|||
while (!_matches(TokenType.EOF)) {
|
||||
_advance();
|
||||
}
|
||||
return astFactory.compilationUnit(firstToken, scriptTag, directives,
|
||||
null, _currentToken, _featureSet);
|
||||
return astFactory.compilationUnit2(
|
||||
beginToken: firstToken,
|
||||
scriptTag: scriptTag,
|
||||
directives: directives,
|
||||
endToken: _currentToken,
|
||||
featureSet: _featureSet);
|
||||
}
|
||||
}
|
||||
return astFactory.compilationUnit(
|
||||
firstToken, scriptTag, directives, null, _currentToken, _featureSet);
|
||||
return astFactory.compilationUnit2(
|
||||
beginToken: firstToken,
|
||||
scriptTag: scriptTag,
|
||||
directives: directives,
|
||||
endToken: _currentToken,
|
||||
featureSet: _featureSet);
|
||||
}
|
||||
|
||||
/// Parse a documentation comment based on the given list of documentation
|
||||
|
|
|
@ -275,15 +275,16 @@ class AstTestFactory {
|
|||
String scriptTag,
|
||||
List<Directive> directives,
|
||||
List<CompilationUnitMember> declarations) =>
|
||||
astFactory.compilationUnit(
|
||||
TokenFactory.tokenFromType(TokenType.EOF),
|
||||
scriptTag == null ? null : AstTestFactory.scriptTag(scriptTag),
|
||||
directives == null ? new List<Directive>() : directives,
|
||||
declarations == null
|
||||
astFactory.compilationUnit2(
|
||||
beginToken: TokenFactory.tokenFromType(TokenType.EOF),
|
||||
scriptTag:
|
||||
scriptTag == null ? null : AstTestFactory.scriptTag(scriptTag),
|
||||
directives: directives == null ? new List<Directive>() : directives,
|
||||
declarations: declarations == null
|
||||
? new List<CompilationUnitMember>()
|
||||
: declarations,
|
||||
TokenFactory.tokenFromType(TokenType.EOF),
|
||||
null);
|
||||
endToken: TokenFactory.tokenFromType(TokenType.EOF),
|
||||
featureSet: null);
|
||||
|
||||
static ConditionalExpression conditionalExpression(Expression condition,
|
||||
Expression thenExpression, Expression elseExpression) =>
|
||||
|
|
|
@ -278,13 +278,13 @@ class AstBinaryReader {
|
|||
}
|
||||
|
||||
CompilationUnit _read_compilationUnit(LinkedNode data) {
|
||||
return astFactory.compilationUnit(
|
||||
_getToken(data.compilationUnit_beginToken),
|
||||
_readNode(data.compilationUnit_scriptTag),
|
||||
_readNodeList(data.compilationUnit_directives),
|
||||
_readNodeList(data.compilationUnit_declarations),
|
||||
_getToken(data.compilationUnit_endToken),
|
||||
null);
|
||||
return astFactory.compilationUnit2(
|
||||
beginToken: _getToken(data.compilationUnit_beginToken),
|
||||
scriptTag: _readNode(data.compilationUnit_scriptTag),
|
||||
directives: _readNodeList(data.compilationUnit_directives),
|
||||
declarations: _readNodeList(data.compilationUnit_declarations),
|
||||
endToken: _getToken(data.compilationUnit_endToken),
|
||||
featureSet: null);
|
||||
}
|
||||
|
||||
ConditionalExpression _read_conditionalExpression(LinkedNode data) {
|
||||
|
|
|
@ -274,13 +274,11 @@ class C {
|
|||
null,
|
||||
AstTestFactory.typeName4('int'),
|
||||
[AstTestFactory.variableDeclaration('V')]);
|
||||
CompilationUnit unit = astFactory.compilationUnit(
|
||||
topLevelVariableDeclaration.beginToken,
|
||||
null,
|
||||
[],
|
||||
[topLevelVariableDeclaration],
|
||||
topLevelVariableDeclaration.endToken,
|
||||
null);
|
||||
CompilationUnit unit = astFactory.compilationUnit2(
|
||||
beginToken: topLevelVariableDeclaration.beginToken,
|
||||
declarations: [topLevelVariableDeclaration],
|
||||
endToken: topLevelVariableDeclaration.endToken,
|
||||
featureSet: null);
|
||||
ElementHolder holder = new ElementHolder();
|
||||
ElementBuilder builder = _makeBuilder(holder);
|
||||
unit.beginToken.offset = 10;
|
||||
|
|
Loading…
Reference in a new issue