LEFT | RIGHT |
(no file at all) | |
1 // Copyright (C) 2007 Google Inc. | 1 // Copyright (C) 2007 Google Inc. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 reason="", | 939 reason="", |
940 matches="/* in outer scope */ var @v = @r", | 940 matches="/* in outer scope */ var @v = @r", |
941 substitutes="___.di(IMPORTS___, '@v'), IMPORTS___.w___('@v', @r)") | 941 substitutes="___.di(IMPORTS___, '@v'), IMPORTS___.w___('@v', @r)") |
942 public ParseTreeNode fire(ParseTreeNode node, Scope scope) { | 942 public ParseTreeNode fire(ParseTreeNode node, Scope scope) { |
943 Map<String, ParseTreeNode> bindings = this.match(node); | 943 Map<String, ParseTreeNode> bindings = this.match(node); |
944 if (bindings != null) { | 944 if (bindings != null) { |
945 Identifier v = (Identifier) bindings.get("v"); | 945 Identifier v = (Identifier) bindings.get("v"); |
946 String vname = v.getName(); | 946 String vname = v.getName(); |
947 if (scope.isOuter(vname)) { | 947 if (scope.isOuter(vname)) { |
948 ParseTreeNode r = bindings.get("r"); | 948 ParseTreeNode r = bindings.get("r"); |
949 mq.addMessage( | |
950 RewriterMessageType.TOP_LEVEL_VAR_INCOMPATIBLE_WITH_CAJA, | |
951 node.getFilePosition(), | |
952 MessagePart.Factory.valueOf( | |
953 render(QuasiBuilder.substV("window['@v']", "v", v)) | |
954 + " = ...")); | |
955 return newExprStmt((Expression) substV( | 949 return newExprStmt((Expression) substV( |
956 "v", v, | 950 "v", v, |
957 "r", expand(nymize(r, vname, "var"), scope))); | 951 "r", expand(nymize(r, vname, "var"), scope))); |
958 } | 952 } |
959 } | 953 } |
960 return NONE; | 954 return NONE; |
961 } | 955 } |
962 }, | 956 }, |
963 | 957 |
964 new Rule() { | 958 new Rule() { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 name="declGlobalVar", | 1014 name="declGlobalVar", |
1021 synopsis="", | 1015 synopsis="", |
1022 reason="", | 1016 reason="", |
1023 matches="/* in outer scope */ var @v", | 1017 matches="/* in outer scope */ var @v", |
1024 substitutes="___.di(IMPORTS___, '@v')") | 1018 substitutes="___.di(IMPORTS___, '@v')") |
1025 public ParseTreeNode fire(ParseTreeNode node, Scope scope) { | 1019 public ParseTreeNode fire(ParseTreeNode node, Scope scope) { |
1026 Map<String, ParseTreeNode> bindings = this.match(node); | 1020 Map<String, ParseTreeNode> bindings = this.match(node); |
1027 if (bindings != null && | 1021 if (bindings != null && |
1028 bindings.get("v") instanceof Identifier && | 1022 bindings.get("v") instanceof Identifier && |
1029 scope.isOuter(((Identifier) bindings.get("v")).getName())) { | 1023 scope.isOuter(((Identifier) bindings.get("v")).getName())) { |
1030 mq.addMessage( | |
1031 RewriterMessageType.TOP_LEVEL_VAR_INCOMPATIBLE_WITH_CAJA, | |
1032 node.getFilePosition(), | |
1033 MessagePart.Factory.valueOf( | |
1034 render(QuasiBuilder.substV("window['@v'] = undefined", | |
1035 "v", bindings.get("v"))))); | |
1036 ExpressionStmt es = newExprStmt( | 1024 ExpressionStmt es = newExprStmt( |
1037 (Expression) substV("v", bindings.get("v"))); | 1025 (Expression) substV("v", bindings.get("v"))); |
1038 markTreeForSideEffect(es); | 1026 markTreeForSideEffect(es); |
1039 return es; | 1027 return es; |
1040 } | 1028 } |
1041 return NONE; | 1029 return NONE; |
1042 } | 1030 } |
1043 }, | 1031 }, |
1044 | 1032 |
1045 new Rule() { | 1033 new Rule() { |
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2188 private static void requireErrors(MessageQueue mq, ParseTreeNode n) { | 2176 private static void requireErrors(MessageQueue mq, ParseTreeNode n) { |
2189 // Make sure a sub-rule has put an error because the rule got an unexpected | 2177 // Make sure a sub-rule has put an error because the rule got an unexpected |
2190 // result from a recursive call to expand. | 2178 // result from a recursive call to expand. |
2191 if (!mq.hasMessageAtLevel(MessageLevel.ERROR)) { | 2179 if (!mq.hasMessageAtLevel(MessageLevel.ERROR)) { |
2192 mq.addMessage( | 2180 mq.addMessage( |
2193 RewriterMessageType.BAD_RESULT_FROM_RECURSIVE_CALL, | 2181 RewriterMessageType.BAD_RESULT_FROM_RECURSIVE_CALL, |
2194 n.getFilePosition(), n); | 2182 n.getFilePosition(), n); |
2195 } | 2183 } |
2196 } | 2184 } |
2197 } | 2185 } |
LEFT | RIGHT |