/src/3rdparty/webkit/Source/JavaScriptCore/parser/JSParser.h

https://bitbucket.org/ultra_iter/qt-vtl · C Header · 164 lines · 127 code · 12 blank · 25 comment · 0 complexity · 5779a0164e69609f0575744e0c9b0116 MD5 · raw file

  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. #ifndef JSParser_h
  26. #define JSParser_h
  27. namespace JSC {
  28. class ExecState;
  29. class FunctionParameters;
  30. class Identifier;
  31. class JSGlobalData;
  32. class SourceCode;
  33. enum {
  34. UnaryOpTokenFlag = 64,
  35. KeywordTokenFlag = 128,
  36. BinaryOpTokenPrecedenceShift = 8,
  37. BinaryOpTokenAllowsInPrecedenceAdditionalShift = 4,
  38. BinaryOpTokenPrecedenceMask = 15 << BinaryOpTokenPrecedenceShift,
  39. };
  40. #define BINARY_OP_PRECEDENCE(prec) (((prec) << BinaryOpTokenPrecedenceShift) | ((prec) << (BinaryOpTokenPrecedenceShift + BinaryOpTokenAllowsInPrecedenceAdditionalShift)))
  41. #define IN_OP_PRECEDENCE(prec) ((prec) << (BinaryOpTokenPrecedenceShift + BinaryOpTokenAllowsInPrecedenceAdditionalShift))
  42. enum JSTokenType {
  43. NULLTOKEN = KeywordTokenFlag,
  44. TRUETOKEN,
  45. FALSETOKEN,
  46. BREAK,
  47. CASE,
  48. DEFAULT,
  49. FOR,
  50. NEW,
  51. VAR,
  52. CONSTTOKEN,
  53. CONTINUE,
  54. FUNCTION,
  55. RETURN,
  56. IF,
  57. THISTOKEN,
  58. DO,
  59. WHILE,
  60. SWITCH,
  61. WITH,
  62. RESERVED,
  63. THROW,
  64. TRY,
  65. CATCH,
  66. FINALLY,
  67. DEBUGGER,
  68. ELSE,
  69. OPENBRACE = 0,
  70. CLOSEBRACE,
  71. OPENPAREN,
  72. CLOSEPAREN,
  73. OPENBRACKET,
  74. CLOSEBRACKET,
  75. COMMA,
  76. QUESTION,
  77. NUMBER,
  78. IDENT,
  79. STRING,
  80. SEMICOLON,
  81. COLON,
  82. DOT,
  83. ERRORTOK,
  84. EOFTOK,
  85. EQUAL,
  86. PLUSEQUAL,
  87. MINUSEQUAL,
  88. MULTEQUAL,
  89. DIVEQUAL,
  90. LSHIFTEQUAL,
  91. RSHIFTEQUAL,
  92. URSHIFTEQUAL,
  93. ANDEQUAL,
  94. MODEQUAL,
  95. XOREQUAL,
  96. OREQUAL,
  97. LastUntaggedToken,
  98. // Begin tagged tokens
  99. PLUSPLUS = 0 | UnaryOpTokenFlag,
  100. MINUSMINUS = 1 | UnaryOpTokenFlag,
  101. EXCLAMATION = 2 | UnaryOpTokenFlag,
  102. TILDE = 3 | UnaryOpTokenFlag,
  103. AUTOPLUSPLUS = 4 | UnaryOpTokenFlag,
  104. AUTOMINUSMINUS = 5 | UnaryOpTokenFlag,
  105. TYPEOF = 6 | UnaryOpTokenFlag | KeywordTokenFlag,
  106. VOIDTOKEN = 7 | UnaryOpTokenFlag | KeywordTokenFlag,
  107. DELETETOKEN = 8 | UnaryOpTokenFlag | KeywordTokenFlag,
  108. OR = 0 | BINARY_OP_PRECEDENCE(1),
  109. AND = 1 | BINARY_OP_PRECEDENCE(2),
  110. BITOR = 2 | BINARY_OP_PRECEDENCE(3),
  111. BITXOR = 3 | BINARY_OP_PRECEDENCE(4),
  112. BITAND = 4 | BINARY_OP_PRECEDENCE(5),
  113. EQEQ = 5 | BINARY_OP_PRECEDENCE(6),
  114. NE = 6 | BINARY_OP_PRECEDENCE(6),
  115. STREQ = 7 | BINARY_OP_PRECEDENCE(6),
  116. STRNEQ = 8 | BINARY_OP_PRECEDENCE(6),
  117. LT = 9 | BINARY_OP_PRECEDENCE(7),
  118. GT = 10 | BINARY_OP_PRECEDENCE(7),
  119. LE = 11 | BINARY_OP_PRECEDENCE(7),
  120. GE = 12 | BINARY_OP_PRECEDENCE(7),
  121. INSTANCEOF = 13 | BINARY_OP_PRECEDENCE(7) | KeywordTokenFlag,
  122. INTOKEN = 14 | IN_OP_PRECEDENCE(7) | KeywordTokenFlag,
  123. LSHIFT = 15 | BINARY_OP_PRECEDENCE(8),
  124. RSHIFT = 16 | BINARY_OP_PRECEDENCE(8),
  125. URSHIFT = 17 | BINARY_OP_PRECEDENCE(8),
  126. PLUS = 18 | BINARY_OP_PRECEDENCE(9) | UnaryOpTokenFlag,
  127. MINUS = 19 | BINARY_OP_PRECEDENCE(9) | UnaryOpTokenFlag,
  128. TIMES = 20 | BINARY_OP_PRECEDENCE(10),
  129. DIVIDE = 21 | BINARY_OP_PRECEDENCE(10),
  130. MOD = 22 | BINARY_OP_PRECEDENCE(10)
  131. };
  132. union JSTokenData {
  133. int intValue;
  134. double doubleValue;
  135. const Identifier* ident;
  136. };
  137. struct JSTokenInfo {
  138. JSTokenInfo() : line(0) {}
  139. int line;
  140. int startOffset;
  141. int endOffset;
  142. };
  143. struct JSToken {
  144. JSTokenType m_type;
  145. JSTokenData m_data;
  146. JSTokenInfo m_info;
  147. };
  148. enum JSParserStrictness { JSParseNormal, JSParseStrict };
  149. enum JSParserMode { JSParseProgramCode, JSParseFunctionCode };
  150. const char* jsParse(JSGlobalData*, FunctionParameters*, JSParserStrictness, JSParserMode, const SourceCode*);
  151. }
  152. #endif // JSParser_h