Solved some JsScope issues.

This commit is contained in:
Pavel Talanov
2011-11-03 22:25:52 +04:00
parent 0e82ff14a8
commit 51856147a2
18 changed files with 539 additions and 516 deletions
+248 -252
View File
@@ -6,41 +6,18 @@
</component>
<component name="ChangeListManager">
<list default="true" id="f02ef53d-47a4-4f5e-a1aa-3df68aae9b20" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lib/junit-4.10.jar" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/libraries/junit.xml" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/test/org/jetbrains/k2js/test/TranslatorTests.java" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/test_files/test_cases/assign.jet" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/test_files/test_cases/localProperty.jet" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/test_files/test_cases/test.kt" />
<change type="DELETED" beforePath="C:\Dev\Projects\jet-contrib\k2js\.idea\libraries\lib.xml" afterPath="" />
<change type="DELETED" beforePath="C:\Dev\Projects\jet-contrib\k2js\out\production\k2js\org\jetbrains\k2js\translate\jet\Library.jet" afterPath="" />
<change type="DELETED" beforePath="C:\Dev\Projects\jet-contrib\k2js\out\test\k2js\com\google\dart\compiler\backend\js\Test.class" afterPath="" />
<change type="DELETED" beforePath="C:\Dev\Projects\jet-contrib\k2js\test\com\google\dart\compiler\backend\js\Test.java" afterPath="" />
<change type="DELETED" beforePath="C:\Dev\Projects\jet-contrib\k2js\test_files\test.kt" afterPath="" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/vcs.xml" afterPath="$PROJECT_DIR$/.idea/vcs.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/k2js.iml" afterPath="$PROJECT_DIR$/k2js.iml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/JsNamer.java" afterPath="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/JsNamer.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/JsSourceGenerationVisitor.java" afterPath="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/JsSourceGenerationVisitor.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/google/dart/compiler/common/Name.java" afterPath="$PROJECT_DIR$/src/com/google/dart/compiler/common/Name.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/google/dart/compiler/util/AstUtil.java" afterPath="$PROJECT_DIR$/src/com/google/dart/compiler/util/AstUtil.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/google/dart/compiler/util/Lists.java" afterPath="$PROJECT_DIR$/src/com/google/dart/compiler/util/Lists.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/google/dart/compiler/util/Maps.java" afterPath="$PROJECT_DIR$/src/com/google/dart/compiler/util/Maps.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/K2JSTranslator.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/K2JSTranslator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/generate/CodeGenerator.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/generate/CodeGenerator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/AbstractTranslator.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/AbstractTranslator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ClassTranslator.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ClassTranslator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ContextType.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ContextType.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java" afterPath="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsRootScope.java" afterPath="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsRootScope.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsScope.java" afterPath="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsScope.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/DeclarationTranslator.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/DeclarationTranslator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionTranslator.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionTranslator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/FunctionTranslator.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/FunctionTranslator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/K2JsVisitor.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/K2JsVisitor.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/Namer.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/Namer.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/NamespaceTranslator.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/NamespaceTranslator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/OperationTranslator.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/OperationTranslator.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/TranslationContext.java" afterPath="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/TranslationContext.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/test/org/jetbrains/k2js/test/TranslatorTests.java" afterPath="$PROJECT_DIR$/test/org/jetbrains/k2js/test/TranslatorTests.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/test_files/test_cases/test.kt" afterPath="$PROJECT_DIR$/test_files/test_cases/test.kt" />
</list>
<ignored path="k2js.iws" />
<ignored path=".idea/workspace.xml" />
@@ -65,7 +42,20 @@
</component>
<component name="DebuggerManager">
<line_breakpoints>
<breakpoint url="file://$PROJECT_DIR$/test/org/jetbrains/k2js/test/TranslatorTests.java" line="37" class="org.jetbrains.k2js.test.TranslatorTests" package="org.jetbrains.k2js.test">
<breakpoint url="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" line="113" class="org.jetbrains.k2js.translate.ExpressionVisitor" package="org.jetbrains.k2js.translate">
<option name="ENABLED" value="true" />
<option name="LOG_ENABLED" value="false" />
<option name="LOG_EXPRESSION_ENABLED" value="false" />
<option name="SUSPEND_POLICY" value="SuspendAll" />
<option name="COUNT_FILTER_ENABLED" value="false" />
<option name="COUNT_FILTER" value="0" />
<option name="CONDITION_ENABLED" value="false" />
<option name="CLASS_FILTERS_ENABLED" value="false" />
<option name="INSTANCE_FILTERS_ENABLED" value="false" />
<option name="CONDITION" value="" />
<option name="LOG_MESSAGE" value="" />
</breakpoint>
<breakpoint url="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" line="126" class="org.jetbrains.k2js.translate.ExpressionVisitor" package="org.jetbrains.k2js.translate">
<option name="ENABLED" value="true" />
<option name="LOG_ENABLED" value="false" />
<option name="LOG_EXPRESSION_ENABLED" value="false" />
@@ -118,13 +108,13 @@
<favorites_list name="k2js" />
</component>
<component name="FileEditorManager">
<splitter split-orientation="horizontal" split-proportion="0.29155123">
<splitter split-orientation="horizontal" split-proportion="0.3427978">
<split-first>
<leaf>
<file leaf-file-name="TranslatorTests.java" pinned="false" current="false" current-in-tab="true">
<file leaf-file-name="TranslatorTests.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/org/jetbrains/k2js/test/TranslatorTests.java">
<provider selected="true" editor-type-id="text-editor">
<state line="57" column="16" selection-start="1910" selection-end="1910" vertical-scroll-proportion="0.97495526">
<state line="70" column="42" selection-start="2283" selection-end="2283" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
@@ -132,37 +122,37 @@
</provider>
</entry>
</file>
<file leaf-file-name="JsVisitor.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsVisitor.java">
<file leaf-file-name="localProperty.js" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/test_files/test_cases/localProperty.js">
<provider selected="true" editor-type-id="text-editor">
<state line="429" column="0" selection-start="8829" selection-end="8829" vertical-scroll-proportion="0.0">
<state line="12" column="22" selection-start="174" selection-end="174" vertical-scroll-proportion="0.33333334">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="JsToStringGenerationVisitor.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/JsToStringGenerationVisitor.java">
<file leaf-file-name="NamespaceTranslator.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/NamespaceTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="236" column="0" selection-start="8269" selection-end="8269" vertical-scroll-proportion="0.0">
<state line="23" column="136" selection-start="641" selection-end="641" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="IElementType.class" pinned="false" current="false" current-in-tab="false">
<entry file="jar://C:/Program Files (x86)/JetBrains/IntelliJ IDEA Community Edition 110.283/lib/openapi.jar!/com/intellij/psi/tree/IElementType.class">
<file leaf-file-name="localProperty.jet" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test_files/test_cases/localProperty.jet">
<provider selected="true" editor-type-id="text-editor">
<state line="5" column="13" selection-start="159" selection-end="159" vertical-scroll-proportion="0.0">
<state line="13" column="22" selection-start="135" selection-end="135" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ParentRunner.class" pinned="false" current="false" current-in-tab="false">
<entry file="jar://C:/Program Files (x86)/JetBrains/IntelliJ IDEA Community Edition 110.240/lib/junit-4.10.jar!/org/junit/runners/ParentRunner.class">
<file leaf-file-name="JsFunction.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsFunction.java">
<provider selected="true" editor-type-id="text-editor">
<state line="49" column="16" selection-start="2839" selection-end="2839" vertical-scroll-proportion="0.0">
<state line="93" column="22" selection-start="2533" selection-end="2533" vertical-scroll-proportion="-6.8461537">
<folding />
</state>
</provider>
@@ -217,91 +207,91 @@
</split-first>
<split-second>
<leaf>
<file leaf-file-name="localProperty.jet" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test_files/test_cases/localProperty.jet">
<provider selected="true" editor-type-id="text-editor">
<state line="15" column="3" selection-start="139" selection-end="139" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="TranslationContext.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/TranslationContext.java">
<provider selected="true" editor-type-id="text-editor">
<state line="117" column="5" selection-start="3876" selection-end="3876" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="FunctionTranslator.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/FunctionTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="40" column="56" selection-start="1624" selection-end="1624" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="NamespaceTranslator.java" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/NamespaceTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="23" column="136" selection-start="641" selection-end="641" vertical-scroll-proportion="0.32668713">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ClassTranslator.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ClassTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="19" column="68" selection-start="625" selection-end="625" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Namer.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/Namer.java">
<provider selected="true" editor-type-id="text-editor">
<state line="76" column="59" selection-start="2627" selection-end="2627" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="JsParameter.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsParameter.java">
<provider selected="true" editor-type-id="text-editor">
<state line="13" column="9" selection-start="409" selection-end="409" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ClassBodyVisitor.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="101" column="102" selection-start="4402" selection-end="4402" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ExpressionVisitor.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="44" column="72" selection-start="1694" selection-end="1694" vertical-scroll-proportion="0.0">
<state line="113" column="0" selection-start="4622" selection-end="4622" vertical-scroll-proportion="-18.461538">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="AbstractTranslator.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/AbstractTranslator.java">
<file leaf-file-name="ValueArgument.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/psi/ValueArgument.java">
<provider selected="true" editor-type-id="text-editor">
<state line="44" column="5" selection-start="1118" selection-end="1118" vertical-scroll-proportion="0.0">
<state line="9" column="20" selection-start="207" selection-end="207" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="JetNamedArgumentImpl.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedArgumentImpl.java">
<provider selected="true" editor-type-id="text-editor">
<state line="9" column="13" selection-start="192" selection-end="192" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="CallMaker.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallMaker.java">
<provider selected="true" editor-type-id="text-editor">
<state line="18" column="25" selection-start="488" selection-end="488" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="JetCallExpression.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetCallExpression.java">
<provider selected="true" editor-type-id="text-editor">
<state line="25" column="0" selection-start="644" selection-end="644" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="AstUtil.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/google/dart/compiler/util/AstUtil.java">
<provider selected="true" editor-type-id="text-editor">
<state line="35" column="0" selection-start="1191" selection-end="1191" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="test.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test_files/test_cases/test.js">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ExpressionTranslator.java" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="9" column="6" selection-start="225" selection-end="225" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="test.kt" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test_files/test_cases/test.kt">
<provider selected="true" editor-type-id="text-editor">
<state line="9" column="0" selection-start="104" selection-end="104" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="assign.js" pinned="false" current="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/test_files/test_cases/assign.js">
<provider selected="true" editor-type-id="text-editor">
<state line="8" column="32" selection-start="123" selection-end="123" vertical-scroll-proportion="0.20858896">
<folding />
</state>
</provider>
@@ -323,22 +313,22 @@
<component name="IdeDocumentHistory">
<option name="changedFiles">
<list>
<option value="$PROJECT_DIR$/test_files/test_cases/assign.js" />
<option value="$PROJECT_DIR$/test_files/test_cases/assign.jet" />
<option value="$PROJECT_DIR$/test_files/test_cases/test.js" />
<option value="$PROJECT_DIR$/test_files/test_cases/bottles.jet" />
<option value="$PROJECT_DIR$/test/org/jetbrains/k2js/test/TranslatorTests.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/OperationTranslator.java" />
<option value="$PROJECT_DIR$/test_files/test_cases/localProperty.jet" />
<option value="$PROJECT_DIR$/src/com/google/dart/compiler/util/AstUtil.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/TranslationContext.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/AbstractTranslator.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/FunctionTranslator.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/Namer.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ClassTranslator.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/NamespaceTranslator.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/DeclarationTranslator.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/FunctionTranslator.java" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/TranslationContext.java" />
<option value="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsScope.java" />
<option value="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsRootScope.java" />
<option value="$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java" />
<option value="$PROJECT_DIR$/test/org/jetbrains/k2js/test/TranslatorTests.java" />
<option value="$PROJECT_DIR$/test_files/test_cases/localProperty.js" />
<option value="$PROJECT_DIR$/test_files/test_cases/test.kt" />
<option value="$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionVisitor.java" />
<option value="$PROJECT_DIR$/test_files/test_cases/assign.js" />
<option value="$PROJECT_DIR$/test_files/test_cases/localProperty.jet" />
</list>
</option>
</component>
@@ -594,63 +584,7 @@
<recent name="C:\Dev\Projects\k2js\src\org\jetbrains\k2js\translate" />
</key>
</component>
<component name="RunManager" selected="JUnit.org.jetbrains.k2js.test in k2js">
<configuration default="false" name="K2JSTranslator" type="JUnit" factoryName="JUnit" temporary="true">
<module name="k2js" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" value="" />
<option name="PACKAGE_NAME" value="org.jetbrains.k2js" />
<option name="MAIN_CLASS_NAME" value="org.jetbrains.k2js.K2JSTranslator" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="" />
<option name="PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="moduleWithDependencies" />
</option>
<envs />
<patterns />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="50557" />
<option name="TRANSPORT" value="0" />
<option name="LOCAL" value="true" />
</RunnerSettings>
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Debug" />
<ConfigurationWrapper RunnerId="Run" />
<method />
</configuration>
<configuration default="false" name="TranslatorTests.Test" type="JUnit" factoryName="JUnit" temporary="true">
<module name="k2js" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PACKAGE_NAME" value="org.jetbrains.k2js.test" />
<option name="MAIN_CLASS_NAME" value="org.jetbrains.k2js.test.TranslatorTests" />
<option name="METHOD_NAME" value="Test" />
<option name="TEST_OBJECT" value="method" />
<option name="VM_PARAMETERS" />
<option name="PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="moduleWithDependencies" />
</option>
<envs />
<patterns />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="50174" />
<option name="TRANSPORT" value="0" />
<option name="LOCAL" value="true" />
</RunnerSettings>
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Debug" />
<ConfigurationWrapper RunnerId="Run" />
<method />
</configuration>
<component name="RunManager" selected="JUnit.TranslatorTests">
<configuration default="false" name="All in k2js" type="JUnit" factoryName="JUnit" temporary="true">
<module name="k2js" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
@@ -697,7 +631,13 @@
</option>
<envs />
<patterns />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="51215" />
<option name="TRANSPORT" value="0" />
<option name="LOCAL" value="true" />
</RunnerSettings>
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Debug" />
<ConfigurationWrapper RunnerId="Run" />
<method />
</configuration>
@@ -723,6 +663,62 @@
<ConfigurationWrapper RunnerId="Run" />
<method />
</configuration>
<configuration default="false" name="TranslatorTests.test" type="JUnit" factoryName="JUnit" temporary="true">
<module name="k2js" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PACKAGE_NAME" value="org.jetbrains.k2js.test" />
<option name="MAIN_CLASS_NAME" value="org.jetbrains.k2js.test.TranslatorTests" />
<option name="METHOD_NAME" value="test" />
<option name="TEST_OBJECT" value="method" />
<option name="VM_PARAMETERS" />
<option name="PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="moduleWithDependencies" />
</option>
<envs />
<patterns />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="51218" />
<option name="TRANSPORT" value="0" />
<option name="LOCAL" value="true" />
</RunnerSettings>
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Debug" />
<ConfigurationWrapper RunnerId="Run" />
<method />
</configuration>
<configuration default="false" name="TranslatorTests.namespaceProperties" type="JUnit" factoryName="JUnit" temporary="true">
<module name="k2js" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PACKAGE_NAME" value="org.jetbrains.k2js.test" />
<option name="MAIN_CLASS_NAME" value="org.jetbrains.k2js.test.TranslatorTests" />
<option name="METHOD_NAME" value="namespaceProperties" />
<option name="TEST_OBJECT" value="method" />
<option name="VM_PARAMETERS" />
<option name="PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="moduleWithDependencies" />
</option>
<envs />
<patterns />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="51241" />
<option name="TRANSPORT" value="0" />
<option name="LOCAL" value="true" />
</RunnerSettings>
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Debug" />
<ConfigurationWrapper RunnerId="Run" />
<method />
</configuration>
<configuration default="true" type="Remote" factoryName="Remote">
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
@@ -798,11 +794,11 @@
</method>
</configuration>
<list size="5">
<item index="0" class="java.lang.String" itemvalue="JUnit.K2JSTranslator" />
<item index="1" class="java.lang.String" itemvalue="JUnit.TranslatorTests.Test" />
<item index="2" class="java.lang.String" itemvalue="JUnit.All in k2js" />
<item index="3" class="java.lang.String" itemvalue="JUnit.TranslatorTests" />
<item index="4" class="java.lang.String" itemvalue="JUnit.org.jetbrains.k2js.test in k2js" />
<item index="0" class="java.lang.String" itemvalue="JUnit.All in k2js" />
<item index="1" class="java.lang.String" itemvalue="JUnit.TranslatorTests" />
<item index="2" class="java.lang.String" itemvalue="JUnit.org.jetbrains.k2js.test in k2js" />
<item index="3" class="java.lang.String" itemvalue="JUnit.TranslatorTests.test" />
<item index="4" class="java.lang.String" itemvalue="JUnit.TranslatorTests.namespaceProperties" />
</list>
<configuration name="&lt;template&gt;" type="WebApp" default="true" selected="false">
<Host>localhost</Host>
@@ -848,7 +844,7 @@
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32907662" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Messages" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32854405" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Metrics" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.3284169" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Metrics" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.3275862" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="true" content_ui="tabs" />
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.3997862" sideWeight="0.6705998" order="0" side_tool="false" content_ui="tabs" />
@@ -915,23 +911,16 @@
<option name="FILTER_TARGETS" value="false" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/TranslationContext.java">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/DeclarationTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="117" column="5" selection-start="3876" selection-end="3876" vertical-scroll-proportion="0.0">
<state line="66" column="71" selection-start="2572" selection-end="2572" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionVisitor.java">
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/FunctionTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="44" column="72" selection-start="1694" selection-end="1694" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test_files/test_cases/test.js">
<provider selected="true" editor-type-id="text-editor">
<state line="11" column="0" selection-start="131" selection-end="131" vertical-scroll-proportion="0.0">
<state line="26" column="16" selection-start="907" selection-end="907" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
@@ -943,41 +932,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/FunctionTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="40" column="56" selection-start="1624" selection-end="1624" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/K2JSTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="48" column="56" selection-start="1885" selection-end="1885" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ClassBodyVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="101" column="102" selection-start="4402" selection-end="4402" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsParameter.java">
<provider selected="true" editor-type-id="text-editor">
<state line="13" column="9" selection-start="409" selection-end="409" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/Namer.java">
<provider selected="true" editor-type-id="text-editor">
<state line="76" column="59" selection-start="2627" selection-end="2627" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionTranslator.java">
<provider selected="true" editor-type-id="text-editor">
<state line="9" column="6" selection-start="225" selection-end="225" vertical-scroll-proportion="0.0">
@@ -985,46 +939,88 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/ast/JsVisitor.java">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/psi/ValueArgument.java">
<provider selected="true" editor-type-id="text-editor">
<state line="429" column="0" selection-start="8829" selection-end="8829" vertical-scroll-proportion="0.0">
<state line="9" column="20" selection-start="207" selection-end="207" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test_files/test_cases/assign.jet">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedArgumentImpl.java">
<provider selected="true" editor-type-id="text-editor">
<state line="10" column="18" selection-start="114" selection-end="114" vertical-scroll-proportion="0.0">
<state line="9" column="13" selection-start="192" selection-end="192" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/google/dart/compiler/backend/js/JsToStringGenerationVisitor.java">
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallMaker.java">
<provider selected="true" editor-type-id="text-editor">
<state line="236" column="0" selection-start="8269" selection-end="8269" vertical-scroll-proportion="0.0">
<state line="18" column="25" selection-start="488" selection-end="488" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/google/dart/compiler/util/AstUtil.java">
<provider selected="true" editor-type-id="text-editor">
<state line="35" column="0" selection-start="1191" selection-end="1191" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetCallExpression.java">
<provider selected="true" editor-type-id="text-editor">
<state line="25" column="0" selection-start="644" selection-end="644" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/org/jetbrains/k2js/test/TranslatorTests.java">
<provider selected="true" editor-type-id="text-editor">
<state line="57" column="16" selection-start="1910" selection-end="1910" vertical-scroll-proportion="0.97495526">
<state line="70" column="42" selection-start="2283" selection-end="2283" vertical-scroll-proportion="0.0">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ClassTranslator.java">
<entry file="file://$PROJECT_DIR$/test_files/test_cases/test.js">
<provider selected="true" editor-type-id="text-editor">
<state line="19" column="68" selection-start="625" selection-end="625" vertical-scroll-proportion="0.0">
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/NamespaceTranslator.java">
<entry file="file://$PROJECT_DIR$/test_files/test_cases/test.kt">
<provider selected="true" editor-type-id="text-editor">
<state line="23" column="136" selection-start="641" selection-end="641" vertical-scroll-proportion="0.32668713">
<state line="9" column="0" selection-start="104" selection-end="104" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/org/jetbrains/k2js/translate/ExpressionVisitor.java">
<provider selected="true" editor-type-id="text-editor">
<state line="113" column="0" selection-start="4622" selection-end="4622" vertical-scroll-proportion="-18.461538">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test_files/test_cases/assign.js">
<provider selected="true" editor-type-id="text-editor">
<state line="8" column="32" selection-start="123" selection-end="123" vertical-scroll-proportion="0.20858896">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test_files/test_cases/localProperty.jet">
<provider selected="true" editor-type-id="text-editor">
<state line="13" column="22" selection-start="135" selection-end="135" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test_files/test_cases/localProperty.js">
<provider selected="true" editor-type-id="text-editor">
<state line="12" column="22" selection-start="174" selection-end="174" vertical-scroll-proportion="0.33333334">
<folding />
</state>
</provider>
BIN
View File
Binary file not shown.
@@ -65,7 +65,7 @@ public class JsCatchScope extends JsScope {
}
@Override
protected JsName findExistingNameNoRecurse(String ident) {
public JsName findExistingNameNoRecurse(String ident) {
if (name.getIdent().equals(ident)) {
return name;
} else {
@@ -33,7 +33,7 @@ public final class JsRootScope extends JsScope {
}
@Override
protected JsName findExistingNameNoRecurse(String ident) {
public JsName findExistingNameNoRecurse(String ident) {
JsName name = super.findExistingNameNoRecurse(ident);
if (name == null) {
if (JsReservedIdentifiers.getReservedGlobalSymbols().contains(ident)) {
@@ -18,18 +18,18 @@ import java.util.Map;
* {@link com.google.dart.compiler.backend.js.ast.JsName}s. A JavaScript AST is
* built in terms of abstract name objects without worrying about obfuscation,
* keyword/identifier blacklisting, and so on.
*
* <p>
*
* <p/>
* <p/>
* <p/>
* Scopes are associated with
* {@link com.google.dart.compiler.backend.js.ast.JsFunction}s, but the two are
* not equivalent. Functions <i>have</i> scopes, but a scope does not
* necessarily have an associated Function. Examples of this include the
* {@link com.google.dart.compiler.backend.js.ast.JsRootScope} and synthetic
* scopes that might be created by a client.
*
* <p>
*
* <p/>
* <p/>
* <p/>
* Scopes can have parents to provide constraints when allocating actual
* identifiers for names. Specifically, names in child scopes are chosen such
* that they do not conflict with names in their parent scopes. The ultimate
@@ -41,258 +41,260 @@ import java.util.Map;
*/
public class JsScope implements Serializable {
private List<JsScope> children = Collections.emptyList();
private final String description;
private Map<String, JsName> names = Collections.emptyMap();
private JsScope parent;
protected int tempIndex = 0;
private final String scopeId;
private List<JsScope> children = Collections.emptyList();
private final String description;
private Map<String, JsName> names = Collections.emptyMap();
private JsScope parent;
protected int tempIndex = 0;
private final String scopeId;
/*
* Create a scope with parent.
*/
public JsScope(JsScope parent, String description) {
this(parent, description, null);
}
/**
* Create a scope with parent.
*/
public JsScope(JsScope parent, String description, String scopeId) {
assert (parent != null);
this.scopeId = scopeId;
this.description = description;
this.parent = parent;
parent.children = Lists.add(parent.children, this);
}
/**
* Rebase the function to a new scope.
* @param newParent The scope to add the function to.
*/
public void rebase(JsScope newParent) {
detachFromParent();
parent = newParent;
parent.children = Lists.add(parent.children, this);
}
/**
* Rebase the function's children to a new scope.
* @param newParent
*/
public void rebaseChildScopes(JsScope newParent) {
if (newParent == this) {
return;
/*
* Create a scope with parent.
*/
public JsScope(JsScope parent, String description) {
this(parent, description, null);
}
parent.children = Lists.addAll(parent.children, children);
for (JsScope child : children) {
child.parent = newParent;
/**
* Create a scope with parent.
*/
public JsScope(JsScope parent, String description, String scopeId) {
assert (parent != null);
this.scopeId = scopeId;
this.description = description;
this.parent = parent;
parent.children = Lists.add(parent.children, this);
}
children = Collections.emptyList();
}
/**
* Subclasses can detach and become parentless.
*/
protected void detachFromParent() {
JsScope oldParent = parent;
oldParent.children = Lists.remove(
parent.children, oldParent.children.indexOf(this));
parent = null;
}
/**
* Subclasses can be parentless.
*/
protected JsScope(String description) {
this.description = description;
this.parent = null;
this.scopeId = null;
}
/**
* Gets a name object associated with the specified ident in this scope,
* creating it if necessary.<br/>
* If the JsName does not exist yet, a new JsName is created. The ident,
* short name, and original name of the newly created JsName are equal to
* the given ident.
*
* @param ident An identifier that is unique within this scope.
*/
public JsName declareName(String ident) {
JsName name = findExistingNameNoRecurse(ident);
if (name != null) {
return name;
/**
* Rebase the function to a new scope.
*
* @param newParent The scope to add the function to.
*/
public void rebase(JsScope newParent) {
detachFromParent();
parent = newParent;
parent.children = Lists.add(parent.children, this);
}
return doCreateName(ident, ident, ident);
}
/**
* Creates a new variable with an unique ident in this scope.
* The generated JsName is guaranteed to have an identifier (but not short
* name) that does not clash with any existing variables in the scope.
* Future declarations of variables might however clash with the temporary
* (unless they use this function).
*/
public JsName declareFreshName(String shortName) {
String ident = shortName;
int counter = 0;
while (findExistingNameNoRecurse(ident) != null) {
ident = shortName + "_" + counter++;
/**
* Rebase the function's children to a new scope.
*
* @param newParent
*/
public void rebaseChildScopes(JsScope newParent) {
if (newParent == this) {
return;
}
parent.children = Lists.addAll(parent.children, children);
for (JsScope child : children) {
child.parent = newParent;
}
children = Collections.emptyList();
}
return doCreateName(ident, shortName, shortName);
}
String getNextTempName() {
// TODO(ngeoffray): Decide on a convention for temporary variables
// introduced by the compiler.
return "tmp$" + (scopeId != null ? scopeId + "$" : "") + tempIndex++;
}
/**
* Subclasses can detach and become parentless.
*/
protected void detachFromParent() {
JsScope oldParent = parent;
/**
* Creates a temporary variable with an unique name in this scope.
* The generated temporary is guaranteed to have an identifier (but not short
* name) that does not clash with any existing variables in the scope.
* Future declarations of variables might however clash with the temporary.
*/
public JsName declareTemporary() {
return declareFreshName(getNextTempName());
}
oldParent.children = Lists.remove(
parent.children, oldParent.children.indexOf(this));
/**
* Gets a name object associated with the specified ident in this scope,
* creating it if necessary.<br/>
* If the JsName does not exist yet, a new JsName is created with the given
* ident, short name and original name.
*
* @param ident An identifier that is unique within this scope.
* @param shortIdent A "pretty" name that does not have to be unique.
* @throws IllegalArgumentException if ident already exists in this scope but
* the requested short name does not match the existing short name.
*/
public JsName declareName(String ident, String shortIdent) {
return declareName(ident, shortIdent, ident);
}
/**
* Gets a name object associated with the specified ident in this scope,
* creating it if necessary.<br/>
* If the JsName does not exist yet, a new JsName is created. The original
* name stored in the JsName is equal to the (unmangled) specified originalName.
*
* @param ident An identifier that is unique within this scope.
* @param shortIdent A "pretty" name that does not have to be unique.
* @param originalName The original name in the source.
* @throws IllegalArgumentException if ident already exists in this scope but
* the requested short name does not match the existing short name,
* or the original name does not match the existing original name.
*/
public JsName declareName(String ident, String shortIdent, String originalName) {
JsName name = findExistingNameNoRecurse(ident);
if (name != null) {
if (!name.getShortIdent().equals(shortIdent)
|| !nullableEquals(name.getOriginalName(), originalName)) {
throw new IllegalArgumentException("Requested short name " + shortIdent
+ " conflicts with preexisting short name " + name.getShortIdent() + " for identifier "
+ ident);
}
return name;
parent = null;
}
return doCreateName(ident, shortIdent, originalName);
}
boolean nullableEquals(String s1, String s2) {
return (s1 == null) ? (s2 == null) : s1.equals(s2);
}
/**
* Attempts to find the name object for the specified ident, searching in this
* scope, and if not found, in the parent scopes.
*
* @return <code>null</code> if the identifier has no associated name
*/
public final JsName findExistingName(String ident) {
JsName name = findExistingNameNoRecurse(ident);
if (name == null && parent != null) {
return parent.findExistingName(ident);
/**
* Subclasses can be parentless.
*/
protected JsScope(String description) {
this.description = description;
this.parent = null;
this.scopeId = null;
}
return name;
}
/**
* Attempts to find an unobfuscatable name object for the specified ident,
* searching in this scope, and if not found, in the parent scopes.
*
* @return <code>null</code> if the identifier has no associated name
*/
public final JsName findExistingUnobfuscatableName(String ident) {
JsName name = findExistingNameNoRecurse(ident);
if (name != null && name.isObfuscatable()) {
name = null;
/**
* Gets a name object associated with the specified ident in this scope,
* creating it if necessary.<br/>
* If the JsName does not exist yet, a new JsName is created. The ident,
* short name, and original name of the newly created JsName are equal to
* the given ident.
*
* @param ident An identifier that is unique within this scope.
*/
public JsName declareName(String ident) {
JsName name = findExistingNameNoRecurse(ident);
if (name != null) {
return name;
}
return doCreateName(ident, ident, ident);
}
if (name == null && parent != null) {
return parent.findExistingUnobfuscatableName(ident);
/**
* Creates a new variable with an unique ident in this scope.
* The generated JsName is guaranteed to have an identifier (but not short
* name) that does not clash with any existing variables in the scope.
* Future declarations of variables might however clash with the temporary
* (unless they use this function).
*/
public JsName declareFreshName(String shortName) {
String ident = shortName;
int counter = 0;
while (findExistingNameNoRecurse(ident) != null) {
ident = shortName + "_" + counter++;
}
return doCreateName(ident, shortName, shortName);
}
return name;
}
/**
* Returns an iterator for all the names defined by this scope.
*/
public Iterator<JsName> getAllNames() {
return names.values().iterator();
}
/**
* Returns a list of this scope's child scopes.
*/
public final List<JsScope> getChildren() {
return children;
}
/**
* Returns the parent scope of this scope, or <code>null</code> if this is the
* root scope.
*/
public final JsScope getParent() {
return parent;
}
/**
* Returns the associated program.
*/
public JsProgram getProgram() {
assert (parent != null) : "Subclasses must override getProgram() if they do not set a parent";
return parent.getProgram();
}
@Override
public final String toString() {
if (parent != null) {
return description + "->" + parent;
} else {
return description;
String getNextTempName() {
// TODO(ngeoffray): Decide on a convention for temporary variables
// introduced by the compiler.
return "tmp$" + (scopeId != null ? scopeId + "$" : "") + tempIndex++;
}
}
/**
* Creates a new name in this scope.
*/
protected JsName doCreateName(String ident, String shortIdent, String originalName) {
JsName name = new JsName(this, ident, shortIdent, originalName);
names = Maps.putOrdered(names, ident, name);
return name;
}
/**
* Creates a temporary variable with an unique name in this scope.
* The generated temporary is guaranteed to have an identifier (but not short
* name) that does not clash with any existing variables in the scope.
* Future declarations of variables might however clash with the temporary.
*/
public JsName declareTemporary() {
return declareFreshName(getNextTempName());
}
/**
* Attempts to find the name object for the specified ident, searching in this
* scope only.
*
* @return <code>null</code> if the identifier has no associated name
*/
protected JsName findExistingNameNoRecurse(String ident) {
return names.get(ident);
}
/**
* Gets a name object associated with the specified ident in this scope,
* creating it if necessary.<br/>
* If the JsName does not exist yet, a new JsName is created with the given
* ident, short name and original name.
*
* @param ident An identifier that is unique within this scope.
* @param shortIdent A "pretty" name that does not have to be unique.
* @throws IllegalArgumentException if ident already exists in this scope but
* the requested short name does not match the existing short name.
*/
public JsName declareName(String ident, String shortIdent) {
return declareName(ident, shortIdent, ident);
}
/**
* Gets a name object associated with the specified ident in this scope,
* creating it if necessary.<br/>
* If the JsName does not exist yet, a new JsName is created. The original
* name stored in the JsName is equal to the (unmangled) specified originalName.
*
* @param ident An identifier that is unique within this scope.
* @param shortIdent A "pretty" name that does not have to be unique.
* @param originalName The original name in the source.
* @throws IllegalArgumentException if ident already exists in this scope but
* the requested short name does not match the existing short name,
* or the original name does not match the existing original name.
*/
public JsName declareName(String ident, String shortIdent, String originalName) {
JsName name = findExistingNameNoRecurse(ident);
if (name != null) {
if (!name.getShortIdent().equals(shortIdent)
|| !nullableEquals(name.getOriginalName(), originalName)) {
throw new IllegalArgumentException("Requested short name " + shortIdent
+ " conflicts with preexisting short name " + name.getShortIdent() + " for identifier "
+ ident);
}
return name;
}
return doCreateName(ident, shortIdent, originalName);
}
boolean nullableEquals(String s1, String s2) {
return (s1 == null) ? (s2 == null) : s1.equals(s2);
}
/**
* Attempts to find the name object for the specified ident, searching in this
* scope, and if not found, in the parent scopes.
*
* @return <code>null</code> if the identifier has no associated name
*/
public final JsName findExistingName(String ident) {
JsName name = findExistingNameNoRecurse(ident);
if (name == null && parent != null) {
return parent.findExistingName(ident);
}
return name;
}
/**
* Attempts to find an unobfuscatable name object for the specified ident,
* searching in this scope, and if not found, in the parent scopes.
*
* @return <code>null</code> if the identifier has no associated name
*/
public final JsName findExistingUnobfuscatableName(String ident) {
JsName name = findExistingNameNoRecurse(ident);
if (name != null && name.isObfuscatable()) {
name = null;
}
if (name == null && parent != null) {
return parent.findExistingUnobfuscatableName(ident);
}
return name;
}
/**
* Returns an iterator for all the names defined by this scope.
*/
public Iterator<JsName> getAllNames() {
return names.values().iterator();
}
/**
* Returns a list of this scope's child scopes.
*/
public final List<JsScope> getChildren() {
return children;
}
/**
* Returns the parent scope of this scope, or <code>null</code> if this is the
* root scope.
*/
public final JsScope getParent() {
return parent;
}
/**
* Returns the associated program.
*/
public JsProgram getProgram() {
assert (parent != null) : "Subclasses must override getProgram() if they do not set a parent";
return parent.getProgram();
}
@Override
public final String toString() {
if (parent != null) {
return description + "->" + parent;
} else {
return description;
}
}
/**
* Creates a new name in this scope.
*/
protected JsName doCreateName(String ident, String shortIdent, String originalName) {
JsName name = new JsName(this, ident, shortIdent, originalName);
names = Maps.putOrdered(names, ident, name);
return name;
}
/**
* Attempts to find the name object for the specified ident, searching in this
* scope only.
*
* @return <code>null</code> if the identifier has no associated name
*/
public JsName findExistingNameNoRecurse(String ident) {
return names.get(ident);
}
}
@@ -65,8 +65,7 @@ public class DeclarationTranslator extends AbstractTranslator {
public final class FunctionVariableDeclaration extends State {
@NotNull
public JsStatement translateProperty(JetProperty declaration) {
String propertyName = declaration.getName();
JsName jsPropertyName = getJSName(propertyName);
JsName jsPropertyName = translationContext().declareLocalName(declaration.getName());
JsExpression jsInitExpression = translateInitializer(declaration);
return AstUtil.newVar(jsPropertyName, jsInitExpression);
}
@@ -76,8 +75,9 @@ public class DeclarationTranslator extends AbstractTranslator {
public final class NamespacePropertyDeclaration extends State {
@NotNull
public JsStatement translateProperty(JetProperty declaration) {
String propertyName = declaration.getName();
JsNameRef jsPropertyNameReference = translationContext().getNamespaceQualifiedReference(getJSName(propertyName));
JsName propertyName = translationContext().declareLocalName(declaration.getName());
JsNameRef jsPropertyNameReference =
translationContext().getNamespaceQualifiedReference(propertyName);
JsExpression jsInitExpression = translateInitializer(declaration);
JsExpression result;
if (jsInitExpression != null) {
@@ -5,6 +5,7 @@ import com.google.dart.compiler.util.AstUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.calls.ExpressionValueArgument;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lexer.JetToken;
@@ -39,10 +40,11 @@ public class ExpressionVisitor extends K2JsVisitor<JsNode> {
public JsNode visitBlockExpression(JetBlockExpression jetBlock, TranslationContext context) {
List<JetElement> jetElements = jetBlock.getStatements();
JsBlock jsBlock = new JsBlock();
TranslationContext newContext = context.newBlock();
for (JetElement jetElement : jetElements) {
//TODO hack alert
JetExpression jetExpression = (JetExpression) jetElement;
JsNode jsNode = jetExpression.accept(this, context.newBlock());
JsNode jsNode = jetExpression.accept(this, newContext);
jsBlock.addStatement(AstUtil.convertToStatement(jsNode));
}
assert jsBlock != null;
@@ -79,15 +81,24 @@ public class ExpressionVisitor extends K2JsVisitor<JsNode> {
return jsBinaryOperation;
}
//TODO think about recursive/non-recursive name look-up
@Override
@NotNull
public JsNode visitSimpleNameExpression(JetSimpleNameExpression expression, TranslationContext context) {
String referencedName = expression.getReferencedName();
if (context.enclosingScope().findExistingName(referencedName) == null) {
JsName name = context.enclosingScope().declareName(referencedName);
return name.makeRef();
JsName jsName = context.enclosingScope().findExistingNameNoRecurse(referencedName);
if (jsName != null) {
return jsName.makeRef();
}
return context.getNamespaceQualifiedReference(context.getJSName(referencedName));
jsName = context.functionScope().findExistingNameNoRecurse(referencedName);
if (jsName != null) {
return context.getNamespaceQualifiedReference(jsName);
}
jsName = context.namespaceScope().findExistingNameNoRecurse(referencedName);
if (jsName != null) {
return context.getNamespaceQualifiedReference(jsName);
}
throw new AssertionError("Unindentified name " + expression.getReferencedName());
}
@Override
@@ -101,7 +112,7 @@ public class ExpressionVisitor extends K2JsVisitor<JsNode> {
@NotNull
public JsNode visitCallExpression(JetCallExpression expression, TranslationContext context) {
JsExpression callee = getCallee(expression, context);
List<JsExpression> arguments = generateArgumentList(expression.getFunctionLiteralArguments(), context);
List<JsExpression> arguments = generateArgumentList(expression.getValueArguments(), context);
return AstUtil.newInvocation(callee, arguments);
}
@@ -112,9 +123,10 @@ public class ExpressionVisitor extends K2JsVisitor<JsNode> {
}
@NotNull
private List<JsExpression> generateArgumentList(List<JetExpression> jetArguments, TranslationContext context) {
private List<JsExpression> generateArgumentList(List<? extends ValueArgument> jetArguments, TranslationContext context) {
List<JsExpression> jsArguments = new ArrayList<JsExpression>();
for (JetExpression jetExpression : jetArguments) {
for (ValueArgument argument : jetArguments) {
JetExpression jetExpression = argument.getArgumentExpression();
jsArguments.add(AstUtil.convertToExpression(jetExpression.accept(this, context)));
}
return jsArguments;
@@ -21,9 +21,10 @@ public class FunctionTranslator extends AbstractTranslator {
@NotNull
public JsStatement translateFunction(JetNamedFunction jetFunction) {
JsNameRef functionName = translationContext().getNamespaceQualifiedReference(getJSName(jetFunction.getName()));
JsName functionName = translationContext().namespaceScope().declareFreshName(jetFunction.getName());
JsFunction function = generateFunctionObject(jetFunction);
return AstUtil.convertToStatement(AstUtil.newAssignment(functionName, function));
return AstUtil.convertToStatement(AstUtil.newAssignment
(translationContext().getNamespaceQualifiedReference(functionName), function));
}
private JsFunction generateFunctionObject(JetNamedFunction jetFunction) {
@@ -25,11 +25,7 @@ public class TranslationContext {
public Scopes(JsScope enclosing, JsScope function, JsScope namespace) {
this.enclosingScope = enclosing;
this.functionScope = function;
this.namespaceScope = function;
}
public Scopes(Scopes other) {
this(other.enclosingScope, other.functionScope, other.namespaceScope);
this.namespaceScope = namespace;
}
public final JsScope enclosingScope;
@@ -42,7 +38,6 @@ public class TranslationContext {
assert program != null;
assert bindingContext != null;
assert scopes != null;
assert currentNamespace != null;
assert type != null;
this.program = program;
this.bindingContext = bindingContext;
@@ -59,7 +54,6 @@ public class TranslationContext {
program, bindingContext, scopes, ContextType.NAMESPACE_BODY);
}
//TODO implement correct factories
@NotNull
public TranslationContext newNamespace(JsName namespaceName, JsFunction namespaceDummyFunction) {
JsScope newScope = namespaceDummyFunction.getScope();
@@ -112,6 +106,21 @@ public class TranslationContext {
return scopes.enclosingScope;
}
@NotNull
JsScope namespaceScope() {
return scopes.namespaceScope;
}
@NotNull
JsScope functionScope() {
return scopes.functionScope;
}
@NotNull
JsName declareLocalName(String name) {
return scopes.enclosingScope.declareFreshName(name);
}
@NotNull
ContextType type() {
return type;
@@ -45,6 +45,8 @@ public class TranslatorTests {
Object functionArgs[] = {};
Function function = (Function) box;
Object result = function.call(cx, scope, scope, functionArgs);
assertTrue(result instanceof Boolean);
assertTrue((Boolean)result == true);
String report = "foo.box() = " + Context.toString(result);
System.out.println(report);
+2 -1
View File
@@ -5,4 +5,5 @@ fun box() : Boolean {
val b = 3;
var c = 4;
return (a < c)
}
}