Skip to content

Commit

Permalink
Merge branch 'topic/fixqualkit' into 'master'
Browse files Browse the repository at this point in the history
Remove `validateArgValue`, directly interpret values

Closes #94

See merge request eng/libadalang/langkit-query-language!74
  • Loading branch information
raph-amiard committed Jul 19, 2023
2 parents 82044fc + c1c4efd commit 754e72d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 53 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ endif

ADDITIONAL_MANAGE_ARGS=

# WARNING: Note that for some reason parallelizing the build still doesn't work
all: lkql lkql_checker lalcheck doc lkql_jit lkql_native_jit

lkql: build/bin/liblkqllang_parse

doc: lkql
Expand Down Expand Up @@ -59,7 +61,7 @@ lkql_jit: lkql
cd lkql_jit && mvn package install

lkql_native_jit: lkql
cd lkql_jit && mvn install -P native-all
cd lkql_jit && mvn package install -P native-all

.PHONY: lkql_checker

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,61 +499,17 @@ private void parseRulesArgs(LKQLContext context) {
Liblkqllang.GrammarRule.EXPR_RULE
);
Liblkqllang.LkqlNode root = unit.getRoot();
if (!validateArgValue(root)) {
throw LKQLRuntimeException.fromMessage("The rule argument value must be an LKQL literal : " + valueSource);
}
ASTTranslator translator = new ASTTranslator(null);
LKQLNode node = root.accept(translator);
Object value = node.executeGeneric(null);

// Add the argument in the context
context.addRuleArg(ruleName, argName, value);
}
}

/**
* Verify that the argument value is a literal expression
*
* @param node The node to verify
* @return If the node is a literal value, false else
*/
private static boolean validateArgValue(Liblkqllang.LkqlNode node) {
// If the node is just a literal it's value
if (node instanceof Liblkqllang.Literal) return true;

// Else if it's a tuple literal we must verify the expressions inside it
else if (node instanceof Liblkqllang.Tuple tupleLiteral) {
Liblkqllang.ExprList exprList = tupleLiteral.fExprs();
int childrenCount = exprList.getChildrenCount();
for (int i = 0; i < childrenCount; i++) {
if (!validateArgValue(exprList.getChild(i))) return false;
try {
Object value = node.executeGeneric(null);
// Add the argument in the context
context.addRuleArg(ruleName, argName, value);
} catch (Exception e) {
throw LKQLRuntimeException.fromMessage(
"The rule argument value generated an interpreter error: " + valueSource
);
}
return true;
}

// Else if it's a list literal we must verify the expressions of the list
else if (node instanceof Liblkqllang.ListLiteral listLiteral) {
Liblkqllang.ExprList exprList = listLiteral.fExprs();
int childrenCount = exprList.getChildrenCount();
for (int i = 0; i < childrenCount; i++) {
if (!validateArgValue(exprList.getChild(i))) return false;
}
return true;
}

// Else if it's an object literal we must verify all association values
else if (node instanceof Liblkqllang.ObjectLiteral objectLiteral) {
Liblkqllang.ObjectAssocList assocList = objectLiteral.fAssocs();
int childrenCount = assocList.getChildrenCount();
for (int i = 0; i < childrenCount; i++) {
Liblkqllang.ObjectAssoc assoc = (Liblkqllang.ObjectAssoc) assocList.getChild(i);
if (!validateArgValue(assoc.fExpr())) return false;
}
return true;
}

// By default return false
return false;
}

}

0 comments on commit 754e72d

Please sign in to comment.