hqlalias.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef __HQLALIAS_HPP_
  14. #define __HQLALIAS_HPP_
  15. #include "hqlexpr.hpp"
  16. class ConditionSet;
  17. class ConditionItem : public CInterface
  18. {
  19. public:
  20. ConditionItem(IHqlExpression * _expr, ConditionSet * _parent);
  21. bool equals(IHqlExpression * _expr, ConditionSet * _parent) const
  22. {
  23. return (expr == _expr) && (parent == _parent);
  24. }
  25. bool isAlwaysConditionalOn(IHqlExpression * expr) const;
  26. protected:
  27. LinkedHqlExpr expr;
  28. ConditionSet * parent;
  29. };
  30. class ConditionSet
  31. {
  32. public:
  33. ConditionSet() { unconditional = false; nesting = 0; }
  34. bool addOrCondition(IHqlExpression * expr, ConditionSet * parent);
  35. bool isAlwaysConditionalOn(IHqlExpression * expr);
  36. bool isUnconditonal() const { return unconditional; }
  37. IHqlExpression * getGuardCondition() const;
  38. void setUnconditional();
  39. protected:
  40. CIArrayOf<ConditionItem> conditions;
  41. unsigned nesting;
  42. bool unconditional;
  43. struct
  44. {
  45. HqlExprAttr search;
  46. bool value;
  47. } isAlwaysCache;
  48. };
  49. class ConditionTracker
  50. {
  51. public:
  52. void pushCondition(IHqlExpression * expr, ConditionSet * parent);
  53. void popCondition();
  54. bool addActiveCondition(ConditionSet & conditions);
  55. protected:
  56. PointerArrayOf<IHqlExpression> conditionStack;
  57. PointerArrayOf<ConditionSet> parentStack;
  58. };
  59. IHqlExpression * optimizeNestedConditional(IHqlExpression * expr);
  60. void optimizeNestedConditional(HqlExprArray & exprs);
  61. #endif