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    import org.jetbrains.annotations.NotNull;
008    
009    public abstract class JsLiteral extends JsExpressionImpl {
010        public static final JsValueLiteral THIS = new JsThisRef();
011        public static final JsNameRef UNDEFINED = new JsNameRef("undefined");
012    
013        public static final JsNullLiteral NULL = new JsNullLiteral();
014    
015        public static final JsBooleanLiteral TRUE = new JsBooleanLiteral(true);
016        public static final JsBooleanLiteral FALSE = new JsBooleanLiteral(false);
017    
018        public static JsBooleanLiteral getBoolean(boolean truth) {
019            return truth ? TRUE : FALSE;
020        }
021    
022        public static final class JsThisRef extends JsValueLiteral {
023            private JsThisRef() {
024                super();
025            }
026    
027            @Override
028            public void accept(JsVisitor v) {
029                v.visitThis(this);
030            }
031    
032            @Override
033            public void traverse(JsVisitorWithContext v, JsContext ctx) {
034                v.visit(this, ctx);
035                v.endVisit(this, ctx);
036            }
037        }
038    
039        public static final class JsBooleanLiteral extends JsValueLiteral {
040            private final boolean value;
041    
042            // Should be interned by JsProgram
043            private JsBooleanLiteral(boolean value) {
044            this.value = value;
045          }
046    
047            public boolean getValue() {
048            return value;
049          }
050    
051            @Override
052            public void accept(JsVisitor v) {
053            v.visitBoolean(this);
054          }
055    
056            @Override
057            public void traverse(JsVisitorWithContext v, JsContext ctx) {
058                v.visit(this, ctx);
059                v.endVisit(this, ctx);
060            }
061        }
062    
063        /**
064         * A JavaScript string literal expression.
065         */
066        public abstract static class JsValueLiteral extends JsLiteral {
067            protected JsValueLiteral() {
068            }
069    
070            @Override
071            public final boolean isLeaf() {
072                return true;
073            }
074    
075            @NotNull
076            @Override
077            public JsExpression deepCopy() {
078                return this;
079            }
080        }
081    }