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.

212 lines
7.6 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. MOFLEX.H
  5. Abstract:
  6. Declarations for class CMofLexer, which tokenizes MOF files.
  7. ANSI, DBCS and UNICODE are supported.
  8. History:
  9. a-raymcc 11-Oct-95 Created.
  10. a-raymcc 27-Jan-96 Update for aliasing.
  11. a-davj 6-June-96 Added support for octal, hex and binary constants
  12. and line stitching, comment concatenation, escape
  13. characters and old style comments.
  14. --*/
  15. #ifndef _MOFLEX_H_
  16. #define _MOFLEX_H_
  17. #include <windows.h>
  18. #include <stdio.h>
  19. #include "trace.h"
  20. #include <datasrc.h>
  21. #include <md5wbem.h>
  22. // Terminal tokens required by the parser.
  23. // =======================================
  24. #define TOK_NULL 0
  25. #define TOK_ERROR -1
  26. #define TOK_CLASS 256
  27. #define TOK_SIMPLE_IDENT 257
  28. #define TOK_OPEN_BRACE 258
  29. #define TOK_CLOSE_BRACE 259
  30. #define TOK_SEMI 260
  31. #define TOK_COLON 261
  32. #define TOK_INTERFACE 262
  33. #define TOK_REF 263
  34. #define TOK_OPEN_BRACKET 264
  35. #define TOK_CLOSE_BRACKET 265
  36. #define TOK_EQUALS 266
  37. #define TOK_INSTANCE 267
  38. #define TOK_AS 268
  39. #define TOK_COMMA 269
  40. #define TOK_EXTERNAL 270
  41. #define TOK_OPEN_PAREN 271
  42. #define TOK_CLOSE_PAREN 272
  43. #define TOK_LPWSTR 274
  44. #define TOK_UUID 277
  45. #define TOK_KEYWORD_NULL 278
  46. #define TOK_FLOAT_VALUE 279
  47. #define TOK_AMPERSAND 280
  48. #define TOK_DOT 281
  49. #define TOK_DOLLAR_SIGN 282
  50. #define TOK_HEX_CONST 283
  51. #define TOK_OCTAL_CONST 284
  52. #define TOK_LINE 285
  53. #define TOK_OF 286
  54. #define TOK_OBJECT 287
  55. #define TOK_TYPEDEF 288
  56. #define TOK_SUBRANGE 289
  57. #define TOK_PRAGMA 290
  58. #define TOK_DEFINE 291
  59. #define TOK_IFDEF 292
  60. #define TOK_INCLUDE 293
  61. #define TOK_ENDIF 294
  62. #define TOK_IFNDEF 295
  63. #define TOK_WCHAR 296
  64. #define TOK_ENUM 300
  65. #define TOK_AUTORECOVER 301
  66. #define TOK_NAMESPACE 302
  67. #define TOK_POUND 303
  68. #define TOK_TRUE 304
  69. #define TOK_FALSE 305
  70. #define TOK_TOINSTANCE 306
  71. #define TOK_TOSUBCLASS 307
  72. #define TOK_ENABLEOVERRIDE 308
  73. #define TOK_DISABLEOVERRIDE 309
  74. #define TOK_NOTTOINSTANCE 310
  75. #define TOK_NOTTOSUBCLASS 311
  76. #define TOK_QUALIFIER 312
  77. #define TOK_INSTANCEFLAGS 313
  78. #define TOK_CLASSFLAGS 314
  79. #define TOK_SIGNED64_NUMERIC_CONST 315
  80. #define TOK_UNSIGNED64_NUMERIC_CONST 316
  81. #define TOK_VOID 317
  82. #define TOK_AMENDMENT 318
  83. #define TOK_RESTRICTED 319
  84. #define TOK_SYSTEM_IDENT 320
  85. #define TOK_AMENDED 321
  86. #define TOK_DELETECLASS 322
  87. #define TOK_FAIL 323
  88. #define TOK_NOFAIL 324
  89. #define TOK_DELETEINSTANCE 326
  90. #define TOK_LOCALE 327
  91. #define TOK_PLUS 328
  92. #define TOK_INSTANCELOCALE 329
  93. #define TOK_NONLOCAL 330
  94. #define TOK_NONLOCALTYPE 331
  95. #define TOK_SOURCE 332
  96. #define TOK_SOURCETYPE 333
  97. // This type is used to describe the state of the lexer state machine.
  98. // ====================================================================
  99. typedef enum { start,
  100. new_style_comment, // ie, "//" comments
  101. old_style_comment, // ie, "/* ... */" comments
  102. wstring,
  103. wcharacter,
  104. uuid,
  105. ident,
  106. numeric,
  107. lexerror,
  108. stop
  109. } LexState;
  110. class CMofLexer
  111. {
  112. PDBG m_pDbg;
  113. int m_nLine;
  114. int m_nTokCol;
  115. int m_nStartOfLinePos;
  116. int m_nTokLine;
  117. int m_nErrorCode;
  118. BOOL m_bUnicode;
  119. wchar_t *m_pBuff; // holds the data to be parsed
  120. BYTE *m_pToFar;
  121. //todo wchar_t *m_pCurrWChar; // points to the current character
  122. //todo wchar_t *m_pLastWChar; // points to the last valid character
  123. DataSrc * m_pDataSrc;
  124. wchar_t *m_pWorkBuf; // Holds the current token string
  125. int m_nWorkBufSize; // number of WCHARs working buff holds
  126. wchar_t *m_pEndOfText; // points to null terminator of working buff
  127. BOOL m_bInString;
  128. BOOL m_bBadString;
  129. bool m_bBMOF;
  130. WCHAR m_wFile[MAX_PATH];
  131. __int64 m_i8;
  132. void Init();
  133. BOOL SpaceAvailable();
  134. void BuildBuffer(long lSize, TCHAR * pFileName,char * pMemSrc, char * pMemToFar);
  135. void MovePtr(int iNum);
  136. wchar_t GetChar(int iNum = 0);
  137. int iGetColumn();
  138. int iGetNumericType(void);
  139. LexState ProcessStr(wchar_t * pNewChar, LexState lsCurr, int *piRet);
  140. int ConvertEsc(wchar_t * pResult, LexState lsCurr);
  141. int OctalConvert(wchar_t *pResult, LexState lsCurr);
  142. int HexConvert(wchar_t *pResult, LexState lsCurr);
  143. BOOL bOKNumericAddition(wchar_t cTest);
  144. BOOL ValidGuid();
  145. bool ProcessBMOFFile(FILE *fp,TCHAR * szFilename);
  146. bool CreateBufferFromBMOF(byte * pIn, DWORD dwCompressedSize, DWORD dwExpandedSize);
  147. public:
  148. enum {
  149. no_error,
  150. file_not_found,
  151. memory_failure,
  152. access_denied,
  153. file_io_error,
  154. unrecognized_token,
  155. token_too_long,
  156. invalid_source_file,
  157. invalid_source_buffer,
  158. problem_creating_temp_file,
  159. preprocessor_error,
  160. invalid_include_file
  161. };
  162. CMofLexer(PDBG pDbg);
  163. CMofLexer(const TCHAR *pFilePath, PDBG pDbg);
  164. ~CMofLexer();
  165. HRESULT SetBuffer(char *pSrcMemory, DWORD dwMemSize);
  166. BOOL IsUnicode(){return m_bUnicode;};
  167. int NextToken(bool bDontAllowWhitespace = false); // Returns 0 on end of file
  168. __int64 GetLastInt(){return m_i8;};
  169. const OLECHAR *GetText(int *pLineDeclared = 0);
  170. int GetLineNumber() { return m_nLine; }
  171. void SetLineNumber(int iNew) {m_nLine = iNew-1;}; // the -1 accounts for the cr/lf at eol
  172. WCHAR * GetErrorFile(){return m_wFile;};
  173. void SetErrorFile(const WCHAR * pNew){wcsncpy(m_wFile, pNew, MAX_PATH-1);};
  174. int GetColumn() { return m_nTokCol; }
  175. int GetError() { return m_nErrorCode; }
  176. void SetError(int iError) { m_nErrorCode = iError; }
  177. bool IsBMOF(){return m_bBMOF;};
  178. BYTE * GetBuff(){return (BYTE *)m_pBuff;};
  179. BYTE * GetToFar(){return (BYTE *)m_pToFar;};
  180. void SetLexPosition(ParseState * pPos);
  181. void GetLexPosition(ParseState * pPos);
  182. TCHAR * GetFileName(){ return m_pDataSrc?m_pDataSrc->GetFileName():NULL; };
  183. };
  184. #endif