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.

198 lines
6.5 KiB

  1. //
  2. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. #ifndef SIMC_ABSTRACT_PARSE_TREE_H
  5. #define SIMC_ABSTRACT_PARSE_TREE_H
  6. /*
  7. * SIMCAbstractParseTree - This class is an abstract class which has
  8. * functions for checking the syntax and semantics of MIBs. However, only
  9. * the syntax-checking functions have an implementation in this class.
  10. * The semantic checking functions are left as pure virtual, and is up
  11. * to the derived class, to define, since different applications have
  12. * different meanings for the Semantic validity of a MIB. All syntax errors
  13. * are put in an SIMCErrorContainer object, which may be retrieved for
  14. * processing/reporting.
  15. */
  16. class SIMCAbstractParseTree
  17. {
  18. protected:
  19. // The place to put error messages
  20. SIMCErrorContainer *_errorContainer;
  21. // A count of the various kinds of errors, for each call of Parse()
  22. // Note that there are 3 kinds of messages (fatal, warning, information)
  23. long _fatalCount, _warningCount, _informationCount;
  24. // The parse tree
  25. SIMCModuleList *_listOfModules;
  26. // This is the flag that decides the way in which the next module
  27. // is syntactically checked or semantically checked.
  28. // That is, CheckSyntax() this flag to make decisions. A user
  29. // implementing the CheckSemantics() function in a derived class
  30. // might also find this helpful.
  31. // 1 indicates conformance to SnmpV1 rules,
  32. // 2 indicates conformance to SnmpV2 rules,
  33. // 0 indicates conformance to a union of of V1 and V2 rules, as
  34. // long as they dont contradict each other.
  35. int _snmpVersion;
  36. // Internal representation of the state of a parse tree.
  37. // Used to decide what methods are allowed to be called
  38. enum ParseTreeState
  39. {
  40. EMPTY,
  41. UNRESOLVED,
  42. UNCHECKED,
  43. FINAL
  44. };
  45. ParseTreeState _parseTreeState;
  46. // All the things to be wrapped up at the end of CheckSyntax()
  47. BOOL WrapUpSyntaxCheck( const SIMCParser& parser);
  48. // Dont allow instantiation. Used only by derived classes
  49. // Accept an error container to put in the error messages
  50. SIMCAbstractParseTree(SIMCErrorContainer *errorContainer)
  51. : _errorContainer(errorContainer), _parseTreeState (EMPTY),
  52. _listOfModules(new SIMCModuleList),
  53. _fatalCount(0), _warningCount(0), _informationCount(0),
  54. _snmpVersion(0)
  55. {}
  56. ~SIMCAbstractParseTree();
  57. public:
  58. // Get the current version setting of the parse tree.
  59. // This may be changed in between calls to CheckSyntax(),
  60. // using SetSnmpVersion()
  61. int GetSnmpVersion() const
  62. {
  63. return _snmpVersion;
  64. }
  65. // Set the SNMP version to which the parse tree checks its
  66. // conformance
  67. BOOL SetSnmpVersion( int x )
  68. {
  69. switch(x)
  70. {
  71. case 0: // '0' means union of v1 and v2 SMIs
  72. case 1:
  73. case 2:
  74. _snmpVersion = x;
  75. return TRUE;
  76. default:
  77. _snmpVersion = 0;
  78. return FALSE;
  79. }
  80. }
  81. // Various ways of specifying input to the parse tree
  82. // Caution - Only the second one (specifying the name of
  83. // a file) has been tested. All error messages are written on
  84. // to the SIMCErrorContainer object, which can be retrieved using
  85. // GetErrorContainer() function. The user may process the error container
  86. // in between calls to CheckSyntax(), to after he finishes all his
  87. // CheckSyntax() calls.
  88. virtual BOOL CheckSyntax( ifstream& inputStream);
  89. virtual BOOL CheckSyntax(const CString& inputStreamName);
  90. virtual BOOL CheckSyntax(const int fileDescriptor);
  91. virtual BOOL CheckSyntax(FILE *fileStream);
  92. // Allow obfuscated code to be written using this class
  93. friend BOOL operator >> (ifstream& inputStream,
  94. SIMCAbstractParseTree& parseTree)
  95. {
  96. return parseTree.CheckSyntax(inputStream);
  97. }
  98. // These are the pure virtual functions in this class.
  99. // These are together used to check the semantics of the
  100. // MIB module(s).
  101. // Resolve() is called to set all the external references (IMPORTS)
  102. // in all the input modules, using their definitions in other input
  103. // modules, and also to set all forward references to a symbol.
  104. // An "input module" is one that has been "entered" into
  105. // the parse tree, using a successful call to CheckSyntax().
  106. // Once resolution has been done successfully, CheckSemantics() should
  107. // be called to check if the modules conform to the rules the user
  108. // wishes to impose. The user gets the modules (SIMCModule objects)
  109. // in the parse tree using GetModule(), GetModuleOfFile() or GetListOfModules(),
  110. // And goes through each symbol (SIMCSymbol object) in the symbol
  111. // table of each module, He uses RTTI to determine the class of the
  112. // symbol (ie., which derived class of SIMCSymbol, the object is really
  113. // an instance of), and checks to see if that object is valid.
  114. // In both these cases, the boolean argument indicates whether the
  115. // the resolution/checking should be done without the definitions
  116. // of IMPORTED symbols, or with them. A true value implies a local
  117. // check, without resolution of IMPORT symbols
  118. virtual BOOL Resolve(BOOL local) = 0;
  119. virtual BOOL CheckSemantics(BOOL local) = 0;
  120. // Returns the error container
  121. const SIMCErrorContainer* GetErrorContainer() const
  122. {
  123. return _errorContainer;
  124. }
  125. // This should not be typically called by a user
  126. ParseTreeState GetParseTreeState() const
  127. {
  128. return _parseTreeState;
  129. }
  130. // # of all the messages generated till now
  131. long GetCurrentDiagnosticCount() const
  132. {
  133. return _errorContainer->NumberOfMessages();
  134. }
  135. // # of each king of message, generated till now.
  136. long GetFatalCount() const
  137. {
  138. return _fatalCount;
  139. }
  140. long GetWarningCount() const
  141. {
  142. return _warningCount;
  143. }
  144. long GetInformationCount() const
  145. {
  146. return _informationCount;
  147. }
  148. // Retreiving the parse tree information for a module ,
  149. // by specifying the module name
  150. SIMCModule * GetModule(const char *const moduleName)
  151. const;
  152. // Retreiving the parse tree information for a module ,
  153. // by specifying the input file name, that was used
  154. SIMCModule * GetModuleOfFile(const char *const fileName)
  155. const;
  156. // Get the parse tree information for all the modules
  157. const SIMCModuleList *GetListOfModules() const
  158. {
  159. return _listOfModules;
  160. }
  161. // For debugging
  162. void WriteTree(ostream& outStream) const;
  163. friend ostream& operator<< (ostream& out, const SIMCAbstractParseTree& r)
  164. {
  165. r.WriteTree(out);
  166. return out;
  167. }
  168. };
  169. #endif // SIMC_ABSTRACT_PARSE_TREE_H