use of lucee.transformer.expression.ExprString in project Lucee by lucee.
the class AbstrCFMLExprTransformer method string.
/*private Expression variable(Data data) throws TemplateException {
Expression expr=null;
// Dynamic
if((expr=dynamic(data))!=null) {
expr = subDynamic(data,expr);
data.mode=DYNAMIC;
return expr;
}
return null;
}*/
/**
* Transfomiert einen lierale Zeichenkette.
* <br />
* EBNF:<br />
* <code>("'" {"##"|"''"|"#" impOp "#"| ?-"#"-"'" } "'") |
* (""" {"##"|""""|"#" impOp "#"| ?-"#"-""" } """);</code>
* @param data
* @return CFXD Element
* @throws TemplateException
*/
protected Expression string(ExprData data) throws TemplateException {
// check starting character for a string literal
if (!data.srcCode.isCurrent('"') && !data.srcCode.isCurrent('\''))
return null;
Position line = data.srcCode.getPosition();
// Init Parameter
char quoter = data.srcCode.getCurrentLower();
StringBuilder str = new StringBuilder();
Expression expr = null;
while (data.srcCode.hasNext()) {
data.srcCode.next();
// check sharp
if (data.srcCode.isCurrent('#')) {
// Ecaped sharp
if (data.srcCode.isNext('#')) {
data.srcCode.next();
str.append('#');
} else // get Content of sharp
{
data.srcCode.next();
comments(data);
Expression inner = assignOp(data);
comments(data);
if (!data.srcCode.isCurrent('#'))
throw new TemplateException(data.srcCode, "Invalid Syntax Closing [#] not found");
ExprString exprStr = null;
if (str.length() != 0) {
exprStr = data.factory.createLitString(str.toString(), line, data.srcCode.getPosition());
if (expr != null) {
expr = data.factory.opString(expr, exprStr);
} else
expr = exprStr;
str = new StringBuilder();
}
if (expr == null) {
expr = inner;
} else {
expr = data.factory.opString(expr, inner);
}
}
} else // check quoter
if (data.srcCode.isCurrent(quoter)) {
// Ecaped sharp
if (data.srcCode.isNext(quoter)) {
data.srcCode.next();
str.append(quoter);
} else // finsish
{
break;
}
} else // all other character
{
str.append(data.srcCode.getCurrent());
}
}
if (!data.srcCode.forwardIfCurrent(quoter))
throw new TemplateException(data.srcCode, "Invalid Syntax Closing [" + quoter + "] not found");
if (expr == null)
expr = data.factory.createLitString(str.toString(), line, data.srcCode.getPosition());
else if (str.length() != 0) {
expr = data.factory.opString(expr, data.factory.createLitString(str.toString(), line, data.srcCode.getPosition()));
}
comments(data);
if (expr instanceof Variable) {
Variable var = (Variable) expr;
var.fromHash(true);
}
return expr;
}
use of lucee.transformer.expression.ExprString 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.ExprString in project Lucee by lucee.
the class Function method createArguments.
private final void createArguments(BytecodeContext bc) throws TransformerException {
GeneratorAdapter ga = bc.getAdapter();
ga.push(arguments.size());
ga.newArray(FUNCTION_ARGUMENT);
Argument arg;
for (int i = 0; i < arguments.size(); i++) {
arg = arguments.get(i);
boolean canHaveKey = Factory.canRegisterKey(arg.getName());
// CHECK if default values
// type
ExprString _strType = arg.getType();
short _type = CFTypes.TYPE_UNKNOW;
if (_strType instanceof LitString) {
_type = CFTypes.toShortStrict(((LitString) _strType).getString(), CFTypes.TYPE_UNKNOW);
}
boolean useType = !canHaveKey || _type != CFTypes.TYPE_ANY;
// boolean useStrType=useType && (_type==CFTypes.TYPE_UNDEFINED || _type==CFTypes.TYPE_UNKNOW || CFTypes.toString(_type, null)==null);
// required
ExprBoolean _req = arg.getRequired();
boolean useReq = !canHaveKey || toBoolean(_req, null) != Boolean.FALSE;
// default-type
Expression _def = arg.getDefaultValueType(bc.getFactory());
boolean useDef = !canHaveKey || toInt(_def, -1) != FunctionArgument.DEFAULT_TYPE_NULL;
// pass by reference
ExprBoolean _pass = arg.isPassByReference();
boolean usePass = !canHaveKey || toBoolean(_pass, null) != Boolean.TRUE;
// display-hint
ExprString _dsp = arg.getDisplayName();
boolean useDsp = !canHaveKey || !isLiteralEmptyString(_dsp);
// hint
ExprString _hint = arg.getHint();
boolean useHint = !canHaveKey || !isLiteralEmptyString(_hint);
// meta
Map _meta = arg.getMetaData();
boolean useMeta = !canHaveKey || (_meta != null && !_meta.isEmpty());
int functionIndex = 7;
if (!useMeta) {
functionIndex--;
if (!useHint) {
functionIndex--;
if (!useDsp) {
functionIndex--;
if (!usePass) {
functionIndex--;
if (!useDef) {
functionIndex--;
if (!useReq) {
functionIndex--;
if (!useType) {
functionIndex--;
}
}
}
}
}
}
}
// write out arguments
ga.dup();
ga.push(i);
// new FunctionArgument(...)
ga.newInstance(canHaveKey && functionIndex < INIT_FAI_KEY_LIGHT.length ? FUNCTION_ARGUMENT_LIGHT : FUNCTION_ARGUMENT_IMPL);
ga.dup();
// name
bc.getFactory().registerKey(bc, arg.getName(), false);
// type
if (functionIndex >= INIT_FAI_KEY.length - 7) {
_strType.writeOut(bc, Expression.MODE_REF);
bc.getAdapter().push(_type);
}
// required
if (functionIndex >= INIT_FAI_KEY.length - 6)
_req.writeOut(bc, Expression.MODE_VALUE);
// default value
if (functionIndex >= INIT_FAI_KEY.length - 5)
_def.writeOut(bc, Expression.MODE_VALUE);
// pass by reference
if (functionIndex >= INIT_FAI_KEY.length - 4)
_pass.writeOut(bc, Expression.MODE_VALUE);
// display-name
if (functionIndex >= INIT_FAI_KEY.length - 3)
_dsp.writeOut(bc, Expression.MODE_REF);
// hint
if (functionIndex >= INIT_FAI_KEY.length - 2)
_hint.writeOut(bc, Expression.MODE_REF);
// meta
if (functionIndex == INIT_FAI_KEY.length - 1)
Page.createMetaDataStruct(bc, _meta, null);
if (functionIndex < INIT_FAI_KEY_LIGHT.length)
ga.invokeConstructor(FUNCTION_ARGUMENT_LIGHT, INIT_FAI_KEY[functionIndex]);
else
ga.invokeConstructor(FUNCTION_ARGUMENT_IMPL, INIT_FAI_KEY[functionIndex]);
ga.visitInsn(Opcodes.AASTORE);
}
}
use of lucee.transformer.expression.ExprString in project Lucee by lucee.
the class VT method _writeOutFirstDataMember.
Type _writeOutFirstDataMember(BytecodeContext bc, DataMember member, int scope, boolean last, boolean doOnlyScope, Expression defaultValue, RefInteger startIndex) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();
if (startIndex != null)
startIndex.setValue(doOnlyScope ? 0 : 1);
// this/static
if (scope == Scope.SCOPE_UNDEFINED) {
ExprString name = member.getName();
if (ASMUtil.isDotKey(name)) {
LitString ls = (LitString) name;
// THIS
if (ls.getString().equalsIgnoreCase("THIS")) {
if (startIndex != null)
startIndex.setValue(1);
adapter.loadArg(0);
adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
if (defaultValue != null) {
defaultValue.writeOut(bc, MODE_REF);
adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, (countFM + countDM) == 1 ? THIS_GET1 : THIS_TOUCH1);
} else
adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, (countFM + countDM) == 1 ? THIS_GET0 : THIS_TOUCH0);
return Types.OBJECT;
}
// STATIC
if (ls.getString().equalsIgnoreCase("STATIC")) {
if (startIndex != null)
startIndex.setValue(1);
adapter.loadArg(0);
adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
if (defaultValue != null) {
defaultValue.writeOut(bc, MODE_REF);
adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, (countFM + countDM) == 1 ? STATIC_GET1 : STATIC_TOUCH1);
} else
adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, (countFM + countDM) == 1 ? STATIC_GET0 : STATIC_TOUCH0);
return Types.OBJECT;
}
}
}
if (member.getSafeNavigated())
adapter.loadArg(0);
// collection
Type rtn;
if (scope == Scope.SCOPE_LOCAL && defaultValue != null) {
// local
adapter.loadArg(0);
adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
getFactory().FALSE().writeOut(bc, MODE_VALUE);
defaultValue.writeOut(bc, MODE_VALUE);
adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, TypeScope.METHOD_LOCAL_EL);
rtn = Types.OBJECT;
} else {
// all other scopes
adapter.loadArg(0);
rtn = TypeScope.invokeScope(adapter, scope);
}
if (doOnlyScope)
return rtn;
getFactory().registerKey(bc, member.getName(), false);
boolean _last = !last && scope == Scope.SCOPE_UNDEFINED;
if (!member.getSafeNavigated()) {
adapter.invokeInterface(TypeScope.SCOPES[scope], _last ? METHOD_SCOPE_GET_COLLECTION_KEY : METHOD_SCOPE_GET_KEY);
} else {
// LDEV-1201
Expression val = member.getSafeNavigatedValue();
if (val == null)
ASMConstants.NULL(bc.getAdapter());
else
val.writeOut(bc, Expression.MODE_REF);
adapter.invokeVirtual(Types.PAGE_CONTEXT, _last ? GET_COLLECTION[THREE] : GET[THREE]);
}
return Types.OBJECT;
}
use of lucee.transformer.expression.ExprString in project Lucee by lucee.
the class AbstrCFMLExprTransformer method subDynamic.
private Expression subDynamic(ExprData data, Expression expr, boolean tryStatic, boolean isStaticChild) throws TemplateException {
String name = null;
Invoker invoker = null;
// Loop over nested Variables
boolean safeNavigation;
while (data.srcCode.isValidIndex()) {
safeNavigation = false;
ExprString nameProp = null, namePropUC = null;
// []
if (data.srcCode.forwardIfCurrent('[')) {
isStaticChild = false;
// get Next Var
nameProp = structElement(data);
namePropUC = nameProp;
// Valid Syntax ???
if (!data.srcCode.forwardIfCurrent(']'))
throw new TemplateException(data.srcCode, "Invalid Syntax Closing []] not found");
} else // .
if (isStaticChild || data.srcCode.forwardIfCurrent('.') || (safeNavigation = data.srcCode.forwardIfCurrent('?', '.'))) {
isStaticChild = false;
// Extract next Var String
comments(data);
Position line = data.srcCode.getPosition();
name = identifier(data, true);
if (name == null)
throw new TemplateException(data.srcCode, "Invalid identifier");
comments(data);
nameProp = Identifier.toIdentifier(data.factory, name, line, data.srcCode.getPosition());
namePropUC = Identifier.toIdentifier(data.factory, name, data.settings.dotNotationUpper ? Identifier.CASE_UPPER : Identifier.CASE_ORIGNAL, line, data.srcCode.getPosition());
} else // finish
{
break;
}
comments(data);
if (expr instanceof Invoker) {
invoker = (Invoker) expr;
} else {
invoker = new ExpressionInvoker(expr);
expr = invoker;
}
// safe navigation
Member member;
if (safeNavigation) {
List<Member> members = invoker.getMembers();
if (members.size() > 0) {
member = members.get(members.size() - 1);
member.setSafeNavigated(true);
}
}
// Method
if (data.srcCode.isCurrent('(')) {
// properly this is never used
if (nameProp == null && name != null)
nameProp = Identifier.toIdentifier(data.factory, name, Identifier.CASE_ORIGNAL, null, null);
invoker.addMember(member = getFunctionMember(data, nameProp, false));
} else
// property
invoker.addMember(member = data.factory.createDataMember(namePropUC));
if (safeNavigation) {
member.setSafeNavigated(true);
}
}
// STATIC SCOPE CALL
if (tryStatic) {
comments(data);
Expression staticCall = staticScope(data, expr);
if (staticCall != null)
return staticCall;
}
return expr;
}
Aggregations