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.

265 lines
6.7 KiB

  1. //
  2. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. #ifndef SIMC_VALUE_REFERENCE
  5. #define SIMC_VALUE_REFERENCE
  6. /*
  7. * This file contains classes that model symbols that result from
  8. * a value assignement.
  9. * Refer to the "Compiler Design Spec" for more detailed definitions
  10. * of a "defined value reference" and a "built-in value reference"
  11. * A defined value reference is caused by a value assignment statement
  12. * in which the RHS is just another symbol. A built-in value reference is
  13. * caused by a value assignment statement in which the RHS is a literal
  14. * value
  15. */
  16. /* This is the base class for a defined or a built-in value reference
  17. * All value references are symbols. Hence this class is derived from
  18. * SIMCSymbol. It stores a pointer to a symbol that represents the
  19. * type of the value
  20. */
  21. class SIMCValueReference: public SIMCSymbol
  22. {
  23. SIMCSymbol **_type;
  24. long _typeLine, _typeColumn;
  25. protected:
  26. SIMCValueReference (SIMCSymbol **type,
  27. long typeLine, long typeColumn,
  28. const char * const symbolName,
  29. SymbolType symbolType = LOCAL,
  30. SIMCModule *module = NULL,
  31. long _lineNumber = 0, long _columnNumber = 0,
  32. long _referenceCount = 0)
  33. : _type(type), _typeLine(typeLine), _typeColumn(typeColumn),
  34. SIMCSymbol( symbolName, symbolType, module,
  35. _lineNumber, _columnNumber, _referenceCount)
  36. {
  37. if(_type)
  38. (*_type)->IncrementReferenceCount();
  39. }
  40. virtual ~SIMCValueReference ()
  41. {
  42. if(UseReferenceCount() && _type)
  43. (*_type)->DecrementReferenceCount();
  44. }
  45. public:
  46. SIMCSymbol ** GetTypeReference() const
  47. {
  48. return _type;
  49. }
  50. const char *GetTypeName() const
  51. {
  52. return (*_type)->GetSymbolName();
  53. }
  54. long GetTypeLine() const
  55. {
  56. return _typeLine;
  57. }
  58. void SetTypeLine( long x)
  59. {
  60. _typeLine = x;
  61. }
  62. long GetTypeColumn() const
  63. {
  64. return _typeColumn;
  65. }
  66. void SetTypeColumn( long x)
  67. {
  68. _typeColumn = x;
  69. }
  70. virtual void WriteSymbol( ostream& outStream ) const
  71. {
  72. outStream << "VALUE REFERENCE ";
  73. SIMCSymbol::WriteSymbol(outStream);
  74. outStream << endl;
  75. outStream << "\t TYPE DETAILS ";
  76. (*_type)->WriteBrief(outStream);
  77. outStream << endl;
  78. }
  79. };
  80. /* This class models a built-in value reference. So, it has a pointer
  81. * to the SIMCValue object that resulted in this value reference
  82. */
  83. class SIMCBuiltInValueReference : public SIMCValueReference
  84. {
  85. SIMCValue *_value;
  86. BOOL _isSharedValue; // Set on the basis of the constructor used
  87. public:
  88. SIMCBuiltInValueReference (SIMCSymbol **type,
  89. long typeLine, long typeColumn,
  90. SIMCValue *value,
  91. const char * const symbolName,
  92. SymbolType symbolType = LOCAL,
  93. SIMCModule *module = NULL,
  94. long lineNumber = 0, long columnNumber = 0,
  95. long referenceCount = 0)
  96. : _value(value), _isSharedValue(FALSE),
  97. SIMCValueReference( type, typeLine, typeColumn,
  98. symbolName, symbolType, module,
  99. lineNumber, columnNumber, referenceCount)
  100. {}
  101. SIMCBuiltInValueReference(SIMCValueReference *symbol,
  102. SIMCBuiltInValueReference *bvRef)
  103. : _value(bvRef->GetValue()), _isSharedValue(TRUE),
  104. SIMCValueReference(symbol->GetTypeReference(),
  105. symbol->GetTypeLine(), symbol->GetTypeColumn(),
  106. symbol->GetSymbolName(),
  107. symbol->GetSymbolType(), symbol->GetModule(),
  108. symbol->GetLineNumber(), symbol->GetColumnNumber(),
  109. symbol->GetReferenceCount())
  110. {}
  111. virtual ~SIMCBuiltInValueReference()
  112. {
  113. if(!_isSharedValue)
  114. delete _value;
  115. }
  116. SIMCValue * GetValue() const
  117. {
  118. return _value;
  119. }
  120. virtual void WriteSymbol( ostream& outStream ) const
  121. {
  122. outStream << "BUILTINVALUE REFERENCE " ;
  123. SIMCValueReference::WriteSymbol(outStream);
  124. outStream << "\tVALUE DETAILS" << endl << (*_value) << endl;
  125. }
  126. };
  127. /* This class models a defined value reference, and hence has a pointer
  128. * to another symbol that was used in creating this defined value reference
  129. */
  130. class SIMCDefinedValueReference : public SIMCValueReference
  131. {
  132. SIMCSymbol ** _value;
  133. long _valueLine, _valueColumn;
  134. // the _value symbol itself may be another defined value reference
  135. // All defined value references have to finally end on a built-in
  136. // value reference. _realValue is that value reference
  137. SIMCBuiltInValueReference *_realValue;
  138. // What happened when an attempt was made to set _realType
  139. SIMCResolutionStatus _status;
  140. public:
  141. SIMCDefinedValueReference (SIMCSymbol **type,
  142. long typeLine, long typeColumn,
  143. SIMCSymbol **value,
  144. long valueLine, long valueColumn,
  145. const char * const symbolName,
  146. SymbolType symbolType = LOCAL,
  147. SIMCModule *module = NULL,
  148. long _lineNumber = 0, long _columnNumber = 0,
  149. long _referenceCount = 0)
  150. : _value(value), _valueLine(valueLine), _valueColumn(valueColumn),
  151. _realValue(NULL), _status(RESOLVE_UNSET),
  152. SIMCValueReference( type, typeLine, typeColumn,
  153. symbolName, symbolType, module,
  154. _lineNumber, _columnNumber, _referenceCount)
  155. {
  156. if( _value )
  157. (*_value)->IncrementReferenceCount();
  158. }
  159. virtual ~SIMCDefinedValueReference()
  160. {
  161. if( UseReferenceCount() && _value )
  162. (*_value)->DecrementReferenceCount();
  163. }
  164. SIMCSymbol ** GetValueReference() const
  165. {
  166. return _value;
  167. }
  168. SIMCBuiltInValueReference * GetRealValue() const
  169. {
  170. return _realValue;
  171. }
  172. void SetRealValue(SIMCBuiltInValueReference *value)
  173. {
  174. _realValue = value;
  175. }
  176. SIMCResolutionStatus GetStatus() const
  177. {
  178. return _status;
  179. }
  180. void SetStatus( SIMCResolutionStatus val)
  181. {
  182. _status = val;
  183. }
  184. long GetValueLine() const
  185. {
  186. return _valueLine;
  187. }
  188. void SetValueLine( long x)
  189. {
  190. _valueLine = x;
  191. }
  192. long GetValueColumn() const
  193. {
  194. return _valueColumn;
  195. }
  196. void SetValueColumn( long x)
  197. {
  198. _valueColumn = x;
  199. }
  200. virtual void WriteSymbol( ostream& outStream ) const
  201. {
  202. outStream << "DEFINEDVALUEREFRENCE " ;
  203. SIMCValueReference::WriteSymbol(outStream);
  204. outStream << "\tVALUE DETAILS " ;
  205. (*_value)->WriteBrief(outStream);
  206. // SIMCValueReference::WriteSymbol(outStream);
  207. outStream << endl;
  208. switch(_status)
  209. {
  210. case RESOLVE_UNSET:
  211. outStream << "UNSET RESOLUTION" << endl;
  212. break;
  213. case RESOLVE_UNDEFINED:
  214. outStream << "UNDEFINED RESOLUTION" << endl;
  215. break;
  216. case RESOLVE_IMPORT:
  217. outStream << "RESOLVES TO IMPORT" << endl;
  218. break;
  219. case RESOLVE_CORRECT:
  220. outStream << "RESOLVES TO " << _realValue->GetSymbolName()
  221. << endl;
  222. break;
  223. }
  224. }
  225. };
  226. typedef CList<SIMCDefinedValueReference *, SIMCDefinedValueReference *> SIMCDefinedValueReferenceList;
  227. #endif