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.

202 lines
5.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: CXX.HXX
  7. //
  8. // Contents: C and C++ filter
  9. //
  10. // History: 26-Jun-92 BartoszM Created
  11. //
  12. //---------------------------------------------------------------------------/
  13. #pragma once
  14. #define cxxDebugOut( x )
  15. #define MAXIDENTIFIER 80
  16. //
  17. // These are the tokens recognized by the scanner
  18. //
  19. enum CToken
  20. {
  21. tEnd, // EOF
  22. tClass, // class
  23. tStruct, // struct
  24. tUnion, // union
  25. tInterface, // interface
  26. tEnum, // enum
  27. tLBrace, // {
  28. tRBrace, // }
  29. tSemi, // ;
  30. tDoubleColon, // ::
  31. tLParen, // (
  32. tRParen, // )
  33. tDefine, // #define
  34. tInclude, // #include
  35. tTypedef, // typedef
  36. tComma, // ,
  37. tStar, // *
  38. };
  39. //+---------------------------------------------------------------------------
  40. //
  41. // Class: CxxScanner
  42. //
  43. // Interface:
  44. //
  45. // History: 26-Jun-92 BartoszM Created
  46. //
  47. //----------------------------------------------------------------------------
  48. class CxxScanner
  49. {
  50. public:
  51. CxxScanner();
  52. void Init(CFilterTextStream* pStream);
  53. CToken Accept()
  54. {
  55. return NextToken(_pStream->GetChar());
  56. }
  57. CToken Accept(int c)
  58. {
  59. return NextToken(c);
  60. }
  61. int EatComment();
  62. int EatString();
  63. int EatCharLiteral();
  64. int EatPrepro();
  65. CToken Token() { return(_token); }
  66. int LoadName(int c);
  67. int LoadIncludeFileName(int c);
  68. int SkipName(int c);
  69. void IgnorePreamble ( BOOL f ) { _fIgnorePreamble = f; }
  70. void SetIdFound( BOOL f ) { _fIdFound = f; }
  71. BOOL IdFound() { return _fIdFound; }
  72. const WCHAR* GetLastIdent ( FILTERREGION& region) const
  73. {
  74. region = _region;
  75. return(_buf);
  76. }
  77. ULONG Lines() { return _cLines; }
  78. private:
  79. CToken NextToken(int c);
  80. CFilterTextStream* _pStream; // stream
  81. WCHAR _buf[MAXIDENTIFIER+1]; // buffer for identifiers
  82. FILTERREGION _region; // region where the identifier was found
  83. CToken _token; // recognized token
  84. BOOL _fIgnorePreamble; // state flag--scanning preamble
  85. ULONG _cLines;
  86. BOOL _fScanningPrepro; // state flag--parsing a prepro stmt
  87. BOOL _fIdFound; // state flag--set to TRUE when
  88. // an identifier is scanned
  89. };
  90. //+---------------------------------------------------------------------------
  91. //
  92. // Class: CxxParser
  93. //
  94. // Interface:
  95. //
  96. // History: 26-Jun-92 BartoszM Created
  97. //
  98. //----------------------------------------------------------------------------
  99. class CxxParser
  100. {
  101. enum TokenType
  102. {
  103. ttClass, ttFunction, ttMethod, ttInlineMethod
  104. };
  105. public:
  106. CxxParser();
  107. ~CxxParser();
  108. void Init( CFilterTextStream * pStream );
  109. BOOL Parse();
  110. PROPSPEC GetAttribute() { return _attribute; }
  111. BOOL GetTokens( ULONG * pcwcBuffer, WCHAR * awcBuffer);
  112. void GetRegion ( FILTERREGION& region );
  113. BOOL GetValueAttribute( PROPSPEC & ps );
  114. PROPVARIANT * GetValue();
  115. void SkipValue() { _iVal++; }
  116. private:
  117. void PutClass ();
  118. void PutMethod ();
  119. void PutInlineMethod();
  120. void PutFunction ();
  121. void SetClass()
  122. {
  123. const WCHAR* buf = _scan.GetLastIdent (_regionClass);
  124. wcsncpy ( _strClass, buf, MAXIDENTIFIER );
  125. _strClass[ MAXIDENTIFIER ] = 0;
  126. }
  127. void SetName()
  128. {
  129. const WCHAR* buf = _scan.GetLastIdent (_regionName);
  130. wcsncpy ( _strName, buf, MAXIDENTIFIER );
  131. _strName[ MAXIDENTIFIER ] = 0;
  132. }
  133. CxxScanner _scan; // the scanner
  134. WCHAR _strClass[MAXIDENTIFIER+1]; // buffer for class name
  135. FILTERREGION _regionClass;
  136. WCHAR _strName [MAXIDENTIFIER+1]; // buffer for identifier
  137. FILTERREGION _regionName;
  138. TokenType _tokenType; // class, function, method?
  139. int _scope; // depth of scope counter
  140. int _inClass; // depth of class
  141. PROPSPEC _attribute;
  142. CToken _token;
  143. ULONG _cwcCopiedClass;
  144. ULONG _cwcCopiedName;
  145. enum CxxVal
  146. {
  147. Function,
  148. Class,
  149. Lines
  150. };
  151. unsigned _iVal;
  152. PROPSPEC _psVal[3];
  153. CPropVar * _aVal[3];
  154. #if CIDBG == 1
  155. CToken _classToken;
  156. #endif // CIDBG == 1
  157. BOOL _fParsingTypedef; // state flag--parsing a typedef
  158. BOOL _fParsingFnPtrTypedef; // state flag--parsing a typedef
  159. // of a fn pointer
  160. int _typedefScope;
  161. };