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

Unified Diff: pkg/analyzer2dart/lib/src/semantic_visitor.dart

Issue 609783002: Support static field access in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer2dart/lib/src/modely.dart ('k') | pkg/analyzer2dart/lib/src/tree_shaker.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer2dart/lib/src/semantic_visitor.dart
diff --git a/pkg/analyzer2dart/lib/src/semantic_visitor.dart b/pkg/analyzer2dart/lib/src/semantic_visitor.dart
new file mode 100644
index 0000000000000000000000000000000000000000..80edf47e3a80edef408c86c3c6c5e8f53ddcea6c
--- /dev/null
+++ b/pkg/analyzer2dart/lib/src/semantic_visitor.dart
@@ -0,0 +1,177 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library analyzer2dart.semantic_visitor;
+
+import 'package:analyzer/analyzer.dart';
+import 'package:analyzer/src/generated/source.dart';
+
+import 'util.dart';
+import 'package:analyzer2dart/src/identifier_semantics.dart';
+
+/// An AST visitor which uses the [AccessSemantics] of invocations and accesses
+/// to fine-grain visitor methods.
+abstract class SemanticVisitor<R> extends RecursiveAstVisitor<R> {
+
+ Source get currentSource;
+
+ void reportMessage(AstNode node, String message) {
+ reportSourceMessage(currentSource, node, message);
+ }
+
+ giveUp(AstNode node, String message) {
+ reportMessage(node, message);
+ throw new UnimplementedError(message);
+ }
+
+ bool invariant(AstNode node, condition, String message) {
+ if (condition is Function) {
+ condition = condition();
+ }
+ if (!condition) {
+ reportMessage(node, message);
+ throw new AssertionError();
+ }
+ return true;
+ }
+
+ R visitDynamicInvocation(MethodInvocation node,
+ AccessSemantics semantics) {
+ return giveUp(node, 'visitDynamicInvocation of $semantics');
+ }
+
+ R visitLocalFunctionInvocation(MethodInvocation node,
+ AccessSemantics semantics) {
+ return giveUp(node, 'visitLocalFunctionInvocation of $semantics');
+ }
+
+ R visitLocalVariableInvocation(MethodInvocation node,
+ AccessSemantics semantics) {
+ return giveUp(node, 'visitLocalVariableInvocation of $semantics');
+ }
+
+ R visitParameterInvocation(MethodInvocation node,
+ AccessSemantics semantics) {
+ return giveUp(node, 'visitParameterInvocation of $semantics');
+ }
+
+ R visitStaticFieldInvocation(MethodInvocation node,
+ AccessSemantics semantics) {
+ return giveUp(node, 'visitStaticFieldInvocation of $semantics');
+ }
+
+ R visitStaticMethodInvocation(MethodInvocation node,
+ AccessSemantics semantics) {
+ return giveUp(node, 'visitStaticMethodInvocation of $semantics');
+ }
+
+ R visitStaticPropertyInvocation(MethodInvocation node,
+ AccessSemantics semantics) {
+ return giveUp(node, 'visitStaticPropertyInvocation of $semantics');
+ }
+
+ @override
+ R visitMethodInvocation(MethodInvocation node) {
+ if (node.target != null) {
+ node.target.accept(this);
+ }
+ node.argumentList.accept(this);
+ AccessSemantics semantics = classifyMethodInvocation(node);
+ switch (semantics.kind) {
+ case AccessKind.DYNAMIC:
+ return visitDynamicInvocation(node, semantics);
+ case AccessKind.LOCAL_FUNCTION:
+ return visitLocalFunctionInvocation(node, semantics);
+ case AccessKind.LOCAL_VARIABLE:
+ return visitLocalVariableInvocation(node, semantics);
+ case AccessKind.PARAMETER:
+ return visitParameterInvocation(node, semantics);
+ case AccessKind.STATIC_FIELD:
+ return visitStaticFieldInvocation(node, semantics);
+ case AccessKind.STATIC_METHOD:
+ return visitStaticMethodInvocation(node, semantics);
+ case AccessKind.STATIC_PROPERTY:
+ return visitStaticPropertyInvocation(node, semantics);
+ default:
+ // Unexpected access kind.
+ return giveUp(node,
+ 'Unexpected ${semantics} in visitMethodInvocation.');
+ }
+ }
+
+ @override
+ R visitPropertyAccess(PropertyAccess node) {
+ if (node.target != null) {
+ node.target.accept(this);
+ }
+ return _handlePropertyAccess(node, classifyPropertyAccess(node));
+ }
+
+ @override
+ R visitPrefixedIdentifier(PrefixedIdentifier node) {
+ node.prefix.accept(this);
+ return _handlePropertyAccess(node, classifyPrefixedIdentifier(node));
+ }
+
+ @override
+ R visitSimpleIdentifier(SimpleIdentifier node) {
+ AccessSemantics semantics = classifySimpleIdentifier(node);
+ if (semantics != null) {
+ return _handlePropertyAccess(node, semantics);
+ } else {
+ return null;
+ }
+ }
+
+ R visitDynamicAccess(AstNode node, AccessSemantics semantics) {
+ return giveUp(node, 'visitDynamicAccess of $semantics');
+ }
+
+ R visitLocalFunctionAccess(AstNode node, AccessSemantics semantics) {
+ return giveUp(node, 'visitLocalFunctionAccess of $semantics');
+ }
+
+ R visitLocalVariableAccess(AstNode node, AccessSemantics semantics) {
+ return giveUp(node, 'visitLocalVariableAccess of $semantics');
+ }
+
+ R visitParameterAccess(AstNode node, AccessSemantics semantics) {
+ return giveUp(node, 'visitParameterAccess of $semantics');
+ }
+
+ R visitStaticFieldAccess(AstNode node, AccessSemantics semantics) {
+ return giveUp(node, 'visitStaticFieldAccess of $semantics');
+ }
+
+ R visitStaticMethodAccess(AstNode node, AccessSemantics semantics) {
+ return giveUp(node, 'visitStaticMethodAccess of $semantics');
+ }
+
+ R visitStaticPropertyAccess(AstNode node, AccessSemantics semantics) {
+ return giveUp(node, 'visitStaticPropertyAccess of $semantics');
+ }
+
+ R _handlePropertyAccess(AstNode node, AccessSemantics semantics) {
+ switch (semantics.kind) {
+ case AccessKind.DYNAMIC:
+ return visitDynamicAccess(node, semantics);
+ case AccessKind.LOCAL_FUNCTION:
+ return visitLocalFunctionAccess(node, semantics);
+ case AccessKind.LOCAL_VARIABLE:
+ return visitLocalVariableAccess(node, semantics);
+ case AccessKind.PARAMETER:
+ return visitParameterAccess(node, semantics);
+ case AccessKind.STATIC_FIELD:
+ return visitStaticFieldAccess(node, semantics);
+ case AccessKind.STATIC_METHOD:
+ return visitStaticMethodAccess(node, semantics);
+ case AccessKind.STATIC_PROPERTY:
+ return visitStaticPropertyAccess(node, semantics);
+ default:
+ // Unexpected access kind.
+ return giveUp(node,
+ 'Unexpected ${semantics} in _handlePropertyAccess.');
+ }
+ }
+}
« no previous file with comments | « pkg/analyzer2dart/lib/src/modely.dart ('k') | pkg/analyzer2dart/lib/src/tree_shaker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698