X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/4be4e30906bcb8ee30b4d189205cb70bad6707ce..81345200c95645a1b0d2635520f96ad55dfde63f:/parser/SyntaxChecker.h?ds=sidebyside diff --git a/parser/SyntaxChecker.h b/parser/SyntaxChecker.h index 7f902c0..8912d8b 100644 --- a/parser/SyntaxChecker.h +++ b/parser/SyntaxChecker.h @@ -27,7 +27,7 @@ #define SyntaxChecker_h #include "Lexer.h" -#include +#include "YarrSyntaxChecker.h" namespace JSC { @@ -75,7 +75,13 @@ public: FunctionExpr, BracketExpr, DotExpr, CallExpr, NewExpr, PreExpr, PostExpr, UnaryExpr, BinaryExpr, ConditionalExpr, AssignmentExpr, TypeofExpr, - DeleteExpr, ArrayLiteralExpr }; + DeleteExpr, ArrayLiteralExpr, BindingDeconstruction, + ArrayDeconstruction, ObjectDeconstruction, SourceElementsResult, + FunctionBodyResult, SpreadExpr, ArgumentsResult, + PropertyListResult, ArgumentsListResult, ElementsListResult, + StatementResult, FormalParameterListResult, ClauseResult, + ClauseListResult, CommaExpr, DeconstructingAssignment + }; typedef int ExpressionType; typedef ExpressionType Expression; @@ -88,8 +94,8 @@ public: { } ALWAYS_INLINE Property(const Identifier* ident, PropertyNode::Type ty) - : name(ident) - , type(ty) + : name(ident) + , type(ty) { } ALWAYS_INLINE Property(PropertyNode::Type ty) @@ -111,29 +117,32 @@ public: typedef int Clause; typedef int ConstDeclList; typedef int BinaryOperand; - + typedef int DeconstructionPattern; + typedef DeconstructionPattern ArrayPattern; + typedef DeconstructionPattern ObjectPattern; + static const bool CreatesAST = false; static const bool NeedsFreeVariableInfo = false; static const bool CanUseFunctionCache = true; static const unsigned DontBuildKeywords = LexexFlagsDontBuildKeywords; static const unsigned DontBuildStrings = LexerFlagsDontBuildStrings; - int createSourceElements() { return 1; } - ExpressionType makeFunctionCallNode(const JSTokenLocation&, int, int, int, int, int, int, int) { return CallExpr; } + int createSourceElements() { return SourceElementsResult; } + ExpressionType makeFunctionCallNode(const JSTokenLocation&, int, int, int, int, int) { return CallExpr; } void appendToComma(ExpressionType& base, ExpressionType right) { base = right; } ExpressionType createCommaExpr(const JSTokenLocation&, ExpressionType, ExpressionType right) { return right; } - ExpressionType makeAssignNode(const JSTokenLocation&, ExpressionType, Operator, ExpressionType, bool, bool, int, int, int, int, int) { return AssignmentExpr; } - ExpressionType makePrefixNode(const JSTokenLocation&, ExpressionType, Operator, int, int, int, int, int) { return PreExpr; } - ExpressionType makePostfixNode(const JSTokenLocation&, ExpressionType, Operator, int, int, int, int, int) { return PostExpr; } + ExpressionType makeAssignNode(const JSTokenLocation&, ExpressionType, Operator, ExpressionType, bool, bool, int, int, int) { return AssignmentExpr; } + ExpressionType makePrefixNode(const JSTokenLocation&, ExpressionType, Operator, int, int, int) { return PreExpr; } + ExpressionType makePostfixNode(const JSTokenLocation&, ExpressionType, Operator, int, int, int) { return PostExpr; } ExpressionType makeTypeOfNode(const JSTokenLocation&, ExpressionType) { return TypeofExpr; } - ExpressionType makeDeleteNode(const JSTokenLocation&, ExpressionType, int, int, int, int, int) { return DeleteExpr; } + ExpressionType makeDeleteNode(const JSTokenLocation&, ExpressionType, int, int, int) { return DeleteExpr; } ExpressionType makeNegateNode(const JSTokenLocation&, ExpressionType) { return UnaryExpr; } ExpressionType makeBitwiseNotNode(const JSTokenLocation&, ExpressionType) { return UnaryExpr; } ExpressionType createLogicalNot(const JSTokenLocation&, ExpressionType) { return UnaryExpr; } ExpressionType createUnaryPlus(const JSTokenLocation&, ExpressionType) { return UnaryExpr; } ExpressionType createVoid(const JSTokenLocation&, ExpressionType) { return UnaryExpr; } ExpressionType thisExpr(const JSTokenLocation&) { return ThisExpr; } - ExpressionType createResolve(const JSTokenLocation&, const Identifier*, int, int, int) { return ResolveExpr; } + ExpressionType createResolve(const JSTokenLocation&, const Identifier*, int) { return ResolveExpr; } ExpressionType createObjectLiteral(const JSTokenLocation&) { return ObjectLiteralExpr; } ExpressionType createObjectLiteral(const JSTokenLocation&, int) { return ObjectLiteralExpr; } ExpressionType createArray(const JSTokenLocation&, int) { return ArrayLiteralExpr; } @@ -142,76 +151,81 @@ public: ExpressionType createString(const JSTokenLocation&, const Identifier*) { return StringExpr; } ExpressionType createBoolean(const JSTokenLocation&, bool) { return BoolExpr; } ExpressionType createNull(const JSTokenLocation&) { return NullExpr; } - ExpressionType createBracketAccess(const JSTokenLocation&, ExpressionType, ExpressionType, bool, int, int, int, int, int) { return BracketExpr; } - ExpressionType createDotAccess(const JSTokenLocation&, ExpressionType, const Identifier*, int, int, int, int, int) { return DotExpr; } - ExpressionType createRegExp(const JSTokenLocation&, const Identifier& pattern, const Identifier&, int, int, int) { return Yarr::checkSyntax(pattern.string()) ? 0 : RegExpExpr; } - ExpressionType createNewExpr(const JSTokenLocation&, ExpressionType, int, int, int, int, int, int) { return NewExpr; } + ExpressionType createBracketAccess(const JSTokenLocation&, ExpressionType, ExpressionType, bool, int, int, int) { return BracketExpr; } + ExpressionType createDotAccess(const JSTokenLocation&, ExpressionType, const Identifier*, int, int, int) { return DotExpr; } + ExpressionType createRegExp(const JSTokenLocation&, const Identifier& pattern, const Identifier&, int) { return Yarr::checkSyntax(pattern.string()) ? 0 : RegExpExpr; } ExpressionType createNewExpr(const JSTokenLocation&, ExpressionType, int, int, int, int) { return NewExpr; } + ExpressionType createNewExpr(const JSTokenLocation&, ExpressionType, int, int) { return NewExpr; } ExpressionType createConditionalExpr(const JSTokenLocation&, ExpressionType, ExpressionType, ExpressionType) { return ConditionalExpr; } - ExpressionType createAssignResolve(const JSTokenLocation&, const Identifier&, ExpressionType, int, int, int, int, int) { return AssignmentExpr; } + ExpressionType createAssignResolve(const JSTokenLocation&, const Identifier&, ExpressionType, int, int, int) { return AssignmentExpr; } ExpressionType createFunctionExpr(const JSTokenLocation&, const Identifier*, int, int, int, int, int, int, int) { return FunctionExpr; } - int createFunctionBody(const JSTokenLocation&, const JSTokenLocation&, int, bool) { return 1; } - void setFunctionStart(int, int) { } - int createArguments() { return 1; } - int createArguments(int) { return 1; } - int createArgumentsList(const JSTokenLocation&, int) { return 1; } - int createArgumentsList(const JSTokenLocation&, int, int) { return 1; } - template Property createProperty(const Identifier* name, int, PropertyNode::Type type) + int createFunctionBody(const JSTokenLocation&, const JSTokenLocation&, int, int, bool) { return FunctionBodyResult; } + void setFunctionNameStart(int, int) { } + int createArguments() { return ArgumentsResult; } + int createArguments(int) { return ArgumentsResult; } + ExpressionType createSpreadExpression(const JSTokenLocation&, ExpressionType, int, int, int) { return SpreadExpr; } + int createArgumentsList(const JSTokenLocation&, int) { return ArgumentsListResult; } + int createArgumentsList(const JSTokenLocation&, int, int) { return ArgumentsListResult; } + Property createProperty(const Identifier* name, int, PropertyNode::Type type, bool complete) { if (!complete) return Property(type); ASSERT(name); return Property(name, type); } - template Property createProperty(VM* vm, double name, int, PropertyNode::Type type) + Property createProperty(VM* vm, double name, int, PropertyNode::Type type, bool complete) { if (!complete) return Property(type); return Property(&vm->parserArena->identifierArena().makeNumericIdentifier(vm, name), type); } - int createPropertyList(const JSTokenLocation&, Property) { return 1; } - int createPropertyList(const JSTokenLocation&, Property, int) { return 1; } - int createElementList(int, int) { return 1; } - int createElementList(int, int, int) { return 1; } - int createFormalParameterList(const Identifier&) { return 1; } - int createFormalParameterList(int, const Identifier&) { return 1; } - int createClause(int, int) { return 1; } - int createClauseList(int) { return 1; } - int createClauseList(int, int) { return 1; } + Property createProperty(VM*, ExpressionNode*, int, PropertyNode::Type type, bool) + { + return Property(type); + } + int createPropertyList(const JSTokenLocation&, Property) { return PropertyListResult; } + int createPropertyList(const JSTokenLocation&, Property, int) { return PropertyListResult; } + int createElementList(int, int) { return ElementsListResult; } + int createElementList(int, int, int) { return ElementsListResult; } + int createFormalParameterList(DeconstructionPattern) { return FormalParameterListResult; } + int createFormalParameterList(int, DeconstructionPattern) { return FormalParameterListResult; } + int createClause(int, int) { return ClauseResult; } + int createClauseList(int) { return ClauseListResult; } + int createClauseList(int, int) { return ClauseListResult; } void setUsesArguments(int) { } - int createFuncDeclStatement(const JSTokenLocation&, const Identifier*, int, int, int, int, int, int, int) { return 1; } - int createBlockStatement(const JSTokenLocation&, int, int, int) { return 1; } - int createExprStatement(const JSTokenLocation&, int, int, int) { return 1; } - int createIfStatement(const JSTokenLocation&, int, int, int, int) { return 1; } - int createIfStatement(const JSTokenLocation&, int, int, int, int, int) { return 1; } - int createForLoop(const JSTokenLocation&, int, int, int, int, int, int) { return 1; } - int createForInLoop(const JSTokenLocation&, const Identifier*, int, int, int, int, int, int, int, int, int, int, int, int) { return 1; } - int createForInLoop(const JSTokenLocation&, int, int, int, int, int, int, int, int, int, int) { return 1; } - int createEmptyStatement(const JSTokenLocation&) { return 1; } - int createVarStatement(const JSTokenLocation&, int, int, int) { return 1; } - int createReturnStatement(const JSTokenLocation&, int, int, int, int, int, int, int) { return 1; } - int createBreakStatement(const JSTokenLocation&, int, int, int, int, int) { return 1; } - int createBreakStatement(const JSTokenLocation&, const Identifier*, int, int, int, int, int) { return 1; } - int createContinueStatement(const JSTokenLocation&, int, int, int, int, int) { return 1; } - int createContinueStatement(const JSTokenLocation&, const Identifier*, int, int, int, int, int) { return 1; } - int createTryStatement(const JSTokenLocation&, int, const Identifier*, int, int, int, int) { return 1; } - int createSwitchStatement(const JSTokenLocation&, int, int, int, int, int, int) { return 1; } - int createWhileStatement(const JSTokenLocation&, int, int, int, int) { return 1; } - int createWithStatement(const JSTokenLocation&, int, int, int, int, int, int, int, int) { return 1; } - int createDoWhileStatement(const JSTokenLocation&, int, int, int, int) { return 1; } - int createLabelStatement(const JSTokenLocation&, const Identifier*, int, int, int, int, int) { return 1; } - int createThrowStatement(const JSTokenLocation&, int, int, int, int, int, int, int) { return 1; } - int createDebugger(const JSTokenLocation&, int, int) { return 1; } - int createConstStatement(const JSTokenLocation&, int, int, int) { return 1; } - int appendConstDecl(const JSTokenLocation&, int, const Identifier*, int) { return 1; } - template Property createGetterOrSetterProperty(const JSTokenLocation&, PropertyNode::Type type, const Identifier* name, int, int, int, int, int, int, int) + int createFuncDeclStatement(const JSTokenLocation&, const Identifier*, int, int, int, int, int, int, int) { return StatementResult; } + int createBlockStatement(const JSTokenLocation&, int, int, int) { return StatementResult; } + int createExprStatement(const JSTokenLocation&, int, int, int) { return StatementResult; } + int createIfStatement(const JSTokenLocation&, int, int, int, int) { return StatementResult; } + int createIfStatement(const JSTokenLocation&, int, int, int, int, int) { return StatementResult; } + int createForLoop(const JSTokenLocation&, int, int, int, int, int, int) { return StatementResult; } + int createForInLoop(const JSTokenLocation&, int, int, int, int, int, int, int, int) { return StatementResult; } + int createForOfLoop(const JSTokenLocation&, int, int, int, int, int, int, int, int) { return StatementResult; } + int createEmptyStatement(const JSTokenLocation&) { return StatementResult; } + int createVarStatement(const JSTokenLocation&, int, int, int) { return StatementResult; } + int createReturnStatement(const JSTokenLocation&, int, int, int) { return StatementResult; } + int createBreakStatement(const JSTokenLocation&, int, int) { return StatementResult; } + int createBreakStatement(const JSTokenLocation&, const Identifier*, int, int) { return StatementResult; } + int createContinueStatement(const JSTokenLocation&, int, int) { return StatementResult; } + int createContinueStatement(const JSTokenLocation&, const Identifier*, int, int) { return StatementResult; } + int createTryStatement(const JSTokenLocation&, int, const Identifier*, int, int, int, int) { return StatementResult; } + int createSwitchStatement(const JSTokenLocation&, int, int, int, int, int, int) { return StatementResult; } + int createWhileStatement(const JSTokenLocation&, int, int, int, int) { return StatementResult; } + int createWithStatement(const JSTokenLocation&, int, int, int, int, int, int) { return StatementResult; } + int createDoWhileStatement(const JSTokenLocation&, int, int, int, int) { return StatementResult; } + int createLabelStatement(const JSTokenLocation&, const Identifier*, int, int, int) { return StatementResult; } + int createThrowStatement(const JSTokenLocation&, int, int, int) { return StatementResult; } + int createDebugger(const JSTokenLocation&, int, int) { return StatementResult; } + int createConstStatement(const JSTokenLocation&, int, int, int) { return StatementResult; } + int appendConstDecl(const JSTokenLocation&, int, const Identifier*, int) { return StatementResult; } + Property createGetterOrSetterProperty(const JSTokenLocation&, PropertyNode::Type type, bool strict, const Identifier* name, int, int, int, int, int, int, int) { ASSERT(name); if (!strict) return Property(type); return Property(name, type); } - template Property createGetterOrSetterProperty(VM* vm, const JSTokenLocation&, PropertyNode::Type type, double name, int, int, int, int, int, int, int) + Property createGetterOrSetterProperty(VM* vm, const JSTokenLocation&, PropertyNode::Type type, bool strict, double name, int, int, int, int, int, int, int) { if (!strict) return Property(type); @@ -220,9 +234,9 @@ public: void appendStatement(int, int) { } void addVar(const Identifier*, bool) { } - int combineCommaNodes(const JSTokenLocation&, int, int) { return 1; } + int combineCommaNodes(const JSTokenLocation&, int, int) { return CommaExpr; } int evalCount() const { return 0; } - void appendBinaryExpressionInfo(int& operandStackDepth, int expr, int, int, int, int, int, bool) + void appendBinaryExpressionInfo(int& operandStackDepth, int expr, int, int, int, bool) { if (!m_topBinaryExpr) m_topBinaryExpr = expr; @@ -240,18 +254,48 @@ public: void operatorStackAppend(int& operatorStackDepth, int, int) { operatorStackDepth++; } int popOperandStack(int&) { int res = m_topBinaryExpr; m_topBinaryExpr = 0; return res; } - void appendUnaryToken(int& stackDepth, int tok, int, int, int) { stackDepth = 1; m_topUnaryToken = tok; } + void appendUnaryToken(int& stackDepth, int tok, int) { stackDepth = 1; m_topUnaryToken = tok; } int unaryTokenStackLastType(int&) { return m_topUnaryToken; } - unsigned unaryTokenStackLastStart(int&) { return 0; } - unsigned unaryTokenStackLastLineStartPosition(int&) { return 0; } + JSTextPosition unaryTokenStackLastStart(int&) { return JSTextPosition(0, 0, 0); } void unaryTokenStackRemoveLast(int& stackDepth) { stackDepth = 0; } - void assignmentStackAppend(int, int, int, int, int, int, int, Operator) { } - int createAssignment(const JSTokenLocation&, int, int, int, int, int) { RELEASE_ASSERT_NOT_REACHED(); return 1; } - const Identifier& getName(const Property& property) const { ASSERT(property.name); return *property.name; } + void assignmentStackAppend(int, int, int, int, int, Operator) { } + int createAssignment(const JSTokenLocation&, int, int, int, int, int) { RELEASE_ASSERT_NOT_REACHED(); return AssignmentExpr; } + const Identifier* getName(const Property& property) const { ASSERT(property.name); return property.name; } PropertyNode::Type getType(const Property& property) const { return property.type; } bool isResolve(ExpressionType expr) const { return expr == ResolveExpr || expr == ResolveEvalExpr; } + ExpressionType createDeconstructingAssignment(const JSTokenLocation&, int, ExpressionType) + { + return DeconstructingAssignment; + } + ArrayPattern createArrayPattern(const JSTokenLocation&) + { + return ArrayDeconstruction; + } + void appendArrayPatternSkipEntry(ArrayPattern, const JSTokenLocation&) + { + } + void appendArrayPatternEntry(ArrayPattern, const JSTokenLocation&, DeconstructionPattern) + { + } + ObjectPattern createObjectPattern(const JSTokenLocation&) + { + return ObjectDeconstruction; + } + void appendObjectPatternEntry(ArrayPattern, const JSTokenLocation&, bool, const Identifier&, DeconstructionPattern) + { + } + DeconstructionPattern createBindingLocation(const JSTokenLocation&, const Identifier&, const JSTextPosition&, const JSTextPosition&) + { + return BindingDeconstruction; + } + + bool isBindingNode(DeconstructionPattern pattern) + { + return pattern == BindingDeconstruction; + } + private: int m_topBinaryExpr; int m_topUnaryToken;