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.

308 lines
7.8 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. QL.H
  5. Abstract:
  6. Level 1 Syntax QL Parser
  7. Implements the syntax described in QL.BNF. This translates the input
  8. into an RPN stream of tokens.
  9. History:
  10. raymcc 21-Jun-96 Created.
  11. --*/
  12. #ifndef _QL__H_
  13. #define _QL__H_
  14. #include <wbemidl.h>
  15. #include <wbemint.h>
  16. #include <qllex.h>
  17. #include <corepol.h>
  18. #include <parmdefs.h>
  19. #include <stdio.h>
  20. #include <wmiutils.h>
  21. class CPropertyName : public WBEM_PROPERTY_NAME
  22. {
  23. protected:
  24. long m_lAllocated;
  25. void EnsureAllocated(long lElements);
  26. public:
  27. void Init();
  28. CPropertyName() {Init();}
  29. CPropertyName(const CPropertyName& Other);
  30. void operator=(const CPropertyName& Other);
  31. void operator=(const WBEM_PROPERTY_NAME& Other);
  32. BOOL operator==(const WBEM_PROPERTY_NAME& Other);
  33. void Empty();
  34. ~CPropertyName() {Empty();}
  35. long GetNumElements() const {return m_lNumElements;}
  36. LPCWSTR GetStringAt(long lIndex) const;
  37. void AddElement(LPCWSTR wszElement);
  38. DELETE_ME LPWSTR GetText();
  39. };
  40. class CQl1ParseSink
  41. {
  42. public:
  43. virtual void SetClassName(LPCWSTR wszClass) = 0;
  44. virtual void SetTolerance(const WBEM_QL1_TOLERANCE& Tolerance) = 0;
  45. virtual void AddToken(const WBEM_QL1_TOKEN& Token) = 0;
  46. virtual void AddProperty(const CPropertyName& Property) = 0;
  47. virtual void AddAllProperties() = 0;
  48. virtual void SetAggregated() = 0;
  49. virtual void SetAggregationTolerance(const WBEM_QL1_TOLERANCE& Tolerance)= 0;
  50. virtual void AddAggregationProperty(const CPropertyName& Property) = 0;
  51. virtual void AddAllAggregationProperties() = 0;
  52. virtual void AddHavingToken(const WBEM_QL1_TOKEN& Token) = 0;
  53. virtual void InOrder(long lOp){}
  54. };
  55. class CAbstractQl1Parser
  56. {
  57. protected:
  58. // Controls keyword parsing in Next().
  59. // ===================================
  60. enum {
  61. NO_KEYWORDS = 0,
  62. ALL_KEYWORDS,
  63. EXCLUDE_GROUP_KEYWORD,
  64. EXCLUDE_EXPRESSION_KEYWORDS
  65. };
  66. CQl1ParseSink* m_pSink;
  67. CGenLexer *m_pLexer;
  68. int m_nLine;
  69. wchar_t* m_pTokenText;
  70. int m_nCurrentToken;
  71. // Semantic transfer variables.
  72. // ============================
  73. VARIANT m_vTypedConst;
  74. BOOL m_bQuoted;
  75. int m_nRelOp;
  76. DWORD m_dwConstFunction;
  77. DWORD m_dwPropFunction;
  78. CPropertyName m_PropertyName;
  79. BOOL m_bInAggregation;
  80. CPropertyName m_PropertyName2;
  81. BOOL m_bPropComp;
  82. // Parsing functions.
  83. // ==================
  84. virtual BOOL Next(int nFlags = ALL_KEYWORDS);
  85. LPCWSTR GetSinglePropertyName();
  86. void DeletePropertyName();
  87. int FlipOperator(int nOp);
  88. void AddAppropriateToken(const WBEM_QL1_TOKEN& Token);
  89. int parse_property_name(CPropertyName& Prop);
  90. int parse(int nFlags);
  91. int prop_list();
  92. int class_name();
  93. int tolerance();
  94. int opt_where();
  95. int expr();
  96. int property_name();
  97. int prop_list_2();
  98. int term();
  99. int expr2();
  100. int simple_expr();
  101. int term2();
  102. int leading_ident_expr();
  103. int finalize();
  104. int rel_operator();
  105. int equiv_operator();
  106. int comp_operator();
  107. int is_operator();
  108. int trailing_prop_expr();
  109. int trailing_prop_expr2();
  110. int trailing_or_null();
  111. int trailing_const_expr();
  112. int trailing_ident_expr();
  113. int unknown_func_expr();
  114. int typed_constant();
  115. int opt_aggregation();
  116. int aggregation_params();
  117. int aggregate_by();
  118. int aggregate_within();
  119. int opt_having();
  120. static DWORD TranslateIntrinsic(LPCWSTR pFuncName);
  121. static void InitToken(WBEM_QL1_TOKEN* pToken);
  122. public:
  123. enum {
  124. SUCCESS = 0,
  125. SYNTAX_ERROR,
  126. LEXICAL_ERROR,
  127. FAILED,
  128. BUFFER_TOO_SMALL
  129. };
  130. enum {
  131. FULL_PARSE = 0,
  132. NO_WHERE,
  133. JUST_WHERE
  134. };
  135. CAbstractQl1Parser(CGenLexSource *pSrc);
  136. virtual ~CAbstractQl1Parser();
  137. int Parse(CQl1ParseSink* pSink, int nFlags);
  138. int CurrentLine() { return m_nLine; }
  139. LPWSTR CurrentToken() { return m_pTokenText; }
  140. };
  141. struct QL_LEVEL_1_TOKEN
  142. {
  143. enum
  144. {
  145. OP_EXPRESSION = QL1_OP_EXPRESSION,
  146. TOKEN_AND = QL1_AND,
  147. TOKEN_OR = QL1_OR,
  148. TOKEN_NOT = QL1_NOT
  149. };
  150. enum
  151. {
  152. IFUNC_NONE = QL1_FUNCTION_NONE,
  153. IFUNC_UPPER = QL1_FUNCTION_UPPER,
  154. IFUNC_LOWER = QL1_FUNCTION_LOWER
  155. };
  156. // If the field is a OP_EXPRESSION, then the following are used.
  157. enum
  158. {
  159. OP_EQUAL = QL1_OPERATOR_EQUALS,
  160. OP_NOT_EQUAL = QL1_OPERATOR_NOTEQUALS,
  161. OP_EQUALorGREATERTHAN = QL1_OPERATOR_GREATEROREQUALS,
  162. OP_EQUALorLESSTHAN = QL1_OPERATOR_LESSOREQUALS,
  163. OP_LESSTHAN = QL1_OPERATOR_LESS,
  164. OP_GREATERTHAN = QL1_OPERATOR_GREATER,
  165. OP_LIKE = QL1_OPERATOR_LIKE
  166. };
  167. int nTokenType; // OP_EXPRESSION,TOKEN_AND, TOKEN_OR, TOKEN_NOT
  168. CPropertyName PropertyName;
  169. // Name of the property on which the operator is applied
  170. int nOperator; // Operator that is applied on property
  171. VARIANT vConstValue; // Value applied by operator
  172. BOOL bQuoted; // FALSE if the string should not have quotes around it.
  173. CPropertyName PropertyName2; // Property to compare, if applicable.
  174. BOOL m_bPropComp; // TRUE if this is a property-to-property compare.
  175. DWORD dwPropertyFunction; // 0=no instrinsic function applied
  176. DWORD dwConstFunction; // "
  177. QL_LEVEL_1_TOKEN();
  178. QL_LEVEL_1_TOKEN(const QL_LEVEL_1_TOKEN&);
  179. ~QL_LEVEL_1_TOKEN();
  180. QL_LEVEL_1_TOKEN& operator=(const QL_LEVEL_1_TOKEN &Src);
  181. QL_LEVEL_1_TOKEN& operator=(const WBEM_QL1_TOKEN &Src);
  182. void Dump(FILE *);
  183. DELETE_ME LPWSTR GetText();
  184. };
  185. // Contains RPN version of expression.
  186. // ===================================
  187. struct QL_LEVEL_1_RPN_EXPRESSION : public CQl1ParseSink
  188. {
  189. int nNumTokens;
  190. int nCurSize;
  191. QL_LEVEL_1_TOKEN *pArrayOfTokens;
  192. BSTR bsClassName;
  193. WBEM_QL1_TOLERANCE Tolerance;
  194. int nNumberOfProperties; // Zero means all properties selected
  195. int nCurPropSize;
  196. BOOL bStar;
  197. CPropertyName *pRequestedPropertyNames;
  198. // Array of property names which values are to be returned if
  199. BOOL bAggregated;
  200. WBEM_QL1_TOLERANCE AggregationTolerance;
  201. BOOL bAggregateAll;
  202. int nNumAggregatedProperties;
  203. int nCurAggPropSize;
  204. CPropertyName *pAggregatedPropertyNames;
  205. int nNumHavingTokens;
  206. int nCurHavingSize;
  207. QL_LEVEL_1_TOKEN *pArrayOfHavingTokens;
  208. long lRefCount;
  209. QL_LEVEL_1_RPN_EXPRESSION();
  210. QL_LEVEL_1_RPN_EXPRESSION(const QL_LEVEL_1_RPN_EXPRESSION& Other);
  211. ~QL_LEVEL_1_RPN_EXPRESSION();
  212. void AddRef();
  213. void Release();
  214. void SetClassName(LPCWSTR wszName);
  215. void SetTolerance(const WBEM_QL1_TOLERANCE& Tolerance);
  216. void AddToken(const WBEM_QL1_TOKEN& Tok);
  217. void AddToken(const QL_LEVEL_1_TOKEN& Tok);
  218. void AddProperty(const CPropertyName& Prop);
  219. void AddAllProperties();
  220. void SetAggregated();
  221. void SetAggregationTolerance(const WBEM_QL1_TOLERANCE& Tolerance);
  222. void AddAggregationProperty(const CPropertyName& Property);
  223. void AddAllAggregationProperties();
  224. void AddHavingToken(const WBEM_QL1_TOKEN& Tok);
  225. void Dump(const char *pszTextFile);
  226. DELETE_ME LPWSTR GetText();
  227. };
  228. class QL1_Parser : public CAbstractQl1Parser
  229. {
  230. QL_LEVEL_1_RPN_EXPRESSION* m_pExpression;
  231. BOOL m_bPartiallyParsed;
  232. public:
  233. QL1_Parser(CGenLexSource *pSrc);
  234. #undef ExportClass
  235. #define ExportClass SMSEXPORT
  236. ~QL1_Parser();
  237. #undef ExportClass
  238. #define ExportClass SMSIMPORT
  239. int GetQueryClass(LPWSTR pBuf, int nBufSize);
  240. int Parse(QL_LEVEL_1_RPN_EXPRESSION **pOutput);
  241. HRESULT Parse(
  242. SWbemRpnEncodedQuery **pOutput
  243. );
  244. static LPWSTR ReplaceClassName(QL_LEVEL_1_RPN_EXPRESSION* pExpr,
  245. LPCWSTR wszClassName);
  246. };
  247. #endif
  248.