|
1 /* |
|
2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * 1. Redistributions of source code must retain the above copyright |
|
8 * notice, this list of conditions and the following disclaimer. |
|
9 * 2. Redistributions in binary form must reproduce the above copyright |
|
10 * notice, this list of conditions and the following disclaimer in the |
|
11 * documentation and/or other materials provided with the distribution. |
|
12 * |
|
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
|
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
|
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
|
23 * THE POSSIBILITY OF SUCH DAMAGE. |
|
24 */ |
|
25 |
|
26 #ifndef SyntaxChecker_h |
|
27 #define SyntaxChecker_h |
|
28 |
|
29 namespace JSC { |
|
30 class SyntaxChecker { |
|
31 public: |
|
32 SyntaxChecker(JSGlobalData* , Lexer*) |
|
33 { |
|
34 } |
|
35 |
|
36 typedef SyntaxChecker FunctionBodyBuilder; |
|
37 |
|
38 typedef int Expression; |
|
39 typedef int SourceElements; |
|
40 typedef int Arguments; |
|
41 typedef int Comma; |
|
42 struct Property { |
|
43 ALWAYS_INLINE Property(void* = 0) |
|
44 : type((PropertyNode::Type)0) |
|
45 { |
|
46 } |
|
47 ALWAYS_INLINE Property(const Identifier* ident, PropertyNode::Type ty) |
|
48 : name(ident) |
|
49 , type(ty) |
|
50 { |
|
51 } |
|
52 ALWAYS_INLINE Property(PropertyNode::Type ty) |
|
53 : name(0) |
|
54 , type(ty) |
|
55 { |
|
56 } |
|
57 ALWAYS_INLINE bool operator!() { return !type; } |
|
58 const Identifier* name; |
|
59 PropertyNode::Type type; |
|
60 }; |
|
61 typedef int PropertyList; |
|
62 typedef int ElementList; |
|
63 typedef int ArgumentsList; |
|
64 typedef int FormalParameterList; |
|
65 typedef int FunctionBody; |
|
66 typedef int Statement; |
|
67 typedef int ClauseList; |
|
68 typedef int Clause; |
|
69 typedef int ConstDeclList; |
|
70 typedef int BinaryOperand; |
|
71 |
|
72 static const bool CreatesAST = false; |
|
73 |
|
74 int createSourceElements() { return 1; } |
|
75 int makeFunctionCallNode(int, int, int, int, int) { return 1; } |
|
76 void appendToComma(int, int) { } |
|
77 int createCommaExpr(int, int) { return 1; } |
|
78 int makeAssignNode(int, Operator, int, bool, bool, int, int, int) { return 1; } |
|
79 int makePrefixNode(int, Operator, int, int, int) { return 1; } |
|
80 int makePostfixNode(int, Operator, int, int, int) { return 1; } |
|
81 int makeTypeOfNode(int) { return 1; } |
|
82 int makeDeleteNode(int, int, int, int) { return 1; } |
|
83 int makeNegateNode(int) { return 1; } |
|
84 int makeBitwiseNotNode(int) { return 1; } |
|
85 int createLogicalNot(int) { return 1; } |
|
86 int createUnaryPlus(int) { return 1; } |
|
87 int createVoid(int) { return 1; } |
|
88 int thisExpr() { return 1; } |
|
89 int createResolve(const Identifier*, int) { return 1; } |
|
90 int createObjectLiteral() { return 1; } |
|
91 int createObjectLiteral(int) { return 1; } |
|
92 int createArray(int) { return 1; } |
|
93 int createArray(int, int) { return 1; } |
|
94 int createNumberExpr(double) { return 1; } |
|
95 int createString(const Identifier*) { return 1; } |
|
96 int createBoolean(bool) { return 1; } |
|
97 int createNull() { return 1; } |
|
98 int createBracketAccess(int, int, bool, int, int, int) { return 1; } |
|
99 int createDotAccess(int, const Identifier&, int, int, int) { return 1; } |
|
100 int createRegex(const Identifier&, const Identifier&, int) { return 1; } |
|
101 int createNewExpr(int, int, int, int, int) { return 1; } |
|
102 int createNewExpr(int, int, int) { return 1; } |
|
103 int createConditionalExpr(int, int, int) { return 1; } |
|
104 int createAssignResolve(const Identifier&, int, bool, int, int, int) { return 1; } |
|
105 int createFunctionExpr(const Identifier*, int, int, int, int, int, int) { return 1; } |
|
106 int createFunctionBody() { return 1; } |
|
107 int createArguments() { return 1; } |
|
108 int createArguments(int) { return 1; } |
|
109 int createArgumentsList(int) { return 1; } |
|
110 int createArgumentsList(int, int) { return 1; } |
|
111 template <bool complete> Property createProperty(const Identifier* name, int, PropertyNode::Type type) |
|
112 { |
|
113 ASSERT(name); |
|
114 if (!complete) |
|
115 return Property(type); |
|
116 return Property(name, type); |
|
117 } |
|
118 template <bool complete> Property createProperty(JSGlobalData* globalData, double name, int, PropertyNode::Type type) |
|
119 { |
|
120 if (!complete) |
|
121 return Property(type); |
|
122 return Property(&globalData->parser->arena().identifierArena().makeNumericIdentifier(globalData, name), type); |
|
123 } |
|
124 int createPropertyList(Property) { return 1; } |
|
125 int createPropertyList(Property, int) { return 1; } |
|
126 int createElementList(int, int) { return 1; } |
|
127 int createElementList(int, int, int) { return 1; } |
|
128 int createFormalParameterList(const Identifier&) { return 1; } |
|
129 int createFormalParameterList(int, const Identifier&) { return 1; } |
|
130 int createClause(int, int) { return 1; } |
|
131 int createClauseList(int) { return 1; } |
|
132 int createClauseList(int, int) { return 1; } |
|
133 void setUsesArguments(int) { } |
|
134 int createFuncDeclStatement(const Identifier*, int, int, int, int, int, int) { return 1; } |
|
135 int createBlockStatement(int, int, int) { return 1; } |
|
136 int createExprStatement(int, int, int) { return 1; } |
|
137 int createIfStatement(int, int, int, int) { return 1; } |
|
138 int createIfStatement(int, int, int, int, int) { return 1; } |
|
139 int createForLoop(int, int, int, int, bool, int, int) { return 1; } |
|
140 int createForInLoop(const Identifier*, int, int, int, int, int, int, int, int, int, int) { return 1; } |
|
141 int createForInLoop(int, int, int, int, int, int, int, int) { return 1; } |
|
142 int createEmptyStatement() { return 1; } |
|
143 int createVarStatement(int, int, int) { return 1; } |
|
144 int createReturnStatement(int, int, int, int, int) { return 1; } |
|
145 int createBreakStatement(int, int, int, int) { return 1; } |
|
146 int createBreakStatement(const Identifier*, int, int, int, int) { return 1; } |
|
147 int createContinueStatement(int, int, int, int) { return 1; } |
|
148 int createContinueStatement(const Identifier*, int, int, int, int) { return 1; } |
|
149 int createTryStatement(int, const Identifier*, bool, int, int, int, int) { return 1; } |
|
150 int createSwitchStatement(int, int, int, int, int, int) { return 1; } |
|
151 int createWhileStatement(int, int, int, int) { return 1; } |
|
152 int createWithStatement(int, int, int, int, int, int) { return 1; } |
|
153 int createDoWhileStatement(int, int, int, int) { return 1; } |
|
154 int createLabelStatement(const Identifier*, int, int, int) { return 1; } |
|
155 int createThrowStatement(int, int, int, int, int) { return 1; } |
|
156 int createDebugger(int, int) { return 1; } |
|
157 int createConstStatement(int, int, int) { return 1; } |
|
158 int appendConstDecl(int, const Identifier*, int) { return 1; } |
|
159 template <bool strict> Property createGetterOrSetterProperty(PropertyNode::Type type, const Identifier* name, int, int, int, int, int, int) |
|
160 { |
|
161 ASSERT(name); |
|
162 if (!strict) |
|
163 return Property(type); |
|
164 return Property(name, type); |
|
165 } |
|
166 |
|
167 void appendStatement(int, int) { } |
|
168 void addVar(const Identifier*, bool) { } |
|
169 int combineCommaNodes(int, int) { return 1; } |
|
170 int evalCount() const { return 0; } |
|
171 void appendBinaryExpressionInfo(int& operandStackDepth, int, int, int, int, bool) { operandStackDepth++; } |
|
172 |
|
173 // Logic to handle datastructures used during parsing of binary expressions |
|
174 void operatorStackPop(int& operatorStackDepth) { operatorStackDepth--; } |
|
175 bool operatorStackHasHigherPrecedence(int&, int) { return true; } |
|
176 BinaryOperand getFromOperandStack(int) { return 1; } |
|
177 void shrinkOperandStackBy(int& operandStackDepth, int amount) { operandStackDepth -= amount; } |
|
178 void appendBinaryOperation(int& operandStackDepth, int&, BinaryOperand, BinaryOperand) { operandStackDepth++; } |
|
179 void operatorStackAppend(int& operatorStackDepth, int, int) { operatorStackDepth++; } |
|
180 int popOperandStack(int&) { return 1; } |
|
181 |
|
182 void appendUnaryToken(int&, int, int) { } |
|
183 int unaryTokenStackLastType(int&) { ASSERT_NOT_REACHED(); return 1; } |
|
184 int unaryTokenStackLastStart(int&) { ASSERT_NOT_REACHED(); return 1; } |
|
185 void unaryTokenStackRemoveLast(int&) { } |
|
186 |
|
187 void assignmentStackAppend(int, int, int, int, int, Operator) { } |
|
188 int createAssignment(int, int, int, int, int) { ASSERT_NOT_REACHED(); return 1; } |
|
189 const Identifier& getName(const Property& property) { ASSERT(property.name); return *property.name; } |
|
190 PropertyNode::Type getType(const Property& property) { return property.type; } |
|
191 }; |
|
192 |
|
193 } |
|
194 |
|
195 #endif |