Source code of Windows XP (NT5)
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.

211 lines
6.2 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. WQL.H
  5. Abstract:
  6. WQL 1.1 Parser
  7. Implements the syntax described in WQL.BNF.
  8. History:
  9. raymcc 19-Sep-97
  10. --*/
  11. #ifndef _WQL__H_
  12. #define _WQL__H_
  13. class CWQLParser
  14. {
  15. // Data.
  16. // =====
  17. CGenLexer *m_pLexer;
  18. int m_nLine;
  19. wchar_t *m_pTokenText;
  20. int m_nCurrentToken;
  21. DWORD m_dwFeaturesFlags;
  22. CWStringArray m_aReferencedTables;
  23. CWStringArray m_aReferencedAliases;
  24. CFlexArray m_aSelAliases;
  25. CFlexArray m_aSelColumns;
  26. SWQLNode_Select *m_pQueryRoot;
  27. SWQLNode_WhereClause *m_pRootWhere;
  28. SWQLNode_ColumnList *m_pRootColList;
  29. SWQLNode_FromClause *m_pRootFrom;
  30. SWQLNode_WhereOptions *m_pRootWhereOptions;
  31. // Parse context. In some cases, there is a general
  32. // shift in state for the whole parser. Rather than
  33. // pass this as an inherited attribute to each production,
  34. // it is much easier to have a general purpose state variable.
  35. // ============================================================
  36. enum { Ctx_Default = 0, Ctx_Subselect = 0x1 };
  37. int m_nParseContext;
  38. bool m_bAllowPromptForConstant;
  39. // Functions.
  40. // ==========
  41. BOOL Next();
  42. LONG GetTokenLong();
  43. int QNameToSWQLColRef(
  44. IN SWQLQualifiedName *pQName,
  45. OUT SWQLColRef **pRetVal
  46. );
  47. enum { eCtxLeftSide = 1, eCtxRightSide = 2 };
  48. // Non-terminal productions.
  49. // =========================
  50. int select_stmt(OUT SWQLNode_Select **pSelStmt);
  51. int select_type(int & nSelType);
  52. int col_ref_list(IN OUT SWQLNode_TableRefs *pTblRefs);
  53. int from_clause(OUT SWQLNode_FromClause **pFrom);
  54. int where_clause(OUT SWQLNode_WhereClause **pRetWhere);
  55. int col_ref(OUT SWQLQualifiedName **pRetVal);
  56. int col_ref_rest(IN OUT SWQLNode_TableRefs *pTblRefs);
  57. int count_clause(
  58. OUT SWQLQualifiedName **pQualName
  59. );
  60. int single_table_decl(OUT SWQLNode_TableRef **pTblRef);
  61. int sql89_join_entry(
  62. IN SWQLNode_TableRef *pInitialTblRef,
  63. OUT SWQLNode_Sql89Join **pJoin );
  64. int sql92_join_entry(
  65. IN SWQLNode_TableRef *pInitialTblRef,
  66. OUT SWQLNode_Join **pJoin
  67. );
  68. int sql89_join_list(
  69. IN SWQLNode_TableRef *pInitialTblRef,
  70. OUT SWQLNode_Sql89Join **pJoin );
  71. int on_clause(OUT SWQLNode_OnClause **pOC);
  72. int rel_expr(OUT SWQLNode_RelExpr **pRelExpr);
  73. int where_options(OUT SWQLNode_WhereOptions **pWhereOpt0);
  74. int group_by_clause(OUT SWQLNode_GroupBy **pRetGroupBy);
  75. int having_clause(OUT SWQLNode_Having **pRetHaving);
  76. int order_by_clause(OUT SWQLNode_OrderBy **pRetOrderBy);
  77. int rel_term(OUT SWQLNode_RelExpr **pNewTerm);
  78. int rel_expr2(
  79. IN OUT SWQLNode_RelExpr *pLeftSide,
  80. OUT SWQLNode_RelExpr **pNewRootRE
  81. );
  82. int rel_simple_expr(OUT SWQLNode_RelExpr **pRelExpr);
  83. int rel_term2(
  84. IN SWQLNode_RelExpr *pLeftSide,
  85. OUT SWQLNode_RelExpr **pNewRootRE
  86. );
  87. int typed_expr(OUT SWQLNode_RelExpr **pRelExpr);
  88. int typed_subexpr_rh(SWQLTypedExpr *pTE);
  89. int typed_subexpr(IN SWQLTypedExpr *pTE);
  90. int typed_const(OUT SWQLTypedConst **pRetVal);
  91. int datepart_call(
  92. OUT SWQLNode_Datepart **pRetDP
  93. );
  94. int function_call(IN BOOL bLeftSide, IN SWQLTypedExpr *pTE);
  95. int function_call_parms();
  96. int func_args();
  97. int func_arg();
  98. int rel_op(int &);
  99. int is_continuator(int &);
  100. int not_continuator(int &);
  101. int in_clause(IN SWQLTypedExpr *pTE);
  102. int subselect_stmt(OUT SWQLNode_Select **pSel);
  103. int qualified_name(OUT SWQLQualifiedName **pHead);
  104. int const_list(OUT SWQLConstList **pRetVal);
  105. int col_list(OUT SWQLNode_ColumnList **pRetColList);
  106. void Empty();
  107. public:
  108. enum {
  109. SUCCESS,
  110. SYNTAX_ERROR,
  111. LEXICAL_ERROR,
  112. FAILED,
  113. BUFFER_TOO_SMALL,
  114. INVALID_PARAMETER,
  115. INTERNAL_ERROR
  116. };
  117. enum
  118. {
  119. Feature_Refs = 0x2, // A WQL 'references of' query
  120. Feature_Assocs = 0x4, // A WQL 'associators of' query
  121. Feature_Events = 0x8, // A WQL event-related query
  122. Feature_Joins = 0x10, // One or more joins occurred
  123. Feature_Having = 0x20, // HAVING used
  124. Feature_GroupBy = 0x40, // GROUP BY used
  125. Feature_OrderBy = 0x80, // ORDER BY used
  126. Feature_Count = 0x100, // COUNT used
  127. Feature_SelectAll = 0x400, // select * from
  128. Feature_SimpleProject = 0x800, // no 'where' clause, no join
  129. Feature_ComplexNames = 0x1000, // Names with long qualifications occurred, such
  130. // as array properties and embedded objects.
  131. Feature_WQL_Extensions = 0x80000000 // WQL-specific extensions
  132. } QueryFeatures;
  133. DWORD GetFeatureFlags();
  134. BOOL GetReferencedTables(OUT CWStringArray & Tables);
  135. BOOL GetReferencedAliases(OUT CWStringArray & Aliases);
  136. const LPWSTR AliasToTable(IN LPWSTR pAlias);
  137. const CFlexArray *GetSelectedAliases() { return &m_aSelAliases; }
  138. // Array of ptrs to SWQLNode_TableRef structs; read-only
  139. const CFlexArray *GetSelectedColumns() { return &m_pRootColList->m_aColumnRefs; }
  140. // Array of ptrs to SWQLColRef structs; read-only
  141. // Manual traversal.
  142. // =================
  143. SWQLNode *GetParseRoot() { return m_pQueryRoot; }
  144. SWQLNode *GetWhereClauseRoot() { return m_pRootWhere; }
  145. SWQLNode *GetColumnList() { return m_pRootColList; }
  146. SWQLNode *GetFromClause() { return m_pRootFrom; }
  147. SWQLNode *GetWhereOptions() { return m_pRootWhereOptions; }
  148. // Working
  149. // =======
  150. CWQLParser(CGenLexSource *pSrc);
  151. ~CWQLParser();
  152. int Parse();
  153. void AllowPromptForConstant(bool bIsAllowed = TRUE) {m_bAllowPromptForConstant = bIsAllowed;}
  154. };
  155. #endif