From b5a3fbeca43054712a0bb75c918ffd515476eaba Mon Sep 17 00:00:00 2001 From: develar Date: Thu, 25 Oct 2012 10:17:03 +0400 Subject: [PATCH] simplify AST (idea like) --- .../google/dart/compiler/backend/js/ast/AbstractNode.java | 3 +-- src/com/google/dart/compiler/backend/js/ast/JsBlock.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsCatch.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsContinue.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsDebugger.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsEmpty.java | 2 +- .../dart/compiler/backend/js/ast/JsExpressionImpl.java | 5 +---- src/com/google/dart/compiler/backend/js/ast/JsFor.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsForIn.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsIf.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsLabel.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsParameter.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsProgram.java | 2 +- .../dart/compiler/backend/js/ast/JsProgramFragment.java | 2 +- .../dart/compiler/backend/js/ast/JsPropertyInitializer.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsReturn.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsSwitch.java | 2 +- .../google/dart/compiler/backend/js/ast/JsSwitchMember.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsThrow.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsTry.java | 2 +- src/com/google/dart/compiler/backend/js/ast/JsVars.java | 4 ++-- src/com/google/dart/compiler/backend/js/ast/JsWhile.java | 2 +- .../js/ast/{JsNodeImpl.java => SourceInfoAwareJsNode.java} | 5 +---- 23 files changed, 24 insertions(+), 31 deletions(-) rename src/com/google/dart/compiler/backend/js/ast/{JsNodeImpl.java => SourceInfoAwareJsNode.java} (80%) diff --git a/src/com/google/dart/compiler/backend/js/ast/AbstractNode.java b/src/com/google/dart/compiler/backend/js/ast/AbstractNode.java index 582b7ac1adb..d2d906be326 100644 --- a/src/com/google/dart/compiler/backend/js/ast/AbstractNode.java +++ b/src/com/google/dart/compiler/backend/js/ast/AbstractNode.java @@ -1,10 +1,9 @@ package com.google.dart.compiler.backend.js.ast; import com.google.dart.compiler.backend.js.JsToStringGenerationVisitor; -import com.google.dart.compiler.common.HasSourceInfo; import com.google.dart.compiler.util.TextOutputImpl; -abstract class AbstractNode implements JsNode, HasSourceInfo { +abstract class AbstractNode implements JsNode { @Override public String toString() { TextOutputImpl out = new TextOutputImpl(); diff --git a/src/com/google/dart/compiler/backend/js/ast/JsBlock.java b/src/com/google/dart/compiler/backend/js/ast/JsBlock.java index a6b133071f3..4538f88cf7a 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsBlock.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsBlock.java @@ -12,7 +12,7 @@ import java.util.List; /** * Represents a JavaScript block statement. */ -public class JsBlock extends JsNodeImpl implements JsStatement { +public class JsBlock extends SourceInfoAwareJsNode implements JsStatement { private final List statements; public JsBlock() { diff --git a/src/com/google/dart/compiler/backend/js/ast/JsCatch.java b/src/com/google/dart/compiler/backend/js/ast/JsCatch.java index 99f3bd11f3c..af1a322e0ee 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsCatch.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsCatch.java @@ -7,7 +7,7 @@ package com.google.dart.compiler.backend.js.ast; /** * Represents a JavaScript catch clause. */ -public class JsCatch extends JsNodeImpl implements HasCondition { +public class JsCatch extends SourceInfoAwareJsNode implements HasCondition { protected final JsCatchScope scope; private JsBlock body; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsContinue.java b/src/com/google/dart/compiler/backend/js/ast/JsContinue.java index 3b5b5fc8070..a3fd84cc43d 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsContinue.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsContinue.java @@ -6,7 +6,7 @@ package com.google.dart.compiler.backend.js.ast; import org.jetbrains.annotations.Nullable; -public class JsContinue extends JsNodeImpl implements JsStatement { +public class JsContinue extends SourceInfoAwareJsNode implements JsStatement { protected final String label; public JsContinue() { diff --git a/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java b/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java index 973bc5210dc..c27240a2468 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java @@ -7,7 +7,7 @@ package com.google.dart.compiler.backend.js.ast; /** * Represents a JavaScript debugger statement. */ -public class JsDebugger extends JsNodeImpl implements JsStatement { +public class JsDebugger extends SourceInfoAwareJsNode implements JsStatement { public JsDebugger() { } diff --git a/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java b/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java index 0835eaf3439..7298da8e4e9 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java @@ -4,7 +4,7 @@ package com.google.dart.compiler.backend.js.ast; -public class JsEmpty extends JsNodeImpl implements JsStatement { +public class JsEmpty extends SourceInfoAwareJsNode implements JsStatement { JsEmpty() { } diff --git a/src/com/google/dart/compiler/backend/js/ast/JsExpressionImpl.java b/src/com/google/dart/compiler/backend/js/ast/JsExpressionImpl.java index 8ae907a92ad..8dba62f3d04 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsExpressionImpl.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsExpressionImpl.java @@ -6,10 +6,7 @@ package com.google.dart.compiler.backend.js.ast; import java.util.List; -abstract class JsExpressionImpl extends JsNodeImpl implements JsExpression { - protected JsExpressionImpl() { - } - +abstract class JsExpressionImpl extends SourceInfoAwareJsNode implements JsExpression { /** * Determines whether or not this expression is a leaf, such as a * {@link JsNameRef}, {@link JsLiteral.JsBooleanLiteral}, and so on. Leaf expressions diff --git a/src/com/google/dart/compiler/backend/js/ast/JsFor.java b/src/com/google/dart/compiler/backend/js/ast/JsFor.java index 186bb056caa..1b582cca10e 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsFor.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsFor.java @@ -15,7 +15,7 @@ package com.google.dart.compiler.backend.js.ast; * Note that any of the parts of the for loop header can be * null, although the body will never be null. */ -public class JsFor extends JsNodeImpl implements JsStatement { +public class JsFor extends SourceInfoAwareJsNode implements JsStatement { private JsStatement body; private JsExpression condition; private JsExpression incrementExpression; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsForIn.java b/src/com/google/dart/compiler/backend/js/ast/JsForIn.java index 68bbc3155aa..bb06baceb9f 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsForIn.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsForIn.java @@ -4,7 +4,7 @@ package com.google.dart.compiler.backend.js.ast; -public class JsForIn extends JsNodeImpl implements JsStatement { +public class JsForIn extends SourceInfoAwareJsNode implements JsStatement { private JsStatement body; private JsExpression iterExpression; private JsExpression objectExpression; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsIf.java b/src/com/google/dart/compiler/backend/js/ast/JsIf.java index 344c2ec5352..f7ec9fb6196 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsIf.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsIf.java @@ -7,7 +7,7 @@ package com.google.dart.compiler.backend.js.ast; /** * Represents a JavaScript if statement. */ -public final class JsIf extends JsNodeImpl implements JsStatement { +public final class JsIf extends SourceInfoAwareJsNode implements JsStatement { private JsExpression ifExpression; private JsStatement thenStatement; private JsStatement elseStatement; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsLabel.java b/src/com/google/dart/compiler/backend/js/ast/JsLabel.java index 3f4fa2b11df..70966f7609c 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsLabel.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsLabel.java @@ -9,7 +9,7 @@ import com.google.dart.compiler.common.Symbol; /** * Represents a JavaScript label statement. */ -public class JsLabel extends JsNodeImpl implements JsStatement, HasName { +public class JsLabel extends SourceInfoAwareJsNode implements JsStatement, HasName { private final JsName label; private JsStatement statement; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsParameter.java b/src/com/google/dart/compiler/backend/js/ast/JsParameter.java index 1af5537ef7f..6080c39fda1 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsParameter.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsParameter.java @@ -9,7 +9,7 @@ import com.google.dart.compiler.common.Symbol; /** * A JavaScript parameter. */ -public final class JsParameter extends JsNodeImpl implements HasName { +public final class JsParameter extends SourceInfoAwareJsNode implements HasName { private final JsName name; public JsParameter(JsName name) { diff --git a/src/com/google/dart/compiler/backend/js/ast/JsProgram.java b/src/com/google/dart/compiler/backend/js/ast/JsProgram.java index 277c74a0b7c..a8f10523557 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsProgram.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsProgram.java @@ -17,7 +17,7 @@ import static com.google.dart.compiler.backend.js.ast.JsNumberLiteral.JsIntLiter /** * A JavaScript program. */ -public final class JsProgram extends JsNodeImpl { +public final class JsProgram extends SourceInfoAwareJsNode { private final JsEmpty emptyStatement; private JsProgramFragment[] fragments; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java b/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java index 0f684a581f4..61fde23eb8e 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java @@ -7,7 +7,7 @@ package com.google.dart.compiler.backend.js.ast; /** * One independently loadable fragment of a {@link JsProgram}. */ -public class JsProgramFragment extends JsNodeImpl { +public class JsProgramFragment extends SourceInfoAwareJsNode { private final JsGlobalBlock globalBlock; public JsProgramFragment() { diff --git a/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java b/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java index e756c47466a..47d040b7178 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java @@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull; /** * Used in object literals to specify property values by name. */ -public class JsPropertyInitializer extends JsNodeImpl { +public class JsPropertyInitializer extends SourceInfoAwareJsNode { private JsExpression labelExpr; private JsExpression valueExpr; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsReturn.java b/src/com/google/dart/compiler/backend/js/ast/JsReturn.java index 5f504488778..311f4532a5c 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsReturn.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsReturn.java @@ -7,7 +7,7 @@ package com.google.dart.compiler.backend.js.ast; /** * A JavaScript return statement. */ -public final class JsReturn extends JsNodeImpl implements JsStatement { +public final class JsReturn extends SourceInfoAwareJsNode implements JsStatement { private JsExpression expression; public JsReturn() { diff --git a/src/com/google/dart/compiler/backend/js/ast/JsSwitch.java b/src/com/google/dart/compiler/backend/js/ast/JsSwitch.java index fe83caabbf5..d9f379ddfef 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsSwitch.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsSwitch.java @@ -10,7 +10,7 @@ import java.util.List; /** * A JavaScript switch statement. */ -public class JsSwitch extends JsNodeImpl implements JsStatement { +public class JsSwitch extends SourceInfoAwareJsNode implements JsStatement { private final List cases = new ArrayList(); private JsExpression expression; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsSwitchMember.java b/src/com/google/dart/compiler/backend/js/ast/JsSwitchMember.java index 89b8ffdebba..8227c24c3cb 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsSwitchMember.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsSwitchMember.java @@ -11,7 +11,7 @@ import java.util.List; /** * A member/case in a JavaScript switch object. */ -public abstract class JsSwitchMember extends JsNodeImpl { +public abstract class JsSwitchMember extends SourceInfoAwareJsNode { protected final List statements = new SmartList(); protected JsSwitchMember() { diff --git a/src/com/google/dart/compiler/backend/js/ast/JsThrow.java b/src/com/google/dart/compiler/backend/js/ast/JsThrow.java index 69e7ee4a085..88dfd185ed1 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsThrow.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsThrow.java @@ -4,7 +4,7 @@ package com.google.dart.compiler.backend.js.ast; -public class JsThrow extends JsNodeImpl implements JsStatement { +public class JsThrow extends SourceInfoAwareJsNode implements JsStatement { private JsExpression expression; public JsThrow() { diff --git a/src/com/google/dart/compiler/backend/js/ast/JsTry.java b/src/com/google/dart/compiler/backend/js/ast/JsTry.java index d09fc842867..40f5e04f19e 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsTry.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsTry.java @@ -12,7 +12,7 @@ import java.util.List; /** * A JavaScript try statement. */ -public class JsTry extends JsNodeImpl implements JsStatement { +public class JsTry extends SourceInfoAwareJsNode implements JsStatement { private final List catches; private JsBlock finallyBlock; private JsBlock tryBlock; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsVars.java b/src/com/google/dart/compiler/backend/js/ast/JsVars.java index fb2f48551e1..1e72f4aeaa2 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsVars.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsVars.java @@ -16,7 +16,7 @@ import java.util.List; /** * A JavaScript var statement. */ -public class JsVars extends JsNodeImpl implements JsStatement, Iterable { +public class JsVars extends SourceInfoAwareJsNode implements JsStatement, Iterable { private final List vars; private final boolean multiline; @@ -49,7 +49,7 @@ public class JsVars extends JsNodeImpl implements JsStatement, Iterablevar statement. */ - public static class JsVar extends JsNodeImpl implements HasName { + public static class JsVar extends SourceInfoAwareJsNode implements HasName { private final JsName name; private JsExpression initExpression; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsWhile.java b/src/com/google/dart/compiler/backend/js/ast/JsWhile.java index 7f5a2a80abd..7b6d1f9fb58 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsWhile.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsWhile.java @@ -7,7 +7,7 @@ package com.google.dart.compiler.backend.js.ast; /** * A JavaScript while statement. */ -public class JsWhile extends JsNodeImpl implements JsStatement { +public class JsWhile extends SourceInfoAwareJsNode implements JsStatement { protected JsStatement body; protected JsExpression condition; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsNodeImpl.java b/src/com/google/dart/compiler/backend/js/ast/SourceInfoAwareJsNode.java similarity index 80% rename from src/com/google/dart/compiler/backend/js/ast/JsNodeImpl.java rename to src/com/google/dart/compiler/backend/js/ast/SourceInfoAwareJsNode.java index 83fe04c8936..d72ff609ad3 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsNodeImpl.java +++ b/src/com/google/dart/compiler/backend/js/ast/SourceInfoAwareJsNode.java @@ -1,11 +1,8 @@ package com.google.dart.compiler.backend.js.ast; -abstract class JsNodeImpl extends AbstractNode { +abstract class SourceInfoAwareJsNode extends AbstractNode { private Object sourceInfo; - protected JsNodeImpl() { - } - @Override public Object getSourceInfo() { return sourceInfo;