Skip to content

Commit 21c9390

Browse files
[MOD] XQuery: drop constructors for built-in records. qtspecs#2768
1 parent bbd7744 commit 21c9390

6 files changed

Lines changed: 8 additions & 75 deletions

File tree

basex-core/src/main/java/org/basex/query/func/Function.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -799,43 +799,6 @@ public enum Function implements AFunction {
799799
ZERO_OR_ONE(FnZeroOrOne::new, "zero-or-one(input)",
800800
params(ITEM_ZM), ITEM_ZO),
801801

802-
// Predefined record constructor functions
803-
804-
/** XQuery function. */
805-
ARRAY_SORT_KEY_RECORD(Records.ARRAY_SORT_KEY.get()),
806-
/** XQuery function. */
807-
ATTRIBUTE_CONVERSION_PLAN_RECORD(Records.ATTRIBUTE_CONVERSION_PLAN.get()),
808-
/** XQuery function. */
809-
CAPTURED_GROUP_RECORD(Records.CAPTURED_GROUP.get()),
810-
/** XQuery function. */
811-
COMPILED_REGEX_RECORD(Records.COMPILED_REGEX.get()),
812-
/** XQuery function. */
813-
DATETIME_RECORD(Records.DATETIME.get()),
814-
/** XQuery function. */
815-
DIVISION_RECORD(Records.DIVISION.get()),
816-
/** XQuery function. */
817-
ELEMENT_CONVERSION_PLAN_RECORD(Records.ELEMENT_CONVERSION_PLAN.get()),
818-
/** XQuery function. */
819-
_BIN_INFER_ENCODING_RECORD(Records.INFER_ENCODING.get()),
820-
/** XQuery function. */
821-
LOAD_XQUERY_MODULE_RECORD(Records.LOAD_XQUERY_MODULE.get()),
822-
/** XQuery function. */
823-
LOCATION_RECORD(Records.LOCATION.get()),
824-
/** XQuery function. */
825-
MATCHING_SEGMENT_RECORD(Records.MATCHING_SEGMENT.get()),
826-
/** XQuery function. */
827-
PARSED_CSV_STRUCTURE_RECORD(Records.PARSED_CSV_STRUCTURE.get()),
828-
/** XQuery function. */
829-
RANDOM_NUMBER_GENERATOR_RECORD(Records.RANDOM_NUMBER_GENERATOR.get()),
830-
/** XQuery function. */
831-
SCHEMA_TYPE_RECORD(Records.SCHEMA_TYPE.get()),
832-
/** XQuery function. */
833-
SORT_KEY_RECORD(Records.SORT_KEY.get()),
834-
/** XQuery function. */
835-
URI_STRUCTURE_RECORD(Records.URI_STRUCTURE.get()),
836-
/** XQuery function. */
837-
VALIDATION_RESULT_RECORD(Records.VALIDATION_RESULT.get()),
838-
839802
// Map Module
840803

841804
/** XQuery function. */
@@ -2206,14 +2169,6 @@ EMPTY_SEQUENCE_Z, flag(UPD), USER_URI, Perm.ADMIN),
22062169
/** Function definition. */
22072170
private final FuncDefinition definition;
22082171

2209-
/**
2210-
* Constructs a function signature for a predefined record constructor from a ShapeType.
2211-
* @param rt record type
2212-
*/
2213-
Function(final RecordType rt) {
2214-
this(ShapeConstructor.definition(rt));
2215-
}
2216-
22172172
/**
22182173
* Constructs a function signature; calls
22192174
* {@link #Function(Supplier, String, SeqType[], SeqType, EnumSet)}.

basex-core/src/main/java/org/basex/query/func/Functions.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,7 @@ private static Cast constructorCall(final QNm name, final FuncBuilder fb) throws
304304
private static StaticFuncCall staticCall(final QNm name, final FuncBuilder fb,
305305
final QueryContext qc) throws QueryException {
306306

307-
if(NSGlobal.reserved(name.uri()) && !Records.BUILT_IN.contains(name)) {
308-
throw qc.functions.similarError(name, fb.info);
309-
}
307+
if(NSGlobal.reserved(name.uri())) throw qc.functions.similarError(name, fb.info);
310308

311309
final StaticFuncCall call = new StaticFuncCall(name, fb.args(), fb.keywords, fb.info);
312310
qc.functions.setFunc(call, fb.runtime, qc);

basex-core/src/main/java/org/basex/query/func/ShapeConstructor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void toString(final QueryString qs) {
122122
* @param sh shape
123123
* @return constructor function definition
124124
*/
125-
public static FuncDefinition definition(final ShapeType sh) {
125+
private static FuncDefinition definition(final ShapeType sh) {
126126
final QNm name = sh.name();
127127
final TokenBuilder tb = new TokenBuilder(name != null ? name.local() :
128128
Token.token(sh instanceof RecordType ? QueryText.RECORD : QueryText.MAP)).add('(');

basex-core/src/test/java/org/basex/query/ModuleTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,6 @@ public final class ModuleTest extends SandboxTest {
216216
final IOFile q2 = new IOFile(sandbox, "q2.xqm");
217217
write(q2, "module namespace q = 'q';\n"
218218
+ "declare %private function x() {42};");
219-
final IOFile r = new IOFile(sandbox, "r.xqm");
220-
write(r, "module namespace r = 'r';\n"
221-
+ "declare function r:f() {\n"
222-
+ " fn:division-record(1, 2),\n"
223-
+ " fn:division-record#2(3, 4),\n"
224-
+ " 5 => fn:division-record(6),\n"
225-
+ " function-lookup(#fn:division-record, 2)(7, 8)\n"
226-
+ "};");
227219
final IOFile s = new IOFile(sandbox, "s.xqm");
228220
write(s, "module namespace s = 's';\n"
229221
+ "import module 's' at '" + s.path() + "';\n"
@@ -238,14 +230,6 @@ public final class ModuleTest extends SandboxTest {
238230
query("import module namespace q = 'q' at '" + q1.path() + "', '" + q2.path() + "';\n"
239231
+ "q:f()", 42);
240232

241-
// built-in record constructor visible in library module
242-
query("import module namespace r = 'r' at '" + r.path() + "';\n"
243-
+ "r:f()",
244-
"{\"quotient\":1,\"remainder\":2}\n"
245-
+ "{\"quotient\":3,\"remainder\":4}\n"
246-
+ "{\"quotient\":5,\"remainder\":6}\n"
247-
+ "{\"quotient\":7,\"remainder\":8}");
248-
249233
// private function reported as such
250234
error("import module namespace p = 'p' at '" + p.path() + "';\n"
251235
+ "p:x()", QueryError.FUNCPRIVATE_X);

basex-core/src/test/java/org/basex/query/expr/RecordTest.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import org.basex.*;
88
import org.basex.query.func.*;
9-
import org.basex.query.util.hash.*;
109
import org.basex.query.value.item.*;
1110
import org.basex.query.value.map.*;
1211
import org.basex.query.value.seq.*;
@@ -740,15 +739,13 @@ declare record cx:complex(r as xs:double, i as xs:double := ());
740739
"0\n0", exists(REPLICATE));
741740
}
742741

743-
/** Checks that every built-in record type has a constructor function in {@link Function}. */
744-
@Test public void builtInRecordsHaveConstructors() {
745-
final QNmSet funcNames = new QNmSet();
746-
for(final Function f : Function.values()) {
747-
funcNames.add(f.definition().name);
748-
}
742+
/** Checks that no built-in record type has a constructor function. */
743+
@Test public void builtInRecordsHaveNoConstructors() {
749744
for(final Records record : Records.values()) {
750-
assertTrue(funcNames.contains(record.get().name()),
751-
"Missing constructor function for " + record);
745+
assertFalse(Functions.BUILT_IN.contains(record.get().name()),
746+
"Constructor function for " + record);
752747
}
748+
error("fn:division-record(1, 2)", WHICHFUNC_X);
749+
error("fn:division-record#2", WHICHFUNC_X);
753750
}
754751
}

basex-core/src/test/java/org/basex/query/func/FnModuleTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ public final class FnModuleTest extends SandboxTest {
445445
query(func.args(" {\"day\": 3,"
446446
+ " \"timezone\": xs:dayTimeDuration('PT1H') }"),
447447
"---03+01:00");
448-
query(func.args(" dateTime-record(day:=4)"), "---04");
449448
// year 0
450449
query(func.args(" {\"year\": 0, \"month\": 1, \"day\": 1}"), "0000-01-01");
451450

0 commit comments

Comments
 (0)