01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.js;
17:
18: import com.google.gwt.dev.js.ast.JsName;
19: import com.google.gwt.dev.js.ast.JsNameRef;
20: import com.google.gwt.dev.js.ast.JsProgram;
21:
22: /**
23: * Resolves any unresolved JsNameRefs.
24: */
25: public class JsSymbolResolver {
26:
27: /**
28: * Resolves any unresolved JsNameRefs.
29: */
30: private class JsResolveSymbolsVisitor extends
31: JsAbstractSymbolResolver {
32:
33: @Override
34: protected void resolve(JsNameRef x) {
35: JsName name;
36: String ident = x.getIdent();
37: if (x.getQualifier() == null) {
38: name = getScope().findExistingName(ident);
39: if (name == null) {
40: // No clue what this is; create a new unobfuscatable name
41: name = program.getRootScope().declareName(ident);
42: name.setObfuscatable(false);
43: }
44: } else {
45: name = program.getObjectScope().findExistingName(ident);
46: if (name == null) {
47: // No clue what this is; create a new unobfuscatable name
48: name = program.getObjectScope().declareName(ident);
49: name.setObfuscatable(false);
50: }
51: }
52: x.resolve(name);
53: }
54: }
55:
56: public static void exec(JsProgram program) {
57: new JsSymbolResolver(program).execImpl();
58: }
59:
60: private final JsProgram program;
61:
62: private JsSymbolResolver(JsProgram program) {
63: this .program = program;
64: }
65:
66: private void execImpl() {
67: JsResolveSymbolsVisitor resolver = new JsResolveSymbolsVisitor();
68: resolver.accept(program);
69: }
70: }
|