Przeglądaj źródła

HPCC-18891 Delay global import so that //#import can control semantics

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 7 lat temu
rodzic
commit
12176cb7d0

+ 0 - 3
ecl/eclcc/eclcc.cpp

@@ -1203,9 +1203,6 @@ void EclCC::processSingleQuery(EclCompileInstance & instance,
             else
             {
                 Owned<IHqlScope> scope = createPrivateScope();
-                if (instance.legacyImport)
-                    importRootModulesToScope(scope, ctx);
-
                 instance.query.setown(parseQuery(scope, queryContents, ctx, NULL, NULL, true, true));
 
                 if (instance.archive)

+ 2 - 0
ecl/hql/hqlgram.hpp

@@ -734,6 +734,7 @@ public:
     IHqlExpression* clearFieldMap(IHqlExpression* expr);
     void setExpectedAttribute(IIdAtom * _expectedAttribute)             { expectedAttribute = _expectedAttribute; current_id = _expectedAttribute; }
     void setCurrentToExpected()             { current_id = expectedAttribute; }
+    void setPendingGlobalImport(bool _globalImportPending) { globalImportPending = _globalImportPending; }
     IHqlScope * queryPrimaryScope(bool isPrivate);
     unsigned nextParameterIndex()               { return 0; } // not commoned up at moment{ return activeParameters.length()+savedParameters.length(); }
     void addActiveParameterOwn(const attribute & errpos, IHqlExpression * expr, IHqlExpression * defaultValue);
@@ -904,6 +905,7 @@ protected:
     bool parseConstantText;
     bool expandingMacroPosition;
     bool inSignedModule;
+    bool globalImportPending = false;
     OwnedHqlExpr gpgSignature;
 
     IErrorArray pendingWarnings;

+ 10 - 0
ecl/hql/hqlgram2.cpp

@@ -3525,6 +3525,13 @@ IHqlExpression *HqlGram::lookupSymbol(IIdAtom * searchName, const attribute& err
     if (expectedUnknownId)
         return NULL;
 
+    if (globalImportPending)
+    {
+        if (lexObject->hasLegacyImportSemantics())
+            importRootModulesToScope(globalScope, lookupCtx);
+        globalImportPending = false;
+    }
+
     //Check periodically if parsing a referenced identifier has caused the compile to abort.
     checkAborting();//NOTE: checkAborting() checks whether the parseContext is aborting and implicitly propagates this state, thus consistently triggering the parser to abort.
 
@@ -12083,6 +12090,9 @@ extern HQL_API IHqlExpression * parseQuery(IHqlScope *scope, IFileContents * con
             ctx.noteBeginQuery(scope, contents);
 
         HqlGram parser(scope, scope, contents, ctx, xmlScope, false, loadImplicit);
+        if (isRoot)
+            parser.setPendingGlobalImport(true);
+
         parser.setQuery(true);
         parser.getLexer()->set_yyLineNo(1);
         parser.getLexer()->set_yyColumn(1);

+ 0 - 2
ecl/hql/hqlutil.cpp

@@ -9091,8 +9091,6 @@ IHqlExpression * expandMacroDefinition(IHqlExpression * expr, HqlLookupContext &
     //with implicitly importing myModule.
     Owned<IFileContents> mappedContents = createFileContentsFromText(macroText.length(), macroText.str(), macroContents->querySourcePath(), false, NULL);
     Owned<IHqlScope> scope = createPrivateScope();
-    if (queryLegacyImportSemantics())
-        importRootModulesToScope(scope, ctx);
     return parseQuery(scope, mappedContents, ctx, NULL, macroParms, true, true);
 }
 

+ 38 - 0
ecl/regress/legacy3.eclxml

@@ -0,0 +1,38 @@
+<Archive legacyMode="true">
+<!--
+
+    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+ <Module name="common">
+  <Attribute name="m1">
+output('hello');
+export m1 := m2+10;
+  </Attribute>
+ </Module>
+ <Module name="other">
+  <Attribute name="m1">
+output('hello');
+export m1 := m2+10;
+  </Attribute>
+ </Module>
+ <Query>
+ //#import(modern);
+ shared common := 3;
+ rec := RECORD
+    other := 3;
+ END;
+ output(common);
+ </Query>
+</Archive>

+ 35 - 0
ecl/regress/legacy4.eclxml

@@ -0,0 +1,35 @@
+<Archive legacyMode="false">
+<!--
+
+    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+ <Module name="common">
+  <Attribute name="m1">
+  //#when(legacy);
+output('hello');
+export m1 := 10;
+  </Attribute>
+ </Module>
+ <Module name="other">
+  <Attribute name="m1">
+output('hello');
+export m1 := m2+10;
+  </Attribute>
+ </Module>
+ <Query>
+ //#import(legacy);
+ output(common.m1);
+ </Query>
+</Archive>

+ 35 - 0
ecl/regress/legacy5.eclxml

@@ -0,0 +1,35 @@
+<Archive legacyMode="true">
+<!--
+
+    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+ <Module name="common">
+  <Attribute name="m1">
+export m1 := 'bad';
+  </Attribute>
+ </Module>
+ <Module name="xx.common">
+  <Attribute name="m1">
+export m1 := 'good';
+  </Attribute>
+ </Module>
+ <Query>
+ //check that the import has precedence over the implicit global import
+ //Although actually there is a long standing problem- that the explicit import appears to be ignored!
+ //So ensure it is consistent with previous versions
+ import xx.common as common;
+ output(common.m1);
+ </Query>
+</Archive>