Skip to content
Snippets Groups Projects
Commit 2fb34219 authored by Julien Lopez's avatar Julien Lopez
Browse files

- Add QIRNot

- Fix QIRFreeVarsVisitor
parent b3e33ef2
No related branches found
No related tags found
No related merge requests found
package qir.ast.expression.logic;
import com.oracle.truffle.api.source.*;
import qir.ast.*;
import qir.util.*;
/**
* The {@link QIRNot} represents an expression that is true if and only if the {@link #left}
* expression and the {@link #right} expression are true.
*/
public final class QIRNot extends QIRNode {
/**
* The left side of the {@link QIRNot} operator.
*/
private final QIRNode child;
public QIRNot(SourceSection source, QIRNode child) {
super(source);
this.child = child;
}
public QIRNode getChild() {
return child;
}
@Override
public <T> T accept(IQIRVisitor<T> visitor) {
return visitor.visit(this);
}
}
\ No newline at end of file
package qir.util;
import java.util.HashSet;
import java.util.HashMap;
import qir.ast.*;
import qir.ast.data.*;
......@@ -13,201 +13,201 @@ import qir.ast.value.*;
/**
* This visitor returns the list of free variables in a query.
*/
public final class QIRFreeVarsVisitor implements IQIRVisitor<HashSet<QIRVariable>> {
final private HashSet<QIRVariable> freeVariables = new HashSet<>();
final private HashSet<QIRVariable> boundVariables = new HashSet<>();
public final class QIRFreeVarsVisitor implements IQIRVisitor<HashMap<String, QIRVariable>> {
final private HashMap<String, QIRVariable> freeVariables = new HashMap<>();
final private HashMap<String, QIRVariable> boundVariables = new HashMap<>();
@Override
public HashSet<QIRVariable> visit(QIRProject qirProject) {
public HashMap<String, QIRVariable> visit(QIRProject qirProject) {
qirProject.getFormatter().accept(this);
return qirProject.getChild().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRScan qirScan) {
public HashMap<String, QIRVariable> visit(QIRScan qirScan) {
return qirScan.getTable().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRSelect qirSelect) {
public HashMap<String, QIRVariable> visit(QIRSelect qirSelect) {
qirSelect.getFilter().accept(this);
return qirSelect.getChild().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRGroup qirGroup) {
public HashMap<String, QIRVariable> visit(QIRGroup qirGroup) {
qirGroup.getEq().accept(this);
qirGroup.getGroup().accept(this);
return qirGroup.getChild().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIROrder qirOrder) {
public HashMap<String, QIRVariable> visit(QIROrder qirOrder) {
qirOrder.getOrder().accept(this);
return qirOrder.getChild().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRLambda qirLambda) {
public HashMap<String, QIRVariable> visit(QIRLambda qirLambda) {
QIRVariable arg = qirLambda.getVar();
boundVariables.add(arg);
boundVariables.put(arg.getId(), arg);
qirLambda.getBody().accept(this);
boundVariables.remove(arg);
return freeVariables;
}
@Override
public HashSet<QIRVariable> visit(QIRApply qirApply) {
public HashMap<String, QIRVariable> visit(QIRApply qirApply) {
qirApply.getLeft().accept(this);
return qirApply.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRPlus qirPlus) {
public HashMap<String, QIRVariable> visit(QIRPlus qirPlus) {
qirPlus.getLeft().accept(this);
return qirPlus.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRMinus qirMinus) {
public HashMap<String, QIRVariable> visit(QIRMinus qirMinus) {
qirMinus.getLeft().accept(this);
return qirMinus.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRStar qirStar) {
public HashMap<String, QIRVariable> visit(QIRStar qirStar) {
qirStar.getLeft().accept(this);
return qirStar.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRDiv qirDiv) {
public HashMap<String, QIRVariable> visit(QIRDiv qirDiv) {
qirDiv.getLeft().accept(this);
return qirDiv.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRMod qirMod) {
public HashMap<String, QIRVariable> visit(QIRMod qirMod) {
qirMod.getLeft().accept(this);
return qirMod.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRAnd qirAnd) {
public HashMap<String, QIRVariable> visit(QIRAnd qirAnd) {
qirAnd.getLeft().accept(this);
return qirAnd.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIROr qirOr) {
public HashMap<String, QIRVariable> visit(QIROr qirOr) {
qirOr.getLeft().accept(this);
return qirOr.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIREqual qirEqual) {
public HashMap<String, QIRVariable> visit(QIREqual qirEqual) {
qirEqual.getLeft().accept(this);
return qirEqual.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRGreaterOrEqual qirGreaterOrEqual) {
public HashMap<String, QIRVariable> visit(QIRGreaterOrEqual qirGreaterOrEqual) {
qirGreaterOrEqual.getLeft().accept(this);
return qirGreaterOrEqual.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRGreaterThan qirGreaterThan) {
public HashMap<String, QIRVariable> visit(QIRGreaterThan qirGreaterThan) {
qirGreaterThan.getLeft().accept(this);
return qirGreaterThan.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRLowerOrEqual qirLowerOrEqual) {
public HashMap<String, QIRVariable> visit(QIRLowerOrEqual qirLowerOrEqual) {
qirLowerOrEqual.getLeft().accept(this);
return qirLowerOrEqual.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRLowerThan qirLowerThan) {
public HashMap<String, QIRVariable> visit(QIRLowerThan qirLowerThan) {
qirLowerThan.getLeft().accept(this);
return qirLowerThan.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRNotEqual qirNotEqual) {
public HashMap<String, QIRVariable> visit(QIRNotEqual qirNotEqual) {
qirNotEqual.getLeft().accept(this);
return qirNotEqual.getRight().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRTable qirTable) {
public HashMap<String, QIRVariable> visit(QIRTable qirTable) {
return freeVariables;
}
@Override
public HashSet<QIRVariable> visit(QIRLnil qirLnil) {
public HashMap<String, QIRVariable> visit(QIRLnil qirLnil) {
return freeVariables;
}
@Override
public HashSet<QIRVariable> visit(QIRLcons qirLcons) {
public HashMap<String, QIRVariable> visit(QIRLcons qirLcons) {
qirLcons.getValue().accept(this);
return qirLcons.getTail().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRLdestr qirLdestr) {
public HashMap<String, QIRVariable> visit(QIRLdestr qirLdestr) {
qirLdestr.getList().accept(this);
qirLdestr.getIfEmpty().accept(this);
return qirLdestr.getHandler().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRTnil qirTnil) {
public HashMap<String, QIRVariable> visit(QIRTnil qirTnil) {
return freeVariables;
}
@Override
public HashSet<QIRVariable> visit(QIRTcons qirTcons) {
public HashMap<String, QIRVariable> visit(QIRTcons qirTcons) {
qirTcons.getValue().accept(this);
return qirTcons.getTail().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRTdestr qirTdestr) {
public HashMap<String, QIRVariable> visit(QIRTdestr qirTdestr) {
return qirTdestr.getTuple().accept(this);
}
@Override
public HashSet<QIRVariable> visit(QIRString qirString) {
public HashMap<String, QIRVariable> visit(QIRString qirString) {
return freeVariables;
}
@Override
public HashSet<QIRVariable> visit(QIRNumber qirNumber) {
public HashMap<String, QIRVariable> visit(QIRNumber qirNumber) {
return freeVariables;
}
@Override
public HashSet<QIRVariable> visit(QIRBigNumber qirBigNumber) {
public HashMap<String, QIRVariable> visit(QIRBigNumber qirBigNumber) {
return freeVariables;
}
@Override
public HashSet<QIRVariable> visit(QIRBoolean qirBoolean) {
public HashMap<String, QIRVariable> visit(QIRBoolean qirBoolean) {
return freeVariables;
}
@Override
public HashSet<QIRVariable> visit(QIRTruffleNode qirTruffleNode) {
public HashMap<String, QIRVariable> visit(QIRTruffleNode qirTruffleNode) {
return freeVariables;
}
@Override
public HashSet<QIRVariable> visit(QIRVariable qirVariable) {
if (!boundVariables.contains(qirVariable))
freeVariables.add(qirVariable);
public HashMap<String, QIRVariable> visit(QIRVariable qirVariable) {
if (!boundVariables.containsKey(qirVariable.getId()))
freeVariables.put(qirVariable.getId(), qirVariable);
return freeVariables;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment