hqlusage.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 __HQLUSAGE_HPP_
  14. #define __HQLUSAGE_HPP_
  15. class HQL_API HqlSelectorAnywhereLocator : public NewHqlTransformer
  16. {
  17. public:
  18. HqlSelectorAnywhereLocator(IHqlExpression * _selector);
  19. virtual void analyseExpr(IHqlExpression * expr);
  20. virtual void analyseSelector(IHqlExpression * expr);
  21. bool containsSelector(IHqlExpression * expr);
  22. protected:
  23. bool foundSelector;
  24. OwnedHqlExpr selector;
  25. };
  26. class HQL_API FieldAccessAnalyser : public NewHqlTransformer
  27. {
  28. public:
  29. FieldAccessAnalyser(IHqlExpression * selector);
  30. inline bool accessedAll() const { return numAccessed == fields.ordinality(); }
  31. IHqlExpression * queryLastFieldAccessed() const;
  32. protected:
  33. virtual void analyseExpr(IHqlExpression * expr);
  34. virtual void analyseSelector(IHqlExpression * expr);
  35. inline void setAccessedAll() { numAccessed = fields.ordinality(); }
  36. protected:
  37. LinkedHqlExpr selector;
  38. HqlExprCopyArray fields;
  39. Owned<IBitSet> accessed;
  40. unsigned numAccessed;
  41. };
  42. class HQL_API SourceFieldUsage : public CInterface
  43. {
  44. public:
  45. SourceFieldUsage(IHqlExpression * _source);
  46. void noteSelect(IHqlExpression * select, IHqlExpression * selector);
  47. inline void noteAll() { usedAll = true; }
  48. inline void noteFilepos() { usedFilepos = true; }
  49. const char * queryFilenameText() const;
  50. inline bool matches(IHqlExpression * search) const { return source == search; }
  51. inline bool seenAll() const { return usedAll; }
  52. IPropertyTree * createReport(bool includeFieldDetail, const IPropertyTree * exclude) const;
  53. protected:
  54. void expandSelects(IPropertyTree * xml, IHqlExpression * record, IHqlExpression * selector, bool allUsed, bool includeFieldDetail, unsigned & numFields, unsigned & numFieldsUsed) const;
  55. IHqlExpression * queryFilename() const;
  56. protected:
  57. LinkedHqlExpr source;
  58. HqlExprArray selects;
  59. bool usedAll;
  60. bool usedFilepos;
  61. private:
  62. mutable StringAttr cachedFilenameEcl;
  63. };
  64. extern HQL_API unsigned getNumUniqueExpressions(IHqlExpression * expr);
  65. extern HQL_API unsigned getNumUniqueExpressions(const HqlExprArray & exprs);
  66. extern HQL_API unsigned getNumOccurences(HqlExprArray & exprs, IHqlExpression * search, unsigned limit);
  67. extern HQL_API void logTreeStats(IHqlExpression * expr);
  68. extern HQL_API void logTreeStats(const HqlExprArray & exprs);
  69. extern HQL_API void gatherSelectExprs(HqlExprArray & target, IHqlExpression * expr);
  70. extern HQL_API bool containsSelector(IHqlExpression * expr, IHqlExpression * selector);
  71. extern HQL_API bool containsSelectorAnywhere(IHqlExpression * expr, IHqlExpression * selector); // searches through nested "hidden" definitions
  72. extern HQL_API void gatherFieldUsage(SourceFieldUsage * fieldUsage, IHqlExpression * expr, IHqlExpression * selector);
  73. extern HQL_API void gatherParentFieldUsage(SourceFieldUsage * fieldUsage, IHqlExpression * expr);
  74. #endif