Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions basex-core/src/main/java/org/basex/query/QueryParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,10 @@ private void check(final MainModule main) throws QueryException {
}
}

// check function calls and variable references
// check function calls
qc.functions.check(qc);
qc.vars.check();
// resolve variable references
qc.vars.resolve();

if(qc.updating) {
// check updating semantics if updating expressions exist
Expand Down Expand Up @@ -897,8 +898,6 @@ private void contextValueDecl() throws QueryException {
*/
private void varDecl(final AnnList anns) throws QueryException {
final Var var = newVar();
if(sc.module != null && !eq(var.name.uri(), sc.module.uri())) throw error(MODULENS_X, var);

localVars.pushContext(false);
final boolean external = wsConsumeWs(EXTERNAL);
Expr expr = null;
Expand All @@ -909,7 +908,7 @@ private void varDecl(final AnnList anns) throws QueryException {
}
final VarScope vs = localVars.popContext();
final String doc = docBuilder.toString();
final StaticVar sv = qc.vars.declare(var, expr, anns, external, vs, doc);
final StaticVar sv = qc.vars.declare(var, moduleURIs, expr, anns, external, vs, doc);
vars.add(sv);
}

Expand Down
2 changes: 1 addition & 1 deletion basex-core/src/main/java/org/basex/query/func/Records.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public enum Records {
add("members", true, FuncType.get(stp.seqType(Occ.ZERO_OR_MORE)).seqType()).
add("simple-content-type", true, FuncType.get(stp.seqType()).seqType()).
add("matches", true, FuncType.get(Types.BOOLEAN_O, Types.ANY_ATOMIC_TYPE_O).seqType()).
add("constructo", true, FuncType.get(Types.ANY_ATOMIC_TYPE_ZM,
add("constructor", true, FuncType.get(Types.ANY_ATOMIC_TYPE_ZM,
Types.ANY_ATOMIC_TYPE_ZO).seqType());
}

Expand Down
20 changes: 2 additions & 18 deletions basex-core/src/main/java/org/basex/query/util/parse/LocalVars.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.basex.query.util.parse;

import static org.basex.query.QueryError.*;
import static org.basex.util.Token.*;

import java.util.*;

import org.basex.query.*;
Expand Down Expand Up @@ -88,25 +85,12 @@ public VarRef resolveLocal(final QNm name, final InputInfo info) {
* @param name variable name
* @param info input info (can be {@code null})
* @return referenced variable
* @throws QueryException if the variable is not defined
*/
public ParseExpr resolve(final QNm name, final InputInfo info) throws QueryException {
public ParseExpr resolve(final QNm name, final InputInfo info) {
// local variable
final VarRef ref = resolveLocal(name, info);
if(ref != null) return ref;

// static variable
final byte[] uri = name.uri();

// accept variable reference...
// - if a variable uses the module or an imported URI, or
// - if it is specified in the main module
final QNm module = parser.sc.module;
final boolean hasImport = parser.moduleURIs.contains(uri);
if(module == null || eq(module.uri(), uri) || hasImport)
return parser.qc.vars.newRef(name, info, hasImport);

throw parser.error(VARUNDEF_X, info, '$' + string(name.string()));
return parser.qc.vars.newRef(name, info, parser.moduleURIs);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions basex-core/src/main/java/org/basex/query/value/item/QNm.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ public byte[] uri() {
return uri == null ? Token.EMPTY : uri;
}

/**
* Returns the URI of the given QName, or an empty string if {@code null}.
* @param qnm name (can be {@code null})
* @return URI
*/
public static byte[] uri(final QNm qnm) {
return qnm == null ? Token.EMPTY : qnm.uri();
}

/**
* Checks if the URI of this QName has been explicitly set.
* @return result of check
Expand Down
19 changes: 5 additions & 14 deletions basex-core/src/main/java/org/basex/query/var/StaticVarRef.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.basex.query.var;

import static org.basex.query.QueryError.*;

import org.basex.query.*;
import org.basex.query.ann.*;
import org.basex.query.expr.*;
import org.basex.query.util.*;
import org.basex.query.value.*;
Expand All @@ -20,21 +17,18 @@
*/
final class StaticVarRef extends ParseExpr {
/** Variable name. */
private final QNm name;
public final QNm name;
/** Referenced variable. */
private StaticVar var;
/** Indicates whether a module import for the variable name's URI was present. */
final boolean hasImport;

/**
* Constructor.
* @param info input info (can be {@code null})
* @param name variable name
* @param hasImport indicates whether a module import for the variable name's URI was present
*/
StaticVarRef(final InputInfo info, final QNm name, final boolean hasImport) {
StaticVarRef(final InputInfo info, final QNm name) {
super(info, Types.ITEM_ZM);
this.name = name;
this.hasImport = hasImport;
}

@Override
Expand Down Expand Up @@ -75,7 +69,7 @@ public boolean accept(final ASTVisitor visitor) {

@Override
public Expr copy(final CompileContext cc, final IntObjectMap<Var> vm) {
final StaticVarRef ref = new StaticVarRef(info, name, hasImport);
final StaticVarRef ref = new StaticVarRef(info, name);
ref.var = var;
return copyType(ref);
}
Expand Down Expand Up @@ -104,11 +98,8 @@ public Expr inline(final InlineContext ic) {
/**
* Initializes this reference with the given variable.
* @param vr variable
* @throws QueryException query exception
*/
void init(final StaticVar vr) throws QueryException {
if(vr.anns.contains(Annotation.PRIVATE) && !sc().baseURI().eq(vr.sc.baseURI()))
throw VARPRIVATE_X.get(info, this);
void init(final StaticVar vr) {
var = vr;
}

Expand Down
Loading