Commit 27867086 authored by Benito van der Zander's avatar Benito van der Zander

fix global, mutable variables set by functions in imported modules not being...

fix global, mutable variables set by functions in imported modules not being available within the calling query; still print variables when some where set when we do not expect it, because static analysis failed to find the assignment (e.g. in case of these function calls)
parent ba5636d2
......@@ -2,3 +2,6 @@ module namespace foobar2 = "pseudo://test-module2";
import module namespace foo = "pseudo://test-module" at "module.xq";
declare variable $foobar2:def := $foo:abc * 1000 ;
declare function foobar2:setglobal (){
$newglobal := "GLOABL"
};
\ No newline at end of file
newglobal := GLOABL
GLOABL
xx:GLOABL
newglobal := GLOABL
xxx := GLOABL
init
res := AAA
res := v1
res := v2
res:v1
res:v2
res:AAA
......
......@@ -420,6 +420,12 @@ tests/test.sh moduleFuncImportRel --module tests/module2.xqm -e '$foobar2:def'
tests/test.sh moduleFuncImportRel -e 'import module namespace rename = "pseudo://test-module2" at "tests/module2.xqm"; $rename:def'
tests/test.sh moduleFuncImportRel --extract-file tests/subdir/test.xq
tests/test.sh moduleFuncImportRel tests/subdir/test.xq
tests/test.sh moduleFuncImportGlobalMut --module tests/module2.xqm -e 'foobar2:setglobal()'
tests/test.sh moduleFuncImportGlobalMut -e 'import module namespace rename = "pseudo://test-module2" at "tests/module2.xqm"; rename:setglobal()'
tests/test.sh moduleFuncImportGlobalMut2 --module tests/module2.xqm -e 'foobar2:setglobal(), "xx:" || $newglobal'
tests/test.sh moduleFuncImportGlobalMut2 -e 'import module namespace rename = "pseudo://test-module2" at "tests/module2.xqm"; rename:setglobal(), "xx:" || $newglobal'
tests/test.sh moduleFuncImportGlobalMut3 --module tests/module2.xqm -e 'xxx := foobar2:setglobal()'
tests/test.sh moduleFuncImportGlobalMut3 -e 'import module namespace rename = "pseudo://test-module2" at "tests/module2.xqm"; xxx := rename:setglobal()'
tests/test.sh varlogBC -e 'x:clear-log(),a:=1,a:=2,b:=3,c:=4,x:clear-log("a"), t:=x:get-log(), u:=("a","b","c")!(.,x:get-log(.))'
tests/test.sh varlogAC -e 'x:clear-log(),a:=1,a:=2,b:=3,c:=4,x:clear-log("b"), t:=x:get-log(), u:=("a","b","c")!(.,x:get-log(.))'
......@@ -540,6 +546,7 @@ tests/test.sh moreActions2 -e '"init"||get("res")' --template-action ac2 --temp
tests/test.sh moreActionsLocalPattern --template-action local --template-file tests/more.actions --xquery '"res:" || $res'
tests/test.sh moreActions -e '"init"||get("res")' --template-action ac1 --template-file tests/more.actions --xquery '"res:" || $res, for $i in ("ac2", "local", "ac1", "ac2") return ( x:call-action($i), "res:"||$res)' #variables set by call-action are reordered before the extract print, since the values of the extract are only known after the for has finished
echo
echo Results:
wc -l /tmp/xidel-tests-state-ok /tmp/xidel-tests-state-failed 2> /dev/null | grep tests | sed -Ee 's/([0-9]+).*-([^-]+)/\1 \2/'
......@@ -2558,6 +2558,7 @@ end;
procedure TExtraction.pageProcessed(unused: TMultipageTemplateReader; parser: THtmlTemplateParser);
begin
printExtractedVariables(parser, false);
THtmlTemplateParserBreaker(htmlparser).closeVariableLog;
end;
......@@ -2578,6 +2579,7 @@ function TExtraction.process(data: IData): TFollowToList;
var
value: IXQValue;
oldvarlogcount: Integer;
begin
//set flags when first processed
if isStdin(extract) then extract:=strReadFromStdin;
......@@ -2620,12 +2622,15 @@ begin
end;
end;
parent.loadDataForQuery(data, extractQueryCache);
THtmlTemplateParserBreaker(htmlparser).closeVariableLog;
if termContainsVariableDefinition(extractQueryCache.Term) then begin
THtmlTemplateParserBreaker(htmlparser).closeVariableLog;
parent.evaluateQuery(extractQueryCache, data, true);
printExtractedVariables(htmlparser, true);
end else begin
oldvarlogcount := htmlparser.variableChangeLog.count;
value := parent.evaluateQuery(extractQueryCache, data, true);
if oldvarlogcount <> htmlparser.variableChangeLog.count then
printExtractedVariables(htmlparser, true); //still print variables when some where set when we do not expect it, because termContainsVariableDefinition failed to find the assignment (e.g. through a function call)
writeBeginGroup;
printExtractedValue(value, false);
writeEndGroup;
......@@ -3516,6 +3521,8 @@ function loadModuleFromAtUrl(const at, base: string): IXQuery;
var d: IData;
ft: TFollowTo;
url, oldBaseUri: String;
visitor: TXQTerm_VisitorFindWeirdGlobalVariableDeclarations;
term: TXQTerm;
begin
url := strResolveURI(at, base);
try
......@@ -3529,6 +3536,16 @@ begin
xpathparser.StaticContext.baseURI := url;
result := xpathparser.parseXQuery3(d.rawData);
xpathparser.StaticContext.baseURI := oldBaseUri;
visitor := TXQTerm_VisitorFindWeirdGlobalVariableDeclarations.Create;
visitor.findNestedVariables := true;
visitor.listVars := true;
term := result.getTerm;
visitor.simpleTermVisit(@term, nil);
for i := 0 to high(visitor.vars) do with visitor.vars[i] do TXQueryEngineBreaker(xpathparser).addAWeirdGlobalVariable(namespace, value);
visitor.free;
result.getTerm;
end;
procedure importModule(pseudoSelf: tobject; sender: TXQueryEngine; context: TXQStaticContext; const namespace: string; const at: array of string);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment