use of lucee.transformer.expression.Expression 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.Expression in project Lucee by lucee.
the class VT method _writeOutUDF.
private static Type _writeOutUDF(BytecodeContext bc, UDF udf) throws TransformerException {
bc.getFactory().registerKey(bc, udf.getName(), false);
Argument[] args = udf.getArguments();
// no arguments
if (args.length == 0) {
bc.getAdapter().getStatic(Types.CONSTANTS, "EMPTY_OBJECT_ARRAY", Types.OBJECT_ARRAY);
} else
ExpressionUtil.writeOutExpressionArray(bc, Types.OBJECT, args);
int type;
if (udf.getSafeNavigated()) {
type = THREE;
Expression val = udf.getSafeNavigatedValue();
if (val == null) {
ASMConstants.NULL(bc.getAdapter());
type = THREE;
} else {
val.writeOut(bc, Expression.MODE_REF);
type = THREE2;
}
} else
type = TWO;
bc.getAdapter().invokeVirtual(udf.getSafeNavigated() ? Types.PAGE_CONTEXT_IMPL : Types.PAGE_CONTEXT, udf.hasNamedArgs() ? GET_FUNCTION_WITH_NAMED_ARGS[type] : GET_FUNCTION[type]);
return Types.OBJECT;
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class VariableString method variableToStringArray.
public static String[] variableToStringArray(Variable var, boolean rawIfPossible) throws TransformerException {
List<Member> members = var.getMembers();
List<String> arr = new ArrayList<String>();
if (var.getScope() != Scope.SCOPE_UNDEFINED)
arr.add(ScopeFactory.toStringScope(var.getScope(), "undefined"));
Iterator<Member> it = members.iterator();
DataMember dm;
Expression n;
while (it.hasNext()) {
Object o = it.next();
if (!(o instanceof DataMember))
throw new TransformerException("can't translate Variable to a String", var.getStart());
dm = (DataMember) o;
n = dm.getName();
if (n instanceof Literal) {
if (rawIfPossible && n instanceof Identifier) {
arr.add(((Identifier) n).getRaw());
} else {
arr.add(((Literal) n).getString());
}
} else
throw new TransformerException("argument name must be a constant value", var.getStart());
}
return arr.toArray(new String[arr.size()]);
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class CFMLTransformer method transform.
/**
* Startmethode zum transfomieren einer CFML Datei.
* <br />
* EBNF:<br />
* <code>{body}</code>
* @param config
* @param ps CFML File
* @param tlibs Tag Library Deskriptoren, nach denen innerhalb der CFML Datei geprueft werden soll.
* @param flibs Function Library Deskriptoren, nach denen innerhalb der Expressions der CFML Datei geprueft werden soll.
* @param returnValue if true the method returns the value of the last expression executed inside when you call the method "call"
* @return uebersetztes CFXD Dokument Element.
* @throws TemplateException
* @throws IOException
*/
public Page transform(Factory factory, ConfigImpl config, PageSource ps, TagLib[] tlibs, FunctionLib[] flibs, boolean returnValue, boolean ignoreScopes) throws TemplateException, IOException {
Page p;
SourceCode sc;
boolean writeLog = config.getExecutionLogEnabled();
Charset charset = config.getTemplateCharset();
boolean dotUpper = ps.getDialect() == CFMLEngine.DIALECT_CFML && ((MappingImpl) ps.getMapping()).getDotNotationUpperCase();
// parse regular
while (true) {
try {
sc = new PageSourceCode(ps, charset, writeLog);
p = transform(factory, config, sc, tlibs, flibs, ps.getResource().lastModified(), dotUpper, returnValue, ignoreScopes);
break;
} catch (ProcessingDirectiveException pde) {
if (pde.getWriteLog() != null)
writeLog = pde.getWriteLog().booleanValue();
if (pde.getDotNotationUpperCase() != null)
dotUpper = pde.getDotNotationUpperCase().booleanValue();
if (!StringUtil.isEmpty(pde.getCharset()))
charset = pde.getCharset();
}
}
// could it be a component?
boolean isCFML = ps.getDialect() == CFMLEngine.DIALECT_CFML;
boolean isCFMLCompExt = isCFML && Constants.isCFMLComponentExtension(ResourceUtil.getExtension(ps.getResource(), ""));
boolean possibleUndetectedComponent = false;
// we don't have a component or interface
if (p.isPage()) {
if (isCFML)
possibleUndetectedComponent = isCFMLCompExt;
else if (Constants.isLuceeComponentExtension(ResourceUtil.getExtension(ps.getResource(), ""))) {
Expression expr;
Statement stat;
PrintOut po;
LitString ls;
List<Statement> statements = p.getStatements();
// check the root statements for component
Iterator<Statement> it = statements.iterator();
String str;
while (it.hasNext()) {
stat = it.next();
if (stat instanceof PrintOut && (expr = ((PrintOut) stat).getExpr()) instanceof LitString) {
ls = (LitString) expr;
str = ls.getString();
if (str.indexOf(Constants.LUCEE_COMPONENT_TAG_NAME) != -1 || str.indexOf(Constants.LUCEE_INTERFACE_TAG_NAME) != -1 || // cfml name is supported as alias
str.indexOf(Constants.CFML_COMPONENT_TAG_NAME) != -1) {
possibleUndetectedComponent = true;
break;
}
}
}
}
}
/*if(p.isPage() && (isCFML?
Constants.isCFMLComponentExtension(ResourceUtil.getExtension(ps.getResource(),"")):
Constants.isLuceeComponentExtension(ResourceUtil.getExtension(ps.getResource(),""))) &&
isPossibleRawScript(sc,config.getIdentification())){*/
if (possibleUndetectedComponent) {
Page _p;
TagLibTag scriptTag = CFMLTransformer.getTLT(sc, isCFML ? Constants.CFML_SCRIPT_TAG_NAME : Constants.LUCEE_SCRIPT_TAG_NAME, config.getIdentification());
sc.setPos(0);
SourceCode original = sc;
// try inside a cfscript
String text = "<" + scriptTag.getFullName() + ">" + original.getText() + "\n</" + scriptTag.getFullName() + ">";
sc = new PageSourceCode(ps, text, charset, writeLog);
try {
while (true) {
if (sc == null) {
sc = new PageSourceCode(ps, charset, writeLog);
text = "<" + scriptTag.getFullName() + ">" + sc.getText() + "\n</" + scriptTag.getFullName() + ">";
sc = new PageSourceCode(ps, text, charset, writeLog);
}
try {
_p = transform(factory, config, sc, tlibs, flibs, ps.getResource().lastModified(), dotUpper, returnValue, ignoreScopes);
break;
} catch (ProcessingDirectiveException pde) {
if (pde.getWriteLog() != null)
writeLog = pde.getWriteLog().booleanValue();
if (pde.getDotNotationUpperCase() != null)
dotUpper = pde.getDotNotationUpperCase().booleanValue();
if (!StringUtil.isEmpty(pde.getCharset()))
charset = pde.getCharset();
sc = null;
}
}
} catch (ComponentTemplateException e) {
throw e.getTemplateException();
}
// we only use that result if it is a component now
if (_p != null && !_p.isPage())
return _p;
}
if (isCFMLCompExt && !p.isComponent() && !p.isInterface()) {
String msg = "template [" + ps.getDisplayPath() + "] must contain a component or an interface.";
if (sc != null)
throw new TemplateException(sc, msg);
throw new TemplateException(msg);
}
return p;
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class CFMLTransformer method attribute.
/**
* Liest ein einzelnes Atribut eines tag ein (nicht NONAME).
* <br />
* EBNF:<br />
* <code>attribute-name spaces "=" spaces attribute-value;</code>
* @param tag Definition des Tag das dieses Attribut enthaelt.
* @param args Container zum Speichern einzelner Attribute Namen zum nachtraeglichen Prufen gegen die Tag-Lib.
* @return Element Attribute Element.
* @throws TemplateException
*/
private static Attribute attribute(TagData data, TagLibTag tag, ArrayList<String> args, RefBoolean allowDefaultValue) throws TemplateException {
Expression value = null;
// Name
StringBuffer sbType = new StringBuffer();
RefBoolean dynamic = new RefBooleanImpl(false);
boolean isDefaultValue = false;
boolean[] parseExpression = new boolean[2];
parseExpression[0] = true;
parseExpression[1] = false;
String name = attributeName(data.srcCode, dynamic, args, tag, sbType, parseExpression, allowDefaultValue.toBooleanValue());
// mixed in a noname attribute
if (StringUtil.isEmpty(name)) {
allowDefaultValue.setValue(false);
TagLibTagAttr attr = tag.getDefaultAttribute();
if (attr == null)
throw new TemplateException(data.srcCode, "Invalid Identifier.");
name = attr.getName();
sbType.append(attr.getType());
isDefaultValue = true;
}
comment(data.srcCode, true);
if (isDefaultValue || data.srcCode.forwardIfCurrent('=')) {
comment(data.srcCode, true);
// Value
value = attributeValue(data, tag, sbType.toString(), parseExpression[0], false, data.factory.createLitString(""));
} else // default value boolean true
{
TagLibTagAttr attr = tag.getAttribute(name);
if (attr != null)
value = attr.getUndefinedValue(data.factory);
else
value = tag.getAttributeUndefinedValue(data.factory);
if (sbType.toString().length() > 0) {
value = CastOther.toExpression(value, sbType.toString());
}
}
comment(data.srcCode, true);
return new Attribute(dynamic.toBooleanValue(), name, value, sbType.toString());
}
Aggregations