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.

76 lines
3.8 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Declaration of Executor.
  4. //
  5. // Runs the script, interpreting its routines and managing its variables.
  6. #include "engcontrol.h"
  7. #include "enginc.h"
  8. #include "oleaut.h"
  9. // While a script is executing, a stack is used to hold routines' local parameters and temporaries for evaluating expressions.
  10. // This stack's memory grows as needed. Memory allocation/deallocation is minimized because many calls to a script will grow
  11. // the stack to its needed size.
  12. class CallStack
  13. {
  14. public:
  15. CallStack() : m_iNext(0) {}
  16. UINT Next() { return m_iNext; }
  17. VARIANT &operator[](UINT i) { assert(i < m_iNext); return m_vec[i]; }
  18. // used for routines' local variables
  19. HRESULT Push(UINT i); // pushes i empty slots
  20. void PopTo(UINT i); // pops everything down to and including i (following this, i will be Next)
  21. private:
  22. SmartRef::Vector<VARIANT> m_vec;
  23. UINT m_iNext;
  24. };
  25. class Executor
  26. {
  27. public:
  28. Executor(Script &script, IDispatch *pGlobalDispatch);
  29. ~Executor();
  30. HRESULT SetGlobal(Variables::index ivar, const VARIANT &varValue, bool fPutRef, EXCEPINFO *pExcepInfo);
  31. const VARIANT &GetGlobal(Variables::index ivar);
  32. HRESULT ExecRoutine(Routines::index irtn, EXCEPINFO *pExcepInfo);
  33. private:
  34. enum DispatchOperationType { _get, _put, _putref, _call };
  35. HRESULT EnsureInitialized();
  36. HRESULT Error(EXCEPINFO *pExcepInfo, bool fOperation, const WCHAR *pwszBeginning, const char *paszMiddle = NULL, const WCHAR *pwszEnd = NULL); // A bit hokey, but it works. Creates an error using wide strings with an ascii string (typically an identifier) in between.
  37. HRESULT ErrorIfImproperRef(const VARIANT &v, bool fRef, Strings::index istrIdentifier, EXCEPINFO *pExcepInfo);
  38. HRESULT ErrorObjectRequired(Strings::index istrIdentifier, EXCEPINFO *pExcepInfo) { return Error(pExcepInfo, false, L"Object required: '", m_script.strings[istrIdentifier], L"'"); }
  39. HRESULT ErrorIfInvokeProblem(DispatchOperationType e, HRESULT hr, Strings::index istrIdentifier, EXCEPINFO *pExcepInfo);
  40. HRESULT ExecStatements(Statements::index istmt, EXCEPINFO *pExcepInfo, UINT iLocals);
  41. HRESULT ExecAssignment(Assignments::index iasgn, EXCEPINFO *pExcepInfo, UINT iLocals);
  42. HRESULT ExecIf(IfBlocks::index iif, EXCEPINFO *pExcepInfo, UINT iLocals);
  43. HRESULT ExecCall(Calls::index icall, bool fPushResult, EXCEPINFO *pExcepInfo, UINT iLocals);
  44. HRESULT ExecCallInternal(Calls::index icall, bool fPushResult, EXCEPINFO *pExcepInfo, UINT iLocals); // helper used by ExecCall
  45. HRESULT EvalExpression(VARIANT &varResult, ExprBlocks::index iexpr, EXCEPINFO *pExcepInfo, UINT iLocals);
  46. HRESULT EvalValue(Values::index ival, VARIANT &v, EXCEPINFO *pExcepInfo, UINT iLocals); // evaluates ival, saving the result in v
  47. HRESULT EvalUnaryOp(Token t, VARIANT &v); // evaluates t on v -- saving the result back into v
  48. HRESULT EvalBinaryOp(Token t, VARIANT &v1, VARIANT &v2, EXCEPINFO *pExcepInfo); // evaluates t on v1 and v2 -- saving the result back into v2
  49. HRESULT GetVariableReference(Variables::index ivarref, VARIANT &v, EXCEPINFO *pExcepInfo, UINT iLocals) { return VariableReferenceInternal(_get, ivarref, v, pExcepInfo, iLocals); }
  50. HRESULT SetVariableReference(bool fSet, Variables::index ivarref, const VARIANT &v, EXCEPINFO *pExcepInfo, UINT iLocals) { return VariableReferenceInternal(fSet ? _putref : _put, ivarref, const_cast<VARIANT&>(v), pExcepInfo, iLocals); }
  51. HRESULT VariableReferenceInternal(DispatchOperationType e, Variables::index ivarref, VARIANT &v, EXCEPINFO *pExcepInfo, UINT iLocals);
  52. HRESULT ChangeToDispatch(VARIANT &var, EXCEPINFO *pExcepInfo, ReferenceNames::index irnameIdentifier);
  53. // Data
  54. bool m_fInitialized;
  55. Script &m_script;
  56. SmartRef::ComPtr<IDispatch> m_scomGlobalDispatch;
  57. VARIANT m_varEmpty; // varient we hold around so we can return a ref to a cleared variant
  58. CallStack m_stack;
  59. };