001 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 002 // for details. All rights reserved. Use of this source code is governed by a 003 // BSD-style license that can be found in the LICENSE file. 004 005 package com.google.dart.compiler.backend.js.ast; 006 007 public abstract class JsLiteral extends JsExpressionImpl { 008 public static final JsValueLiteral THIS = new JsThisRef(); 009 public static final JsNameRef UNDEFINED = new JsNameRef("undefined"); 010 011 public static final JsNullLiteral NULL = new JsNullLiteral(); 012 013 public static final JsBooleanLiteral TRUE = new JsBooleanLiteral(true); 014 public static final JsBooleanLiteral FALSE = new JsBooleanLiteral(false); 015 016 public static JsBooleanLiteral getBoolean(boolean truth) { 017 return truth ? TRUE : FALSE; 018 } 019 020 public static final class JsThisRef extends JsValueLiteral { 021 private JsThisRef() { 022 super(); 023 } 024 025 @Override 026 public void accept(JsVisitor v) { 027 v.visitThis(this); 028 } 029 } 030 031 public static final class JsBooleanLiteral extends JsValueLiteral { 032 private final boolean value; 033 034 // Should be interned by JsProgram 035 private JsBooleanLiteral(boolean value) { 036 this.value = value; 037 } 038 039 public boolean getValue() { 040 return value; 041 } 042 043 @Override 044 public void accept(JsVisitor v) { 045 v.visitBoolean(this); 046 } 047 } 048 049 /** 050 * A JavaScript string literal expression. 051 */ 052 public abstract static class JsValueLiteral extends JsLiteral { 053 protected JsValueLiteral() { 054 } 055 056 @Override 057 public final boolean isLeaf() { 058 return true; 059 } 060 } 061 }