From d3a8f78a8855049ba972206de622c7af9fbd7959 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Thu, 2 Oct 2014 14:48:36 +0400 Subject: [PATCH] JS inline minor: moved JsInliningContext definition to the bottom of JsInliner --- .../org/jetbrains/k2js/inline/JsInliner.java | 134 +++++++----------- 1 file changed, 53 insertions(+), 81 deletions(-) diff --git a/js/js.inliner/src/org/jetbrains/k2js/inline/JsInliner.java b/js/js.inliner/src/org/jetbrains/k2js/inline/JsInliner.java index 0dcffa9a80e..d24cc1ccb8b 100644 --- a/js/js.inliner/src/org/jetbrains/k2js/inline/JsInliner.java +++ b/js/js.inliner/src/org/jetbrains/k2js/inline/JsInliner.java @@ -33,87 +33,6 @@ import static org.jetbrains.k2js.inline.util.UtilPackage.IdentitySet; public class JsInliner extends JsVisitorWithContextImpl { - private class JsInliningContext implements InliningContext { - private final FunctionContext functionContext; - - JsInliningContext(JsFunction function) { - functionContext = new FunctionContext(function, this) { - @Nullable - @Override - protected JsFunction lookUpStaticFunction(@Nullable JsName functionName) { - return functions.get(functionName); - } - }; - } - - @NotNull - @Override - public RenamingContext getRenamingContext() { - return new RenamingContext(getFunctionContext().getScope()); - } - - @NotNull - @Override - public StatementContext getStatementContext() { - return new StatementContext() { - @NotNull - @Override - public JsContext getCurrentStatementContext() { - return getLastStatementLevelContext(); - } - - @NotNull - @Override - protected JsStatement getEmptyStatement() { - return getFunctionContext().getEmpty(); - } - - @Override - public void shiftCurrentStatementForward() { - super.shiftCurrentStatementForward(); - lastStatementWasShifted = true; - } - }; - } - - @NotNull - @Override - public FunctionContext getFunctionContext() { - return functionContext; - } - - @NotNull - @Override - public JsExpression getThisReplacement(JsInvocation call) { - if (InvocationUtil.isCallInvocation(call)) { - return call.getArguments().get(0); - } - - if (InvocationUtil.hasReceiver(call)) { - return InvocationUtil.getReceiver(call); - } - - return JsLiteral.THIS; - } - - @NotNull - @Override - public List getArguments(JsInvocation call) { - List arguments = call.getArguments(); - if (InvocationUtil.isCallInvocation(call)) { - return arguments.subList(1, arguments.size()); - } - - return arguments; - } - - @Override - public boolean isResultNeeded(JsInvocation call) { - JsStatement currentStatement = getStatementContext().getCurrentStatement(); - return InvocationUtil.isResultUsed(currentStatement, call); - } - } - private final IdentityHashMap functions; private final Stack inliningContexts = new Stack(); private final Set processedFunctions = IdentitySet(); @@ -265,4 +184,57 @@ public class JsInliner extends JsVisitorWithContextImpl { private static boolean shouldInline(@NotNull JsInvocation call) { return call.getInlineStrategy().isInline(); } + + + private class JsInliningContext implements InliningContext { + private final FunctionContext functionContext; + + JsInliningContext(JsFunction function) { + functionContext = new FunctionContext(function, this) { + @Nullable + @Override + protected JsFunction lookUpStaticFunction(@Nullable JsName functionName) { + return functions.get(functionName); + } + }; + } + + @NotNull + @Override + public NamingContext newNamingContext() { + JsScope scope = getFunctionContext().getScope(); + InsertionPoint insertionPoint = getStatementContext().getInsertionPoint(); + return new NamingContext(scope, insertionPoint); + } + + @NotNull + @Override + public StatementContext getStatementContext() { + return new StatementContext() { + @NotNull + @Override + public JsContext getCurrentStatementContext() { + return getLastStatementLevelContext(); + } + + @NotNull + @Override + protected JsStatement getEmptyStatement() { + return getFunctionContext().getEmpty(); + } + + @Override + public void shiftCurrentStatementForward() { + super.shiftCurrentStatementForward(); + lastStatementWasShifted = true; + } + }; + } + + @NotNull + @Override + public FunctionContext getFunctionContext() { + return functionContext; + } + } }