Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.8 KiB

  1. /*++
  2. Copyright Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. SQL_1.H
  5. Abstract:
  6. Level 1 Syntax SQL Parser
  7. History:
  8. --*/
  9. #ifndef _SQL_1_H_
  10. #define _SQL_1_H_
  11. struct SQL_LEVEL_1_TOKEN
  12. {
  13. enum { OP_EXPRESSION = 1, TOKEN_AND, TOKEN_OR, TOKEN_NOT };
  14. enum { IFUNC_NONE = 0, IFUNC_UPPER = 1, IFUNC_LOWER = 2 };
  15. int nTokenType; // OP_EXPRESSION,TOKEN_AND, TOKEN_OR, TOKEN_NOT
  16. // If the field is a OP_EXPRESSION, then the following are used.
  17. enum { OP_EQUAL = 1, OP_NOT_EQUAL, OP_EQUALorGREATERTHAN,
  18. OP_EQUALorLESSTHAN, OP_LESSTHAN, OP_GREATERTHAN, OP_LIKE };
  19. BSTR pPropertyName; // Name of the property on which the operator is applied
  20. int nOperator; // Operator that is applied on property
  21. BOOL bConstIsStrNumeric; // True if the vConstValue is a BSTR and is a UINT32 or any 64bit number
  22. VARIANT vConstValue; // Value applied by operator
  23. BSTR pPropName2; // Property compared to.
  24. DWORD dwPropertyFunction; // 0=no instrinsic function applied
  25. DWORD dwConstFunction; // "
  26. SQL_LEVEL_1_TOKEN();
  27. SQL_LEVEL_1_TOKEN(SQL_LEVEL_1_TOKEN&);
  28. ~SQL_LEVEL_1_TOKEN();
  29. SQL_LEVEL_1_TOKEN& operator=(SQL_LEVEL_1_TOKEN &Src);
  30. void Dump(FILE *);
  31. };
  32. // Contains RPN version of expression.
  33. // ===================================
  34. struct SQL_LEVEL_1_RPN_EXPRESSION
  35. {
  36. int nNumTokens;
  37. int nCurSize;
  38. SQL_LEVEL_1_TOKEN *pArrayOfTokens;
  39. BSTR bsClassName;
  40. int nNumberOfProperties; // Zero means all properties selected
  41. int nCurPropSize;
  42. BSTR *pbsRequestedPropertyNames; // Array of property names which values are to be returned if
  43. SQL_LEVEL_1_RPN_EXPRESSION();
  44. ~SQL_LEVEL_1_RPN_EXPRESSION();
  45. //Note: this method deletes the token it is passed as an argument
  46. void AddToken(SQL_LEVEL_1_TOKEN *pTok);
  47. void AddToken(SQL_LEVEL_1_TOKEN &pTok);
  48. void AddProperty(LPWSTR pProp);
  49. void Dump(const char *pszTextFile);
  50. };
  51. class SQL1_Parser
  52. {
  53. CGenLexer *m_pLexer;
  54. int m_nLine;
  55. wchar_t* m_pTokenText;
  56. int m_nCurrentToken;
  57. SQL_LEVEL_1_RPN_EXPRESSION* m_pExpression;
  58. //Cleanup used by d'tor and SetSource
  59. void Cleanup();
  60. //Init used by c'tor and SetSource
  61. void Init(CGenLexSource *pSrc);
  62. // Semantic transfer variables.
  63. // ============================
  64. VARIANT m_vTypedConst;
  65. int m_nRelOp;
  66. DWORD m_dwConstFunction;
  67. DWORD m_dwPropFunction;
  68. LPWSTR m_pIdent;
  69. LPWSTR m_pPropComp;
  70. BOOL m_bConstIsStrNumeric;
  71. // Parsing functions.
  72. // ==================
  73. BOOL Next();
  74. int parse();
  75. int prop_list();
  76. int class_name();
  77. int opt_where();
  78. int expr();
  79. int property_name();
  80. int prop_list_2();
  81. int term();
  82. int expr2();
  83. int simple_expr();
  84. int term2();
  85. int leading_ident_expr();
  86. int finalize();
  87. int rel_operator();
  88. int equiv_operator();
  89. int comp_operator();
  90. int is_operator();
  91. int trailing_prop_expr();
  92. int trailing_prop_expr2();
  93. int trailing_or_null();
  94. int trailing_const_expr();
  95. int unknown_func_expr();
  96. int typed_constant();
  97. public:
  98. enum {
  99. SUCCESS,
  100. SYNTAX_ERROR,
  101. LEXICAL_ERROR,
  102. FAILED,
  103. BUFFER_TOO_SMALL
  104. };
  105. SQL1_Parser(CGenLexSource *pSrc);
  106. ~SQL1_Parser();
  107. int GetQueryClass(LPWSTR pBuf, int nBufSize);
  108. int Parse(SQL_LEVEL_1_RPN_EXPRESSION **pOutput);
  109. // use operator delete on pOutput
  110. int CurrentLine() { return m_nLine; }
  111. LPWSTR CurrentToken() { return m_pTokenText; }
  112. void SetSource(CGenLexSource *pSrc);
  113. };
  114. #endif