Browse Source

HPCC-19662 PassParameterMeta does not work with C++ Embeds

- Modified getBoolAttributeValue to check for null and accept a default value
- Added a test to the ecl/regress suite

Signed-off-by: James McMullan <James.McMullan@lexisnexis.com>
James McMullan 7 years ago
parent
commit
2ad71adc21
6 changed files with 26 additions and 17 deletions
  1. 8 8
      ecl/hql/hqlexpr.cpp
  2. 1 1
      ecl/hql/hqlexpr.hpp
  3. 1 5
      ecl/hql/hqlutil.cpp
  4. 2 2
      ecl/hqlcpp/hqlcpp.cpp
  5. 1 1
      ecl/hqlcpp/hqlwcpp.cpp
  6. 13 0
      ecl/regress/issue19662.ecl

+ 8 - 8
ecl/hql/hqlexpr.cpp

@@ -13060,7 +13060,7 @@ IHqlExpression * createExternalFuncdefFromInternal(IHqlExpression * funcdef)
         attrs.append(*createAttribute(activityAtom));
     
     IHqlExpression* passParamAttr = getFunctionBodyAttribute(body, passParameterMetaAtom);
-    if (passParamAttr != NULL && getBoolAttributeValue(passParamAttr))
+    if (getBoolAttributeValue(passParamAttr))
         attrs.append(*createAttribute(passParameterMetaAtom));
 
     IHqlExpression *child = body->queryChild(0);
@@ -16733,8 +16733,11 @@ bool isKeyedCountAggregate(IHqlExpression * aggregate)
 }
 
 
-bool getBoolAttributeValue(IHqlExpression * attr)
+bool getBoolAttributeValue(IHqlExpression * attr, bool dft)
 {
+    if (attr == NULL)
+        return dft;
+
     IHqlExpression * value = attr->queryChild(0);
     //No argument implies true
     if (!value)
@@ -16757,9 +16760,8 @@ bool getBoolAttribute(IHqlExpression * expr, IAtom * name, bool dft)
     if (!expr)
         return dft;
     IHqlExpression * attr = expr->queryAttribute(name);
-    if (!attr)
-        return dft;
-    return getBoolAttributeValue(attr);
+
+    return getBoolAttributeValue(attr,dft);
 }
 
 IHqlExpression * queryBoolAttribute(IHqlExpression * expr, IAtom * name)
@@ -16780,9 +16782,7 @@ IHqlExpression * queryBoolExpr(bool value)
 bool getBoolAttributeInList(IHqlExpression * expr, IAtom * search, bool dft)
 {
     IHqlExpression * match = queryAttributeInList(search, expr);
-    if (!match)
-        return dft;
-    return getBoolAttributeValue(match);
+    return getBoolAttributeValue(match,dft);
 }
 
 IHqlExpression * queryOriginalRecord(IHqlExpression * expr)

+ 1 - 1
ecl/hql/hqlexpr.hpp

@@ -1968,7 +1968,7 @@ extern HQL_API void ensureSymbolsDefined(IHqlExpression * scope, HqlLookupContex
 extern HQL_API void ensureSymbolsDefined(IHqlScope * scope, HqlLookupContext & ctx);
 extern HQL_API IHqlExpression * queryBoolExpr(bool value);
 extern HQL_API IHqlExpression * queryBoolAttribute(IHqlExpression * expr, IAtom * name);    // true expr, false expr or NULL
-extern HQL_API bool getBoolAttributeValue(IHqlExpression * attr);
+extern HQL_API bool getBoolAttributeValue(IHqlExpression * attr, bool dft=false);
 extern HQL_API bool getBoolAttribute(IHqlExpression * expr, IAtom * name, bool dft=false);
 extern HQL_API bool getBoolAttributeInList(IHqlExpression * expr, IAtom * name, bool dft);
 

+ 1 - 5
ecl/hql/hqlutil.cpp

@@ -7911,12 +7911,8 @@ public:
 
         if (formals->numChildren())
         {
-            bool hasMeta = false;
             IHqlExpression* passParamAttr = getFunctionBodyAttribute(body, passParameterMetaAtom);
-            if (passParamAttr != NULL)
-            {
-                hasMeta = getBoolAttributeValue(passParamAttr);
-            }
+            bool hasMeta = getBoolAttributeValue(passParamAttr);
 
             ForEachChild(i, formals)
             {

+ 2 - 2
ecl/hqlcpp/hqlcpp.cpp

@@ -6164,7 +6164,7 @@ void HqlCppTranslator::doBuildCall(BuildCtx & ctx, const CHqlBoundTarget * tgt,
         case type_groupedtable:
             {
                 IHqlExpression* passParamAttr = getFunctionBodyAttribute(external, passParameterMetaAtom);
-                if (passParamAttr != NULL && getBoolAttributeValue(passParamAttr))
+                if (getBoolAttributeValue(passParamAttr))
                     args.append(*buildMetaParameter(curParam));
                 ExpressionFormat format = queryNaturalFormat(argType);
                 buildDataset(ctx, castParam, bound, format);
@@ -6173,7 +6173,7 @@ void HqlCppTranslator::doBuildCall(BuildCtx & ctx, const CHqlBoundTarget * tgt,
         case type_row:
             {
                 IHqlExpression* passParamAttr = getFunctionBodyAttribute(external, passParameterMetaAtom);
-                if (passParamAttr != NULL && getBoolAttributeValue(passParamAttr))
+                if (getBoolAttributeValue(passParamAttr))
                     args.append(*buildMetaParameter(curParam));
                 Owned<IReferenceSelector> selector = buildNewRow(ctx, castParam);
 

+ 1 - 1
ecl/hqlcpp/hqlwcpp.cpp

@@ -851,7 +851,7 @@ void HqlCppWriter::generateParamCpp(IHqlExpression * param, IHqlExpression * att
     case type_groupedtable:
     case type_row:
         IHqlExpression* passParamAttr = getFunctionBodyAttribute(attrs, passParameterMetaAtom);
-        if (passParamAttr != NULL && getBoolAttributeValue(passParamAttr))
+        if (getBoolAttributeValue(passParamAttr))
         {
             out.append("IOutputMetaData & ");
             if (paramName)

+ 13 - 0
ecl/regress/issue19662.ecl

@@ -0,0 +1,13 @@
+r := RECORD
+    UNSIGNED id;
+    STRING name;
+END;
+
+testPassParameterMeta(streamed dataset(r) ds) := EMBED(C++ : passparametermeta)
+  if (metaDs.queryRecordAccessor(true).getNumFields() != 2) {
+  	rtlFail(0,"Meta data incorrect");
+  }
+ENDEMBED;
+
+ds := DATASET([{1,'Name'}], r);
+testPassParameterMeta(ds);