Commit Graph

482 Commits

Author SHA1 Message Date
Paul Berry ae6fd961a1 Prepare for decoupling analyzer ASTs from element model.
This CL creates top level accessor functions which may be used to map from AST data structures to their corresponding elements and types, and begins using those accessor functions throughout the SDK.  It also adds empty interfaces ResolutionTarget and ResolutionType, which are implemented by Element and DartType respectively.

In a future CL, I will change the types stored in the AST to ResolutionTarget and ResolutionType, rather than specific element types; this will decouple the ASTs from the element model.  The presence of the accessor functions will allow clients to continue accessing elements and types in a type-safe way.

R=asgerf@google.com, brianwilkerson@google.com, scheglov@google.com, vsm@google.com

Review URL: https://codereview.chromium.org/2551023005 .
2016-12-07 11:08:14 -08:00
Andrew Lorenzen c9d7a5a5c8 Make Element.accept() generic. (#27690)
* Make Element.accept() generic.

* Update subclasses of Element.
2016-12-06 20:42:00 +01:00
Paul Berry c4f50f53cb Remove old AST factory constructors from analyzer.
This reapplies the remainder of
1d028eed8d (which was reverted due to
conflicts with dev_compiler), since dev_compiler has now been fixed to
use analyzer's new astFactory.

R=brianwilkerson@google.com, scheglov@google.com

Review URL: https://codereview.chromium.org/2549613002 .
2016-12-01 11:17:10 -08:00
Vijay Menon b8d3758dcd Revert "Transition analyzer and analysis_server to new astFactory; remove old AST factory methods."
This reverts commit 1d028eed8d.

This was breaking DDC.

TBR=paulberry@google.com

Review URL: https://codereview.chromium.org/2542753002 .
2016-11-30 14:57:49 -08:00
Paul Berry 1d028eed8d Transition analyzer and analysis_server to new astFactory; remove old AST factory methods.
R=brianwilkerson@google.com, scheglov@google.com

Review URL: https://codereview.chromium.org/2539243002 .
2016-11-30 12:28:51 -08:00
Paul Berry be11197a6c Consolidate AST element/type interfaces.
The AST getters/setters for `bestElement`, `propagatedElement`, and
`staticElement` having type `MethodElement` are moved to a common
interface class, `MethodReferenceExpression`.

The AST getters/setters for `staticElement` having type
`ConstructorElement` are moved to a common interface class,
`ConstructorReferenceNode`.

The overrides for `propagatedInvokeType` and `staticInvokeType` are
removed from `FunctionExpressionInvocation` and `MethodInvocation`,
since these overrides are identical to the corresponding declarations
in the base class, `InvocationExpression`.

R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/2536253002 .
2016-11-29 10:11:35 -08:00
Paul Berry f4baeb20d7 Create a new AstFactory class to be used by analyzer and its clients.
Unlike the previous AstFactory (now called AstTestFactory), this class
is not just for testing; it is intended to be able to create all
analyzer AST objects used in production.  Also, its methods are
non-static.

For now, all users of the new AstFactory access it using the final
variable `astFactory` in standard_ast_factory.dart.  In future CLs I
intend to plumb a reference to the AstFactory through various analyzer
classes so that it can be used in a dependency injection style.

Also, the classes CommentType and UriValidationCodeImpl have been
moved out of the AST implementation file
(pkg/analyzer/lib/src/dart/ast/ast.dart) and to their own files so
that the AST interface will be able to continue to use them without
depending on the AST implementation.

In follow-up CLs I will change the analyzer and its clients to use the
AstFactory rather than the redirecting constructors in the AST
interface file, and then remove those redirecting constructors.

R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/2522143003 .
2016-11-28 10:50:20 -08:00
Brian Wilkerson b923dafd25 Add parser support for using a URI in a part-of directive
R=scheglov@google.com

Review URL: https://codereview.chromium.org/2526063002 .
2016-11-25 08:16:45 -08:00
Paul Berry 4cd9b28eb6 Create pkg/front_end/src/base and begin populating with general use classes.
In the long run, pkg/front_end/src/base is intended to contain code
that is useful to many components of the front end.

In this initial implementation, it contains:
- Source and the classes it references
- ErrorCode, ErrorSeverity, and ErrorType
- SyntacticEntity

Note that AnalysisTarget is included (even though strictly speaking it
is part of the analyzer task model) because it was too hard to
disentangle from Source.

Note that Token classes remain in pkg/front_end/src/scanner for now; I
plan to reorganize them at the time the parser is moved into the front
end.

R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/2486923007 .
2016-11-14 09:20:18 -08:00
Brian Wilkerson c7eab6ba06 Enhance generalizing visitor to allow visiting an invocation expression
R=scheglov@google.com

Review URL: https://codereview.chromium.org/2490703004 .
2016-11-10 09:50:46 -08:00
Brian Wilkerson 3c437f5d9e Create AST structure for asserts in constructor initializers
R=scheglov@google.com

Review URL: https://codereview.chromium.org/2492633002 .
2016-11-10 09:00:18 -08:00
Paul Berry 0a1fb8d248 Move scanner into pkg/front_end/lib/src/scanner.
Several support classes also had to move to front_end along with the
scanner.  Some of these support classes arguably don't belong to the
scanner itself, since they have other uses (e.g. SyntacticEntity,
ErrorCode, ErrorSeverity, ErrorType, and StringUtilities).  They will
be reorganized into a more appropriate location in future CLs, at the
time that they become needed by other components of the front end.

In order to avoid dragging in a lot of dependencies, the following
changes were made:

1. Scanner no longer reports errors through Source and
AnalysisErrorListener objects passed to the constructor.  Instead, it
provides an abstract reportError() method which clients may override
to perform error reporting in any way they wish.  Analyzer contains an
override of Scanner that mimics the old behavior in order to maintain
compatibility.

2. Static members of ErrorCode (`values` and `byUniqueName`) have been
moved to top level, and remain in analyzer.  To maintain
compatibility, these static members remain in ErrorCode (as deprecated
members that simply wrap the implementations in analyzer).  This means
we have a reverse dependency (front_end depends on analyzer), but this
dependency will go away as soon as we publish the next breaking change
release of analyzer.

R=brianwilkerson@google.com, scheglov@google.com

Review URL: https://codereview.chromium.org/2486873003 .
2016-11-08 13:47:17 -08:00
Jennifer Messerly 4213059b74 fix #27040, promote the upper bound of a type parameter
also fixes #27210, by cleaning up TypeParameterMember equality TODO.

R=leafp@google.com

Review URL: https://codereview.chromium.org/2375373002 .
2016-11-01 18:14:59 -07:00
Brian Wilkerson 6446cab391 Guard against exceptions thrown by linters (issue 27545)
R=scheglov@google.com

Review URL: https://codereview.chromium.org/2407553002 .
2016-10-07 14:37:39 -07:00
Brian Wilkerson f87e62ef14 Convert subclasses of Enum
R=scheglov@google.com

Review URL: https://codereview.chromium.org/2365553004 .
2016-09-23 06:54:26 -07:00
Paul Berry dac96d0584 Add SyntacticEntity, an interface shared by AstNode and Token.
This allows types to be tightened up for AstNode.childEntities.

R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/2357803002 .
2016-09-21 11:23:46 -07:00
John Messerly 865e808f15 support @virtual fields, fix #27384
R=leafp@google.com

Review URL: https://codereview.chromium.org/2352433002 .
2016-09-19 09:45:24 -07:00
Konstantin Shcheglov 54ee2b88c8 ImportElement/ExportElement 'uri' should be the selected URI.
So, that the URI is consistent with the imported/exportedLibrary.

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org/2343103003 .
2016-09-17 17:26:13 -07:00
Brian Wilkerson 772c93ccf2 Rename libraryUri
R=scheglov@google.com

Review URL: https://codereview.chromium.org/2347213002 .
2016-09-16 10:54:25 -07:00
Brian Wilkerson 7eb7573dc4 Initial support for the NNBD proposal
R=scheglov@google.com

Review URL: https://codereview.chromium.org/2342383002 .
2016-09-16 10:51:19 -07:00
Brian Wilkerson 22040876bf Use declared variables to select the correct configuration for resolution
R=paulberry@google.com, scheglov@google.com

Review URL: https://codereview.chromium.org/2345773003 .
2016-09-16 07:32:40 -07:00
John Messerly 28247a3daa fix #25578, implement @covariant parameter overrides
R=leafp@google.com

Review URL: https://codereview.chromium.org/2336503003 .
2016-09-13 14:57:22 -07:00
Konstantin Shcheglov 8c1d5a3b56 Remove LibraryElement.visibleLibraries.
It is not used now.
The only other is smoke, and its only in test, and it is actually
used incorrectly there.

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org/2336913002 .
2016-09-13 07:45:53 -07:00
Konstantin Shcheglov 4e95a1b8b6 Remove LibraryElement.isUpToDate().
It is not used anywhere.

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org/2335843003 .
2016-09-12 15:03:58 -07:00
Konstantin Shcheglov 663a3e810c Reapply abc5051854: Remove 'Element.docRange'.
I also marked the corresponding information in summaries as @deprecated
and made a small tweak to the generator so that it knows that the ids
of deprecated fields are still used.

R=brianwilkerson@google.com, paulberry@google.com
BUG=

Review URL: https://codereview.chromium.org/2330813002 .
2016-09-11 09:41:53 -07:00
pq b7f0ce083b Revert "Remove 'Element.docRange'."
This reverts commit abc5051854.

Background: required to keep `analyzer` version-compatible with `test`.

BUG=
R=brianwilkerson@google.com, scheglov@google.com

Review URL: https://codereview.chromium.org/2293143003 .
2016-08-30 13:10:15 -07:00
Konstantin Shcheglov abc5051854 Remove 'Element.docRange'.
I also marked the corresponding information in summaries as @deprecated
and made a small tweak to the generator so that it knows that the ids
of deprecated fields are still used.

R=brianwilkerson@google.com, paulberry@google.com
BUG=

Review URL: https://codereview.chromium.org/2270903002 .
2016-08-24 09:40:23 -07:00
Paul Berry 052a6c867d Fix summary handling of unresolved imports, exports, and parts.
Previously this was working for a few use cases by dumb luck, but it
wasn't well tested and became broken by
b29c6bf330.  This CL fixes it for real
and adds tests to verify the fix.

Note that there is a change to how we represent an unresolved
import/export: instead of storing a URI_EXISTS modifier in the element
model, we simply mark the imported library element as synthetic.
(This library element existed anyway; we just weren't marking it as
synthetic).  This makes it easy to tie in with summaries, since it is
easy for the resynthesizer to detect that the library doesn't exist at
the time the library handle is resolved.

R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/2235373003 .
2016-08-12 13:59:51 -07:00
Brian Wilkerson b29c6bf330 Suppress follow-on errors when a file is imported with either a prefix or a show clause
R=scheglov@google.com

Review URL: https://codereview.chromium.org/2226613004 .
2016-08-09 11:11:39 -07:00
Brian Wilkerson 4dcb9b6196 Initial implementation for lazy compound assignment operators
R=scheglov@google.com

Review URL: https://codereview.chromium.org/2199323002 .
2016-08-02 09:16:17 -07:00
pq f4c2a0faba Analyzer support for @factory methods (linter#253).
R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/2096103002 .

Fixes: https://github.com/dart-lang/linter/issues/253.
2016-06-24 14:41:00 -07:00
pq c07b21d03b Dangling comment reference cleanup in analyzer.
First pass with the new `comment_reference` lint.

BUG=
R=scheglov@google.com

Review URL: https://codereview.chromium.org/1994243002 .
2016-05-19 10:24:53 -07:00
Brian Wilkerson 3024554b3c Improve type information and minor clean up
R=scheglov@google.com

Review URL: https://codereview.chromium.org/1977413002 .
2016-05-16 08:43:58 -07:00
Brian Wilkerson f2356d0d33 Add API to force the computation of constant values
R=scheglov@google.com

Review URL: https://codereview.chromium.org/1966323002 .
2016-05-12 07:37:08 -07:00
Konstantin Shcheglov 76f73c38cc Add 'ParameterizedType get type' to TypeParameterizedElement.
R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org/1968543002 .
2016-05-10 11:07:09 -07:00
Brian Wilkerson 61818c95a1 Convert some for-in loops for performance
R=scheglov@google.com

Review URL: https://codereview.chromium.org/1955373003 .
2016-05-09 11:01:16 -07:00
Brian Wilkerson 91e2852659 Remove cast from AstNodeImpl._becomeParentOf
R=scheglov@google.com

Review URL: https://codereview.chromium.org/1939853002 .
2016-05-02 10:21:33 -07:00
Brian Wilkerson 24d23680d1 Use null-aware operators to clean up the code
R=scheglov@google.com

Review URL: https://codereview.chromium.org/1933763002 .
2016-04-29 08:48:12 -07:00
Brian Wilkerson ee8bb2cea9 Add a (public) utility method to clean-up code
R=scheglov@google.com

Review URL: https://codereview.chromium.org/1925173002 .
2016-04-28 10:07:32 -07:00
Konstantin Shcheglov 305f1f538c Pull the 'keyword' property into Token.
So, we can use it without casting to KeywordToken.
This gives small, but noticable performanace boost, about 4% on hot VM.

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org/1909843002 .
2016-04-21 08:23:49 -07:00
pq ac48484a07 Support for @JS() validation (#26225).
See: https://github.com/dart-lang/sdk/issues/26225

BUG=
R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/1871103002 .
2016-04-08 13:45:46 -07:00
pq 6a430d0730 Validation of @required params (#26182).
See: https://github.com/dart-lang/sdk/issues/26182.

BUG=
R=brianwilkerson@google.com, scheglov@google.com

Review URL: https://codereview.chromium.org/1863803002 .
2016-04-06 06:09:44 -07:00
Brian Wilkerson 513433d514 Sort analyzer sources
R=scheglov@google.com

Review URL: https://codereview.chromium.org/1843473002 .
2016-03-28 17:41:52 -07:00
Bob Nystrom 31aa8e26df Distinguish SimpleIdentifier uses and declarations at parse time.
Instead of a very slow .inDeclarationContext() method which determines
whether a given identifier is in a use position or not, we just create
a different subclass at parse time that encodes that fact directly.

Also, remove an unnecessary _validateElement() method.

On my Mac laptop, this takes benchmark/errors_in_all_libraries.dart

From: 0:00:05.673849
To:   0:00:05.193563 (91.53%)

R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/1833573006 .
2016-03-25 10:38:22 -07:00
Brian Wilkerson 5309d86424 First batch of changes to make analyzer package strong mode error free
Review URL: https://codereview.chromium.org/1808123005 .
2016-03-18 07:47:58 -07:00
Brian Wilkerson 50c9131702 Move DartObject into the public API
R=scheglov@google.com

Review URL: https://codereview.chromium.org/1809013003 .
2016-03-18 07:41:58 -07:00
pq 9a042501c9 Timing hooks to profile linters (#24548).
Adds a `TimedAstVisitor` that wraps and times base visitors.  The perf hit for collecting timing was neglible so I opted to NOT surface a way to not collect the data.  We can add that if needed.

Once this is published in a new analyzer, I can bake client support into (for example) the linter.

More context and a client mock here: https://github.com/dart-lang/sdk/issues/24548

BUG=
R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/1807723002 .
2016-03-15 16:10:35 -07:00
pq 4528052e98 Validation of @mustCallSuper overrides.
Carried over and refined from https://codereview.chromium.org/1767843002/.

BUG=
R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org/1773803002 .
2016-03-07 13:37:35 -08:00
Leaf Petersen 7d2976c7d5 Add instantiate method on ParameterizedType and InterfaceType,
and deprecate the old substitute4 in favor of instantiate.

BUG=
R=brianwilkerson@google.com, jmesserly@google.com

Review URL: https://codereview.chromium.org/1758913002 .
2016-03-02 15:06:38 -08:00
pq 9ea17184ad Add @overrides to (a lot of) analyzer.
This gets us roughly half+ way there.  We should defintely consider automating this to speed up the rest.  (Even with the quick-fix it's VERY tedious and slow going.)

Once we've done this in bulk, I'd like to add the  `annotate_overrides` lint to analyzer and server `.analysis_options`.

BUG=
R=brianwilkerson@google.com, scheglov@google.com

Review URL: https://codereview.chromium.org/1749143003 .
2016-03-01 16:33:20 -08:00