use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class AbstrCFMLExprTransformer method scope.
/**
* Liest einen CFML Scope aus,
* falls der folgende identifier keinem Scope entspricht,
* gibt die Variable null zurueck.
* <br />
* EBNF:<br />
* <code>"variable" | "cgi" | "url" | "form" | "session" | "application" | "arguments" | "cookie" | " client";</code>
* @param id String identifier,
* wird aus Optimierungszwechen nicht innerhalb dieser Funktion ausgelsen.
* @return CFXD Variable Element oder null
* @throws TemplateException
*/
private Variable scope(ExprData data, Identifier id, Position line) throws TemplateException {
String idStr = id.getUpper();
if (idStr.equals("ARGUMENTS"))
return data.factory.createVariable(Scope.SCOPE_ARGUMENTS, line, data.srcCode.getPosition());
else if (idStr.equals("LOCAL"))
return data.factory.createVariable(Scope.SCOPE_LOCAL, line, data.srcCode.getPosition());
else if (idStr.equals("VAR")) {
Identifier _id = identifier(data, false, true);
if (_id != null) {
comments(data);
Variable local = data.factory.createVariable(ScopeSupport.SCOPE_VAR, line, data.srcCode.getPosition());
if (!"LOCAL".equalsIgnoreCase(_id.getString()))
local.addMember(data.factory.createDataMember(_id));
else {
local.ignoredFirstMember(true);
}
return local;
}
} else if (idStr.equals("VARIABLES"))
return data.factory.createVariable(Scope.SCOPE_VARIABLES, line, data.srcCode.getPosition());
else if (idStr.equals("REQUEST"))
return data.factory.createVariable(Scope.SCOPE_REQUEST, line, data.srcCode.getPosition());
else if (idStr.equals("SERVER"))
return data.factory.createVariable(Scope.SCOPE_SERVER, line, data.srcCode.getPosition());
if (data.settings.ignoreScopes)
return null;
if (idStr.equals("CGI"))
return data.factory.createVariable(Scope.SCOPE_CGI, line, data.srcCode.getPosition());
else if (idStr.equals("SESSION"))
return data.factory.createVariable(Scope.SCOPE_SESSION, line, data.srcCode.getPosition());
else if (idStr.equals("APPLICATION"))
return data.factory.createVariable(Scope.SCOPE_APPLICATION, line, data.srcCode.getPosition());
else if (idStr.equals("FORM"))
return data.factory.createVariable(Scope.SCOPE_FORM, line, data.srcCode.getPosition());
else if (idStr.equals("URL"))
return data.factory.createVariable(Scope.SCOPE_URL, line, data.srcCode.getPosition());
else if (idStr.equals("CLIENT"))
return data.factory.createVariable(Scope.SCOPE_CLIENT, line, data.srcCode.getPosition());
else if (idStr.equals("COOKIE"))
return data.factory.createVariable(Scope.SCOPE_COOKIE, line, data.srcCode.getPosition());
else if (idStr.equals("CLUSTER"))
return data.factory.createVariable(Scope.SCOPE_CLUSTER, line, data.srcCode.getPosition());
return null;
}
use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class TryCatchFinally method addCatch.
/**
* @param type
* @param name
* @param b
* @param line
* @throws TransformerException
*/
public void addCatch(Expression type, Expression name, Body b, Position line) throws TransformerException {
// type
if (type == null || type instanceof ExprString)
;
else if (type instanceof Variable) {
type = VariableString.toExprString(type);
} else
throw new TransformerException("type from catch statement is invalid", type.getStart());
// name
if (name instanceof LitString) {
Variable v = getFactory().createVariable(Scope.SCOPE_UNDEFINED, name.getStart(), name.getEnd());
v.addMember(getFactory().createDataMember(getFactory().toExprString(name)));
name = new VariableRef(v, true);
} else if (name instanceof Variable)
name = new VariableRef((Variable) name, true);
else
throw new TransformerException("name from catch statement is invalid", name.getStart());
addCatch((ExprString) type, (VariableRef) name, b, line);
}
use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class QueryExecute method evaluate.
@Override
public void evaluate(BIF bif, FunctionLibFunction flf) throws EvaluatorException {
Variable var = bif.getParent();
if (var != null) {
Assign ass = var.assign();
if (ass != null) {
try {
String str = VariableString.variableToString(ass.getVariable(), false);
addArgument(bif, str);
} catch (TransformerException e) {
SystemOut.printDate(e);
}
}
}
}
use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class Query method translateChildren.
private void translateChildren(Iterator it) {
Statement stat;
while (it.hasNext()) {
stat = (Statement) it.next();
if (stat instanceof PrintOut) {
PrintOut printOut = ((PrintOut) stat);
Expression e = printOut.getExpr();
if (!(e instanceof Literal)) {
Expression expr = removeCastString(e);
if (expr instanceof Variable) {
// do not preserve BIF PreserveSingleQuotes return value
Member member = ((Variable) expr).getFirstMember();
if (member instanceof BIF) {
BIF bif = (BIF) member;
if (bif.getClassDefinition().getClassName().equals(PreserveSingleQuotes.class.getName())) {
printOut.setExpr(bif.getArguments()[0].getValue());
continue;
} else if (bif.getClassDefinition().getClassName().equals(ListQualify.class.getName())) {
Argument[] args = bif.getArguments();
List<Argument> arr = new ArrayList<Argument>();
// first get existing arguments
arr.add(args[0]);
arr.add(args[1]);
if (args.length >= 3)
arr.add(args[2]);
else
arr.add(new Argument(expr.getFactory().createLitString(","), "string"));
if (args.length >= 4)
arr.add(args[3]);
else
arr.add(new Argument(expr.getFactory().createLitString("all"), "string"));
if (args.length >= 5)
arr.add(args[4]);
else
arr.add(new Argument(expr.getFactory().createLitBoolean(false), "boolean"));
// PSQ-BIF DO NOT REMOVE THIS COMMENT
arr.add(new Argument(expr.getFactory().createLitBoolean(true), "boolean"));
bif.setArguments(arr.toArray(new Argument[arr.size()]));
continue;
} else if (bif.getClassDefinition().getClassName().equals(QuotedValueList.class.getName()) || bif.getClassDefinition().getClassName().equals(ValueList.class.getName())) {
// printOut.setPreserveSingleQuote(false);
continue;
}
}
// do not preserve UDF return value
member = ((Variable) expr).getLastMember();
if (member instanceof UDF)
continue;
}
printOut.setCheckPSQ(true);
if (e != expr)
printOut.setExpr(expr);
}
} else if (stat instanceof Tag) {
Body b = ((Tag) stat).getBody();
if (b != null)
translateChildren(b.getStatements().iterator());
} else if (stat instanceof Body) {
translateChildren(((Body) stat).getStatements().iterator());
}
}
}
use of lucee.transformer.expression.var.Variable in project Lucee by lucee.
the class AbstrCFMLExprTransformer method conditionalOp.
private Expression conditionalOp(ExprData data) throws TemplateException {
Expression expr = impOp(data);
if (data.srcCode.forwardIfCurrent('?')) {
comments(data);
// Elvis
if (data.srcCode.forwardIfCurrent(':')) {
comments(data);
Expression right = assignOp(data);
if (expr instanceof ExprBoolean)
return expr;
if (!(expr instanceof Variable))
throw new TemplateException(data.srcCode, "left operand of the Elvis operator has to be a variable or a function call");
Variable left = (Variable) expr;
/*List<Member> members = left.getMembers();
Member last=null;
for(Member m:members) {
last=m;
m.setSafeNavigated(true);
}
if(last!=null) {
last.setSafeNavigatedValue(right);
}
return left;*/
return OpElvis.toExpr(left, right);
}
Expression left = assignOp(data);
comments(data);
if (!data.srcCode.forwardIfCurrent(':'))
throw new TemplateException(data.srcCode, "invalid conditional operator");
comments(data);
Expression right = assignOp(data);
expr = OpContional.toExpr(expr, left, right);
}
return expr;
}
Aggregations