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.

270 lines
7.9 KiB

  1. //***************************************************************************
  2. //
  3. // WQL.H
  4. //
  5. // WQL 1.1 Parser
  6. //
  7. // Implements the syntax described in WQL.BNF.
  8. //
  9. // raymcc 19-Sep-97
  10. //
  11. //***************************************************************************
  12. #ifndef _WQL__H_
  13. #define _WQL__H_
  14. #include <wmiutils.h>
  15. #include <wbemint.h>
  16. class CWbemQueryQualifiedName : public SWbemQueryQualifiedName
  17. {
  18. public:
  19. void Init();
  20. void DeleteAll();
  21. CWbemQueryQualifiedName();
  22. ~CWbemQueryQualifiedName();
  23. CWbemQueryQualifiedName(CWbemQueryQualifiedName &Src);
  24. CWbemQueryQualifiedName& operator =(CWbemQueryQualifiedName &Src);
  25. };
  26. class CWbemRpnQueryToken : public SWbemRpnQueryToken
  27. {
  28. public:
  29. void Init();
  30. void DeleteAll();
  31. CWbemRpnQueryToken();
  32. ~CWbemRpnQueryToken();
  33. CWbemRpnQueryToken(CWbemRpnQueryToken &);
  34. CWbemRpnQueryToken& operator =(CWbemRpnQueryToken&);
  35. };
  36. class CWbemRpnEncodedQuery : public SWbemRpnEncodedQuery
  37. {
  38. public:
  39. void Init();
  40. void DeleteAll();
  41. CWbemRpnEncodedQuery();
  42. ~CWbemRpnEncodedQuery();
  43. CWbemRpnEncodedQuery(CWbemRpnEncodedQuery &Src);
  44. CWbemRpnEncodedQuery& operator=(CWbemRpnEncodedQuery &Src);
  45. };
  46. class CWQLParser
  47. {
  48. // Data.
  49. // =====
  50. CGenLexer *m_pLexer;
  51. LPWSTR m_pszQueryText;
  52. int m_nLine;
  53. wchar_t *m_pTokenText;
  54. int m_nCurrentToken;
  55. unsigned __int64 m_uFeatures;
  56. CWStringArray m_aReferencedTables;
  57. CWStringArray m_aReferencedAliases;
  58. CFlexArray m_aSelAliases;
  59. CFlexArray m_aSelColumns;
  60. SWQLNode_QueryRoot *m_pQueryRoot;
  61. SWQLNode_WhereClause *m_pRootWhere;
  62. SWQLNode_ColumnList *m_pRootColList;
  63. SWQLNode_FromClause *m_pRootFrom;
  64. SWQLNode_WhereOptions *m_pRootWhereOptions;
  65. CWbemRpnEncodedQuery *m_pRpn;
  66. // Parse context. In some cases, there is a general
  67. // shift in state for the whole parser. Rather than
  68. // pass this as an inherited attribute to each production,
  69. // it is much easier to have a general purpose state variable.
  70. // ============================================================
  71. enum { Ctx_Default = 0, Ctx_Subselect = 0x1 };
  72. int m_nParseContext;
  73. bool m_bAllowPromptForConstant;
  74. // Functions.
  75. // ==========
  76. BOOL Next();
  77. BOOL GetIntToken(BOOL *bSigned, BOOL *b64Bit, unsigned __int64 *pVal);
  78. int QNameToSWQLColRef(
  79. IN SWQLQualifiedName *pQName,
  80. OUT SWQLColRef **pRetVal
  81. );
  82. enum { eCtxLeftSide = 1, eCtxRightSide = 2 };
  83. // Non-terminal productions.
  84. // =========================
  85. int select_stmt(OUT SWQLNode_Select **pSelStmt);
  86. int delete_stmt(OUT SWQLNode_Delete **pDelStmt);
  87. int update_stmt(OUT SWQLNode_Update **pUpdStmt);
  88. int insert_stmt(OUT SWQLNode_Insert **pInsStmt);
  89. int assocquery(OUT SWQLNode_AssocQuery **pAssocQuery);
  90. int select_type(int & nSelType);
  91. int col_ref_list(IN OUT SWQLNode_TableRefs *pTblRefs);
  92. int from_clause(OUT SWQLNode_FromClause **pFrom);
  93. int where_clause(OUT SWQLNode_WhereClause **pRetWhere);
  94. int col_ref(OUT SWQLQualifiedName **pRetVal);
  95. int col_ref_rest(IN OUT SWQLNode_TableRefs *pTblRefs);
  96. int count_clause(
  97. OUT SWQLQualifiedName **pQualName
  98. );
  99. int wmi_scoped_select(SWQLNode_FromClause *pFC);
  100. int single_table_decl(OUT SWQLNode_TableRef **pTblRef);
  101. int sql89_join_entry(
  102. IN SWQLNode_TableRef *pInitialTblRef,
  103. OUT SWQLNode_Sql89Join **pJoin );
  104. int sql92_join_entry(
  105. IN SWQLNode_TableRef *pInitialTblRef,
  106. OUT SWQLNode_Join **pJoin
  107. );
  108. int sql89_join_list(
  109. IN SWQLNode_TableRef *pInitialTblRef,
  110. OUT SWQLNode_Sql89Join **pJoin );
  111. int on_clause(OUT SWQLNode_OnClause **pOC);
  112. int rel_expr(OUT SWQLNode_RelExpr **pRelExpr);
  113. int where_options(OUT SWQLNode_WhereOptions **pWhereOpt0);
  114. int group_by_clause(OUT SWQLNode_GroupBy **pRetGroupBy);
  115. int having_clause(OUT SWQLNode_Having **pRetHaving);
  116. int order_by_clause(OUT SWQLNode_OrderBy **pRetOrderBy);
  117. int rel_term(OUT SWQLNode_RelExpr **pNewTerm);
  118. int rel_expr2(
  119. IN OUT SWQLNode_RelExpr *pLeftSide,
  120. OUT SWQLNode_RelExpr **pNewRootRE
  121. );
  122. int rel_simple_expr(OUT SWQLNode_RelExpr **pRelExpr);
  123. int rel_term2(
  124. IN SWQLNode_RelExpr *pLeftSide,
  125. OUT SWQLNode_RelExpr **pNewRootRE
  126. );
  127. int typed_expr(OUT SWQLNode_RelExpr **pRelExpr);
  128. int typed_subexpr_rh(SWQLTypedExpr *pTE);
  129. int typed_subexpr(IN SWQLTypedExpr *pTE);
  130. int typed_const(OUT SWQLTypedConst **pRetVal);
  131. int datepart_call(
  132. OUT SWQLNode_Datepart **pRetDP
  133. );
  134. int function_call(IN BOOL bLeftSide, IN SWQLTypedExpr *pTE);
  135. int function_call_parms();
  136. int func_args();
  137. int func_arg();
  138. int rel_op(int &);
  139. int is_continuator(int &);
  140. int not_continuator(int &);
  141. int in_clause(IN SWQLTypedExpr *pTE);
  142. int subselect_stmt(OUT SWQLNode_Select **pSel);
  143. int qualified_name(OUT SWQLQualifiedName **pHead);
  144. int const_list(OUT SWQLConstList **pRetVal);
  145. int col_list(OUT SWQLNode_ColumnList **pRetColList);
  146. void Empty();
  147. public:
  148. enum
  149. {
  150. Feature_Refs = 0x2, // A WQL 'references of' query
  151. Feature_Assocs = 0x4, // A WQL 'associators of' query
  152. Feature_Events = 0x8, // A WQL event-related query
  153. Feature_Joins = 0x10, // One or more joins occurred
  154. Feature_Having = 0x20, // HAVING used
  155. Feature_GroupBy = 0x40, // GROUP BY used
  156. Feature_OrderBy = 0x80, // ORDER BY used
  157. Feature_Count = 0x100, // COUNT used
  158. Feature_SelectAll = 0x400, // select * from
  159. Feature_SimpleProject = 0x800, // no 'where' clause, no join
  160. Feature_ComplexNames = 0x1000, // Names with long qualifications occurred, such
  161. // as array properties and embedded objects.
  162. Feature_WQL_Extensions = 0x80000000 // WQL-specific extensions
  163. } QueryFeatures;
  164. DWORD GetFeatureFlags();
  165. BOOL GetReferencedTables(OUT CWStringArray & Tables);
  166. BOOL GetReferencedAliases(OUT CWStringArray & Aliases);
  167. const LPWSTR AliasToTable(IN LPWSTR pAlias);
  168. const CFlexArray *GetSelectedAliases() { return &m_aSelAliases; }
  169. // Array of ptrs to SWQLNode_TableRef structs; read-only
  170. const CFlexArray *GetSelectedColumns() { return &m_pRootColList->m_aColumnRefs; }
  171. // Array of ptrs to SWQLColRef structs; read-only
  172. // Manual traversal.
  173. // =================
  174. SWQLNode_QueryRoot *GetParseRoot() { return m_pQueryRoot; }
  175. SWQLNode *GetWhereClauseRoot() { return m_pRootWhere; }
  176. SWQLNode *GetColumnList() { return m_pRootColList; }
  177. SWQLNode *GetFromClause() { return m_pRootFrom; }
  178. SWQLNode *GetWhereOptions() { return m_pRootWhereOptions; }
  179. LPCWSTR GetQueryText() { return m_pszQueryText; }
  180. // Working
  181. // =======
  182. CWQLParser(LPWSTR pszQueryText, CGenLexSource *pSrc);
  183. ~CWQLParser();
  184. HRESULT Parse();
  185. void AllowPromptForConstant(bool bIsAllowed = TRUE) {m_bAllowPromptForConstant = bIsAllowed;}
  186. // Rpn Helpers.
  187. // ============
  188. HRESULT GetRpnSequence(
  189. OUT SWbemRpnEncodedQuery **pRpn
  190. );
  191. HRESULT BuildRpnWhereClause(
  192. SWQLNode *pRootOfWhere,
  193. CFlexArray &aRpnReorg
  194. );
  195. HRESULT BuildCurrentWhereToken(
  196. SWQLNode_RelExpr *pSrc,
  197. SWbemRpnQueryToken *pDest
  198. );
  199. HRESULT BuildSelectList(
  200. CWbemRpnEncodedQuery *pQuery
  201. );
  202. HRESULT BuildFromClause(
  203. CWbemRpnEncodedQuery *pQuery
  204. );
  205. };
  206. #endif