Introduce enum to quickly discriminate AST nodes.
RELNOTES: None.
PiperOrigin-RevId: 166370036
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Statement.java b/src/main/java/com/google/devtools/build/lib/syntax/Statement.java
index 58130b6..1795af1 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Statement.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Statement.java
@@ -20,6 +20,23 @@
public abstract class Statement extends ASTNode {
/**
+ * Kind of the statement. This is similar to using instanceof, except that it's more efficient and
+ * can be used in a switch/case.
+ */
+ public enum Kind {
+ ASSIGNMENT,
+ AUGMENTED_ASSIGNMENT,
+ CONDITIONAL,
+ EXPRESSION,
+ FLOW,
+ FOR,
+ FUNCTION_DEF,
+ IF,
+ LOAD,
+ RETURN,
+ }
+
+ /**
* Executes the statement in the specified build environment, which may be
* modified.
*
@@ -44,4 +61,10 @@
* @throws InterruptedException may be thrown in a sub class.
*/
abstract void doExec(Environment env) throws EvalException, InterruptedException;
+
+ /**
+ * Kind of the statement. This is similar to using instanceof, except that it's more efficient and
+ * can be used in a switch/case.
+ */
+ public abstract Kind kind();
}