1 16 package com.google.gwt.dev.js.ast; 17 18 import java.math.BigInteger ; 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 25 public final class JsProgram extends JsNode { 26 27 private final JsStatement debuggerStmt = new JsDebugger(); 28 29 private final Map decimalLiteralMap = new HashMap (); 30 31 private final JsEmpty emptyStmt = new JsEmpty(); 32 33 private final JsBooleanLiteral falseLiteral = new JsBooleanLiteral(false); 34 35 private final JsGlobalBlock globalBlock; 36 37 private final Map integralLiteralMap = new HashMap (); 38 39 private final JsNullLiteral nullLiteral = new JsNullLiteral(); 40 41 private final JsScope objectScope; 42 43 private final JsRootScope rootScope; 44 45 private final Map stringLiteralMap = new HashMap (); 46 47 private final JsScope topScope; 48 49 private final JsBooleanLiteral trueLiteral = new JsBooleanLiteral(true); 50 51 54 public JsProgram() { 55 rootScope = new JsRootScope(this); 56 globalBlock = new JsGlobalBlock(); 57 topScope = new JsScope(rootScope, "Global"); 58 objectScope = new JsScope(rootScope, "Object"); 59 } 60 61 67 public JsStatement getDebuggerStmt() { 68 return debuggerStmt; 69 } 70 71 public JsDecimalLiteral getDecimalLiteral(String value) { 72 JsDecimalLiteral lit = (JsDecimalLiteral) decimalLiteralMap.get(value); 73 if (lit == null) { 74 lit = new JsDecimalLiteral(value); 75 decimalLiteralMap.put(value, lit); 76 } 77 return lit; 78 } 79 80 public JsEmpty getEmptyStmt() { 81 return emptyStmt; 82 } 83 84 public JsBooleanLiteral getFalseLiteral() { 85 return falseLiteral; 86 } 87 88 91 public JsBlock getGlobalBlock() { 92 return globalBlock; 93 } 94 95 public JsIntegralLiteral getIntegralLiteral(BigInteger value) { 96 JsIntegralLiteral lit = (JsIntegralLiteral) integralLiteralMap.get(value); 97 if (lit == null) { 98 lit = new JsIntegralLiteral(value); 99 integralLiteralMap.put(value, lit); 100 } 101 return lit; 102 } 103 104 public JsNullLiteral getNullLiteral() { 105 return nullLiteral; 106 } 107 108 public JsScope getObjectScope() { 109 return objectScope; 110 } 111 112 117 public JsRootScope getRootScope() { 118 return rootScope; 119 } 120 121 125 public JsScope getScope() { 126 return topScope; 127 } 128 129 public JsStringLiteral getStringLiteral(String value) { 130 JsStringLiteral lit = (JsStringLiteral) stringLiteralMap.get(value); 131 if (lit == null) { 132 lit = new JsStringLiteral(value); 133 stringLiteralMap.put(value, lit); 134 } 135 return lit; 136 } 137 138 public JsBooleanLiteral getTrueLiteral() { 139 return trueLiteral; 140 } 141 142 public void traverse(JsVisitor v, JsContext ctx) { 143 if (v.visit(this, ctx)) { 144 v.accept(globalBlock); 145 } 146 v.endVisit(this, ctx); 147 } 148 } 149 | Popular Tags |