فهرست منبع

Merge pull request #9403 from ghalliday/issue16742

HPCC-16742 Add support for //#WHEN(LEGACY|MODERN)

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 8 سال پیش
والد
کامیت
b69b3dd652
4فایلهای تغییر یافته به همراه73 افزوده شده و 4 حذف شده
  1. 7 1
      ecl/hql/hqlgram.hpp
  2. 5 3
      ecl/hql/hqlgram2.cpp
  3. 39 0
      ecl/hql/hqlparse.cpp
  4. 22 0
      ecl/regress/hashwhen.ecl

+ 7 - 1
ecl/hql/hqlgram.hpp

@@ -374,6 +374,7 @@ public:
     HqlExprArray imports;
     bool inSignedModule;
     bool legacyImport;
+    bool legacyWhen;
 };
 
 typedef const IAtom * const * AtomList;
@@ -875,7 +876,6 @@ protected:
     bool resolveSymbols;
     bool forceResult;
     bool associateWarnings;
-    bool legacyWhenSemantics;
     bool isQuery;
     bool parseConstantText;
     bool expandingMacroPosition;
@@ -1130,10 +1130,15 @@ class HqlLex
         StringBuffer& doGetDataType(StringBuffer & type, const char * text, int lineno, int column);
         void pushText(const char *);
         bool hasLegacyImportSemantics() const;
+        bool hasLegacyWhenSemantics() const;
         void setLegacyImport(bool _legacyImportMode)
         {
             legacyImportMode = _legacyImportMode;
         }
+        void setLegacyWhen(bool _legacyWhenMode)
+        {
+            legacyWhenMode = _legacyWhenMode;
+        }
 
     protected:
         void init(IFileContents * _text);
@@ -1245,6 +1250,7 @@ private:
         UnsignedArray hashendKinds;
         bool hasHashbreak;
         bool legacyImportMode = false;
+        bool legacyWhenMode = false;
         int loopTimes;
 
         bool inComment;

+ 5 - 3
ecl/hql/hqlgram2.cpp

@@ -348,6 +348,7 @@ HqlGram::HqlGram(IHqlScope * _globalScope, IHqlScope * _containerScope, IFileCon
 
     lexObject = new HqlLex(this, _text, xmlScope, NULL);
     lexObject->setLegacyImport(queryLegacyImportSemantics());
+    lexObject->setLegacyWhen(queryLegacyWhenSemantics());
 
     //MORE: This should be in the parseContext calculated once
     if (lookupCtx.queryRepository() && loadImplicit)
@@ -377,6 +378,7 @@ HqlGram::HqlGram(HqlGramCtx & parent, IHqlScope * _containerScope, IFileContents
     //Clone parseScope
     lexObject = new HqlLex(this, _text, xmlScope, NULL);
     lexObject->setLegacyImport(parent.legacyImport);
+    lexObject->setLegacyWhen(parent.legacyWhen);
     forceResult = true;
     parsingTemplateAttribute = false;
     parseConstantText = _parseConstantText;
@@ -404,6 +406,7 @@ void HqlGram::saveContext(HqlGramCtx & ctx, bool cloneScopes)
     }
 
     ctx.legacyImport = lexObject->hasLegacyImportSemantics();
+    ctx.legacyWhen = lexObject->hasLegacyWhenSemantics();
     ctx.globalScope.set(globalScope);
     appendArray(ctx.defaultScopes, defaultScopes);
     appendArray(ctx.implicitScopes, implicitScopes);
@@ -420,7 +423,6 @@ void HqlGram::init(IHqlScope * _globalScope, IHqlScope * _containerScope)
 {
     minimumScopeIndex = 0;
     isQuery = false;
-    legacyWhenSemantics = queryLegacyWhenSemantics();
     current_id = NULL;
     lexObject = NULL;
     expectedAttribute = NULL;
@@ -9231,7 +9233,7 @@ IHqlExpression * HqlGram::associateSideEffects(IHqlExpression * expr, const ECLl
 {
     if (sideEffectsPending())
     {
-        if (legacyWhenSemantics)
+        if (lexObject->hasLegacyWhenSemantics())
         {
             if (okToAddSideEffects(expr))
                 return addSideEffects(expr);
@@ -9310,7 +9312,7 @@ void HqlGram::doDefineSymbol(DefineIdSt * defineid, IHqlExpression * _expr, IHql
             if (isQuery && !insideNestedScope())
             {
                 //If this is a global query, and not inside a nested attribute, then keep any actions on the global list of results
-                if (!legacyWhenSemantics)
+                if (!lexObject->hasLegacyWhenSemantics())
                 {
                     //Should we give a warning here?? export/shared would not be legal if this was within the repository
                 }

+ 39 - 0
ecl/hql/hqlparse.cpp

@@ -316,8 +316,10 @@ void HqlLex::pushText(IFileContents * text, int startLineNo, int startColumn)
     MTIME_SECTION(timer, "HqlLex::pushText");
 #endif
     bool useLegacyImport = hasLegacyImportSemantics();
+    bool useLegacyWhen = hasLegacyWhenSemantics();
     inmacro = new HqlLex(yyParser, text, NULL, NULL);
     inmacro->setLegacyImport(useLegacyImport);
+    inmacro->setLegacyWhen(useLegacyWhen);
     inmacro->set_yyLineNo(startLineNo);
     inmacro->set_yyColumn(startColumn);
 }
@@ -337,8 +339,10 @@ void HqlLex::pushText(const char *s)
 #endif
     Owned<IFileContents> macroContents = createFileContentsFromText(s, sourcePath, yyParser->inSignedModule, yyParser->gpgSignature);
     bool useLegacyImport = hasLegacyImportSemantics();
+    bool useLegacyWhen = hasLegacyWhenSemantics();
     inmacro = new HqlLex(yyParser, macroContents, NULL, NULL);
     inmacro->setLegacyImport(useLegacyImport);
+    inmacro->setLegacyWhen(useLegacyWhen);
     inmacro->set_yyLineNo(yyLineNo);
     inmacro->set_yyColumn(yyColumn);
 
@@ -354,6 +358,13 @@ bool HqlLex::hasLegacyImportSemantics() const
     return legacyImportMode;
 }
 
+bool HqlLex::hasLegacyWhenSemantics() const
+{
+    if (inmacro)
+        return inmacro->hasLegacyWhenSemantics();
+    return legacyWhenMode;
+}
+
 void HqlLex::setMacroParam(const YYSTYPE & errpos, IHqlExpression* funcdef, StringBuffer& curParam, IIdAtom * argumentId, unsigned& parmno,IProperties *macroParms)
 {
     IHqlExpression * formals = queryFunctionParameters(funcdef);
@@ -573,8 +584,10 @@ void HqlLex::pushMacro(IHqlExpression *expr)
     else
     {
         bool useLegacyImport = hasLegacyImportSemantics();
+        bool useLegacyWhen = hasLegacyWhenSemantics();
         inmacro = new HqlLex(yyParser, macroContents, NULL, LINK(expr));
         inmacro->setLegacyImport(useLegacyImport);
+        inmacro->setLegacyWhen(useLegacyWhen);
 
 #if defined(TRACE_MACRO)
         PrintLog("MACRO>> inmacro %p created for \"%s\" at %d:%d\n",inmacro, s.str(),macroBodyExpr->getStartLine(),macroBodyExpr->getStartColumn());
@@ -700,8 +713,10 @@ void HqlLex::processEncrypted()
     Owned<ISourcePath> sourcePath = createSourcePath("<encrypted>");
     Owned<IFileContents> decryptedContents = createFileContentsFromText((const char *)decrypted.toByteArray(), sourcePath, yyParser->inSignedModule, yyParser->gpgSignature);
     bool useLegacyImport = hasLegacyImportSemantics();
+    bool useLegacyWhen = hasLegacyWhenSemantics();
     inmacro = new HqlLex(yyParser, decryptedContents, NULL, NULL);
     inmacro->setLegacyImport(useLegacyImport);
+    inmacro->setLegacyWhen(useLegacyWhen);
     inmacro->setParentLex(this);
     inmacro->encrypted = true;
 }
@@ -1092,6 +1107,30 @@ void HqlLex::doSlashSlashHash(YYSTYPE const & returnToken, const char * command)
         else
             reportError(returnToken, ERR_EXPECTED_LEFTCURLY, "Expected (");
     }
+    else if (hasPrefix(command, "when", false))
+    {
+        const char * next = skipws(command + 4);
+        if (*next == '(')
+        {
+            next = skipws(next + 1);
+            const char * bra = strchr(next, ')');
+            if (bra)
+            {
+                StringBuffer option(bra - next, next);
+                option.clip();
+                if (strieq(option, "legacy"))
+                    setLegacyWhen(true);
+                else if (strieq(option, "modern"))
+                    setLegacyWhen(false);
+                else
+                    reportError(returnToken, ERR_EXPECTED_ID, "Unknown #import option '%s' - expected legacy or modern", option.str());
+            }
+            else
+                reportError(returnToken, ERR_EXPECTED_RIGHTCURLY, "Expected closing )");
+        }
+        else
+            reportError(returnToken, ERR_EXPECTED_LEFTCURLY, "Expected (");
+    }
     //Ignore any unrecognised commands
 }
 

+ 22 - 0
ecl/regress/hashwhen.ecl

@@ -0,0 +1,22 @@
+
+
+//#when(legacy)
+
+x := function
+
+   output ('ok!');
+   return 3;
+END;
+
+x;
+
+
+//#when(modern)
+
+y := function
+
+   output ('not ok!'); // error
+   return 3;
+END;
+
+y;