PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/js/src/frontend/ParseNode-inl.h

http://github.com/zpao/v8monkey
C Header | 205 lines | 151 code | 16 blank | 38 comment | 12 complexity | 6d8904363c0a40cdde4f3c5a8a6b017c MD5 | raw file
  1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2 * vim: set ts=8 sw=4 et tw=99:
  3 * ***** BEGIN LICENSE BLOCK *****
  4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5 *
  6 * The contents of this file are subject to the Mozilla Public License Version
  7 * 1.1 (the "License"); you may not use this file except in compliance with
  8 * the License. You may obtain a copy of the License at
  9 * http://www.mozilla.org/MPL/
 10 *
 11 * Software distributed under the License is distributed on an "AS IS" basis,
 12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 13 * for the specific language governing rights and limitations under the
 14 * License.
 15 *
 16 * The Original Code is Mozilla Communicator client code, released
 17 * March 31, 1998.
 18 *
 19 * The Initial Developer of the Original Code is
 20 * Netscape Communications Corporation.
 21 * Portions created by the Initial Developer are Copyright (C) 1998-2011
 22 * the Initial Developer. All Rights Reserved.
 23 *
 24 * Contributor(s):
 25 *
 26 * Alternatively, the contents of this file may be used under the terms of
 27 * either the GNU General Public License Version 2 or later (the "GPL"), or
 28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 29 * in which case the provisions of the GPL or the LGPL are applicable instead
 30 * of those above. If you wish to allow use of your version of this file only
 31 * under the terms of either the GPL or the LGPL, and not to allow others to
 32 * use your version of this file under the terms of the MPL, indicate your
 33 * decision by deleting the provisions above and replace them with the notice
 34 * and other provisions required by the GPL or the LGPL. If you do not delete
 35 * the provisions above, a recipient may use your version of this file under
 36 * the terms of any one of the MPL, the GPL or the LGPL.
 37 *
 38 * ***** END LICENSE BLOCK ***** */
 39
 40#ifndef ParseNode_inl_h__
 41#define ParseNode_inl_h__
 42
 43#include "frontend/ParseNode.h"
 44#include "frontend/BytecodeEmitter.h"
 45#include "frontend/TokenStream.h"
 46
 47namespace js {
 48
 49inline bool
 50ParseNode::isConstant()
 51{
 52    switch (pn_type) {
 53      case PNK_NUMBER:
 54      case PNK_STRING:
 55      case PNK_NULL:
 56      case PNK_FALSE:
 57      case PNK_TRUE:
 58        return true;
 59      case PNK_RB:
 60      case PNK_RC:
 61        return isOp(JSOP_NEWINIT) && !(pn_xflags & PNX_NONCONST);
 62      default:
 63        return false;
 64    }
 65}
 66
 67#ifdef DEBUG
 68inline void
 69IndentNewLine(int indent)
 70{
 71    fputc('\n', stderr);
 72    for (int i = 0; i < indent; ++i)
 73        fputc(' ', stderr);
 74}
 75
 76inline void
 77ParseNode::dump(int indent)
 78{
 79    switch (pn_arity) {
 80      case PN_NULLARY:
 81        ((NullaryNode *) this)->dump();
 82        break;
 83      case PN_UNARY:
 84        ((UnaryNode *) this)->dump(indent);
 85        break;
 86      case PN_BINARY:
 87        ((BinaryNode *) this)->dump(indent);
 88        break;
 89      case PN_TERNARY:
 90        ((TernaryNode *) this)->dump(indent);
 91        break;
 92      case PN_FUNC:
 93        ((FunctionNode *) this)->dump(indent);
 94        break;
 95      case PN_LIST:
 96        ((ListNode *) this)->dump(indent);
 97        break;
 98      case PN_NAME:
 99        ((NameNode *) this)->dump(indent);
100        break;
101      default:
102        fprintf(stderr, "?");
103        break;
104    }
105}
106
107inline void
108NullaryNode::dump()
109{
110    fprintf(stderr, "(%s)", js_CodeName[getOp()]);
111}
112
113inline void
114UnaryNode::dump(int indent)
115{
116    const char *name = js_CodeName[getOp()];
117    fprintf(stderr, "(%s ", name);
118    indent += strlen(name) + 2;
119    DumpParseTree(pn_kid, indent);
120    fprintf(stderr, ")");
121}
122
123inline void
124BinaryNode::dump(int indent)
125{
126    const char *name = js_CodeName[getOp()];
127    fprintf(stderr, "(%s ", name);
128    indent += strlen(name) + 2;
129    DumpParseTree(pn_left, indent);
130    IndentNewLine(indent);
131    DumpParseTree(pn_right, indent);
132    fprintf(stderr, ")");
133}
134
135inline void
136TernaryNode::dump(int indent)
137{
138    const char *name = js_CodeName[getOp()];
139    fprintf(stderr, "(%s ", name);
140    indent += strlen(name) + 2;
141    DumpParseTree(pn_kid1, indent);
142    IndentNewLine(indent);
143    DumpParseTree(pn_kid2, indent);
144    IndentNewLine(indent);
145    DumpParseTree(pn_kid3, indent);
146    fprintf(stderr, ")");
147}
148
149inline void
150FunctionNode::dump(int indent)
151{
152    const char *name = js_CodeName[getOp()];
153    fprintf(stderr, "(%s ", name);
154    indent += strlen(name) + 2;
155    DumpParseTree(pn_body, indent);
156    fprintf(stderr, ")");
157}
158
159inline void
160ListNode::dump(int indent)
161{
162    const char *name = js_CodeName[getOp()];
163    fprintf(stderr, "(%s ", name);
164    if (pn_head != NULL) {
165        indent += strlen(name) + 2;
166        DumpParseTree(pn_head, indent);
167        ParseNode *pn = pn_head->pn_next;
168        while (pn != NULL) {
169            IndentNewLine(indent);
170            DumpParseTree(pn, indent);
171            pn = pn->pn_next;
172        }
173    }
174    fprintf(stderr, ")");
175}
176
177inline void
178NameNode::dump(int indent)
179{
180    const char *name = js_CodeName[getOp()];
181    if (isUsed())
182        fprintf(stderr, "(%s)", name);
183    else {
184        fprintf(stderr, "(%s ", name);
185        indent += strlen(name) + 2;
186        DumpParseTree(expr(), indent);
187        fprintf(stderr, ")");
188    }
189}
190#endif
191
192inline void
193NameNode::initCommon(TreeContext *tc)
194{
195    pn_expr = NULL;
196    pn_cookie.makeFree();
197    pn_dflags = (!tc->topStmt || tc->topStmt->type == STMT_BLOCK)
198                ? PND_BLOCKCHILD
199                : 0;
200    pn_blockid = tc->blockid();
201}
202
203} /* namespace js */
204
205#endif /* ParseNode_inl_h__ */