use of lucee.transformer.expression.literal.LitString in project Lucee by lucee.
the class SourceLastModifiedClassAdapter method execute.
/**
* convert the Page Object to java bytecode
* @param className name of the genrated class (only necessary when Page object has no PageSource reference)
* @return
* @throws TransformerException
*/
public byte[] execute(String className) throws TransformerException {
// not exists in any case, so every usage must have a plan b for not existence
PageSource optionalPS = sourceCode instanceof PageSourceCode ? ((PageSourceCode) sourceCode).getPageSource() : null;
List<LitString> keys = new ArrayList<LitString>();
ClassWriter cw = ASMUtil.getClassWriter();
ArrayList<String> imports = new ArrayList<String>();
getImports(imports, this);
// look for component if necessary
TagCIObject comp = getTagCFObject(null);
// in case we have a sub component
if (className == null) {
if (optionalPS == null)
throw new IllegalArgumentException("when Page object has no PageSource, a className is necessary");
className = optionalPS.getClassName();
}
if (comp != null)
className = createSubClass(className, comp.getName(), sourceCode.getDialect());
className = className.replace('.', '/');
this.className = className;
// parent
// "lucee/runtime/Page";
String parent = PageImpl.class.getName();
if (// "lucee/runtime/ComponentPage";
isComponent(comp))
// "lucee/runtime/ComponentPage";
parent = ComponentPageImpl.class.getName();
else // "lucee/runtime/InterfacePage";
if (isInterface(comp))
parent = InterfacePageImpl.class.getName();
parent = parent.replace('.', '/');
cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, className, null, parent, null);
if (optionalPS != null) {
// we use full path when FD is enabled
String path = config.allowRequestTimeout() ? optionalPS.getRealpathWithVirtual() : optionalPS.getPhyscalFile().getAbsolutePath();
// when adding more use ; as delimiter
cw.visitSource(path, null);
// cw.visitSource(optionalPS.getPhyscalFile().getAbsolutePath(),
// "rel:"+optionalPS.getRealpathWithVirtual()); // when adding more use ; as delimiter
} else {
// cw.visitSource("","rel:");
}
// static constructor
// GeneratorAdapter statConstrAdapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC,STATIC_CONSTRUCTOR,null,null,cw);
// StaticConstrBytecodeContext statConstr = null;//new BytecodeContext(null,null,this,externalizer,keys,cw,name,statConstrAdapter,STATIC_CONSTRUCTOR,writeLog(),suppressWSbeforeArg);
// constructor
GeneratorAdapter constrAdapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR_PS, null, null, cw);
ConstrBytecodeContext constr = new ConstrBytecodeContext(optionalPS, this, keys, cw, className, constrAdapter, CONSTRUCTOR_PS, writeLog(), suppressWSbeforeArg, output, returnValue);
constrAdapter.loadThis();
Type t;
if (isComponent(comp)) {
t = Types.COMPONENT_PAGE_IMPL;
// extends
// Attribute attr = comp.getAttribute("extends");
// if(attr!=null) ExpressionUtil.writeOutSilent(attr.getValue(),constr, Expression.MODE_REF);
// else constrAdapter.push("");
constrAdapter.invokeConstructor(t, CONSTRUCTOR);
} else if (isInterface(comp)) {
t = Types.INTERFACE_PAGE_IMPL;
constrAdapter.invokeConstructor(t, CONSTRUCTOR);
} else {
t = Types.PAGE_IMPL;
constrAdapter.invokeConstructor(t, CONSTRUCTOR);
}
// call _init()
constrAdapter.visitVarInsn(Opcodes.ALOAD, 0);
constrAdapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, constr.getClassName(), "initKeys", "()V");
// private static ImportDefintion[] test=new ImportDefintion[]{...};
{
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "imports", "[Llucee/runtime/component/ImportDefintion;", null, null);
fv.visitEnd();
constrAdapter.visitVarInsn(Opcodes.ALOAD, 0);
ArrayVisitor av = new ArrayVisitor();
av.visitBegin(constrAdapter, Types.IMPORT_DEFINITIONS, imports.size());
int index = 0;
Iterator<String> it = imports.iterator();
while (it.hasNext()) {
av.visitBeginItem(constrAdapter, index++);
constrAdapter.push(it.next());
ASMConstants.NULL(constrAdapter);
constrAdapter.invokeStatic(Types.IMPORT_DEFINITIONS_IMPL, ID_GET_INSTANCE);
av.visitEndItem(constrAdapter);
}
av.visitEnd();
constrAdapter.visitFieldInsn(Opcodes.PUTFIELD, className, "imports", "[Llucee/runtime/component/ImportDefintion;");
}
// getVersion
GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, VERSION, null, null, cw);
adapter.push(version);
adapter.returnValue();
adapter.endMethod();
// public ImportDefintion[] getImportDefintions()
if (imports.size() > 0) {
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, GET_IMPORT_DEFINITIONS, null, null, cw);
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.visitFieldInsn(Opcodes.GETFIELD, className, "imports", "[Llucee/runtime/component/ImportDefintion;");
adapter.returnValue();
adapter.endMethod();
} else {
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, GET_IMPORT_DEFINITIONS, null, null, cw);
adapter.visitInsn(Opcodes.ICONST_0);
adapter.visitTypeInsn(Opcodes.ANEWARRAY, "lucee/runtime/component/ImportDefintion");
adapter.returnValue();
adapter.endMethod();
}
// getSourceLastModified
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, LAST_MOD, null, null, cw);
adapter.push(lastModifed);
adapter.returnValue();
adapter.endMethod();
// getSourceLength
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, LENGTH, null, null, cw);
adapter.push(length);
adapter.returnValue();
adapter.endMethod();
// getCompileTime
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, COMPILE_TIME, null, null, cw);
adapter.push(System.currentTimeMillis());
adapter.returnValue();
adapter.endMethod();
// getHash
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, HASH, null, null, cw);
adapter.push(hash);
adapter.returnValue();
adapter.endMethod();
if (comp != null) {
writeOutStaticConstructor(constr, keys, cw, comp, className);
}
// newInstance/initComponent/call
if (isComponent()) {
writeOutNewComponent(constr, keys, cw, comp, className);
writeOutInitComponent(constr, keys, cw, comp, className);
} else if (isInterface()) {
writeOutNewInterface(constr, keys, cw, comp, className);
writeOutInitInterface(constr, keys, cw, comp, className);
} else {
writeOutCall(constr, keys, cw, className);
}
// write UDFProperties to constructor
// writeUDFProperties(bc,funcs,pageType);
// udfCall
Function[] functions = getFunctions();
ConditionVisitor cv;
DecisionIntVisitor div;
// less/equal than 10 functions
if (isInterface()) {
} else if (functions.length <= 10) {
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_CALL, null, new Type[] { Types.THROWABLE }, cw);
BytecodeContext bc = new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, UDF_CALL, writeLog(), suppressWSbeforeArg, output, returnValue);
if (functions.length == 0) {
} else if (functions.length == 1) {
ExpressionUtil.visitLine(bc, functions[0].getStart());
functions[0].getBody().writeOut(bc);
ExpressionUtil.visitLine(bc, functions[0].getEnd());
} else
writeOutUdfCallInner(bc, functions, 0, functions.length);
adapter.visitInsn(Opcodes.ACONST_NULL);
adapter.returnValue();
adapter.endMethod();
} else // more than 10 functions
{
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_CALL, null, new Type[] { Types.THROWABLE }, cw);
BytecodeContext bc = new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, UDF_CALL, writeLog(), suppressWSbeforeArg, output, returnValue);
cv = new ConditionVisitor();
cv.visitBefore();
int count = 0;
for (int i = 0; i < functions.length; i += 10) {
cv.visitWhenBeforeExpr();
div = new DecisionIntVisitor();
div.visitBegin();
adapter.loadArg(2);
div.visitLT();
adapter.push(i + 10);
div.visitEnd(bc);
cv.visitWhenAfterExprBeforeBody(bc);
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.visitVarInsn(Opcodes.ALOAD, 1);
adapter.visitVarInsn(Opcodes.ALOAD, 2);
adapter.visitVarInsn(Opcodes.ILOAD, 3);
adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, createFunctionName(++count), "(Llucee/runtime/PageContext;Llucee/runtime/type/UDF;I)Ljava/lang/Object;");
// adapter.returnValue();
adapter.visitInsn(Opcodes.ARETURN);
cv.visitWhenAfterBody(bc);
}
cv.visitAfter(bc);
adapter.visitInsn(Opcodes.ACONST_NULL);
adapter.returnValue();
adapter.endMethod();
count = 0;
Method innerCall;
for (int i = 0; i < functions.length; i += 10) {
innerCall = new Method(createFunctionName(++count), Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, USER_DEFINED_FUNCTION, Types.INT_VALUE });
adapter = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, innerCall, null, new Type[] { Types.THROWABLE }, cw);
writeOutUdfCallInner(new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, innerCall, writeLog(), suppressWSbeforeArg, output, returnValue), functions, i, i + 10 > functions.length ? functions.length : i + 10);
adapter.visitInsn(Opcodes.ACONST_NULL);
adapter.returnValue();
adapter.endMethod();
}
}
// threadCall
TagThread[] threads = getThreads();
if (true) {
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, THREAD_CALL, null, new Type[] { Types.THROWABLE }, cw);
if (threads.length > 0)
writeOutThreadCallInner(new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, THREAD_CALL, writeLog(), suppressWSbeforeArg, output, returnValue), threads, 0, threads.length);
// adapter.visitInsn(Opcodes.ACONST_NULL);
adapter.returnValue();
adapter.endMethod();
}
// less/equal than 10 functions
if (isInterface()) {
} else if (functions.length <= 10) {
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_DEFAULT_VALUE, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
if (functions.length > 0)
writeUdfDefaultValueInner(new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, UDF_DEFAULT_VALUE, writeLog(), suppressWSbeforeArg, output, returnValue), functions, 0, functions.length);
adapter.loadArg(DEFAULT_VALUE);
adapter.returnValue();
adapter.endMethod();
} else {
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_DEFAULT_VALUE, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
BytecodeContext bc = new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, UDF_DEFAULT_VALUE, writeLog(), suppressWSbeforeArg, output, returnValue);
cv = new ConditionVisitor();
cv.visitBefore();
int count = 0;
for (int i = 0; i < functions.length; i += 10) {
cv.visitWhenBeforeExpr();
div = new DecisionIntVisitor();
div.visitBegin();
adapter.loadArg(1);
div.visitLT();
adapter.push(i + 10);
div.visitEnd(bc);
cv.visitWhenAfterExprBeforeBody(bc);
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.visitVarInsn(Opcodes.ALOAD, 1);
adapter.visitVarInsn(Opcodes.ILOAD, 2);
adapter.visitVarInsn(Opcodes.ILOAD, 3);
adapter.visitVarInsn(Opcodes.ALOAD, 4);
adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, "udfDefaultValue" + (++count), "(Llucee/runtime/PageContext;IILjava/lang/Object;)Ljava/lang/Object;");
// adapter.returnValue();
adapter.visitInsn(Opcodes.ARETURN);
cv.visitWhenAfterBody(bc);
}
cv.visitAfter(bc);
adapter.visitInsn(Opcodes.ACONST_NULL);
adapter.returnValue();
adapter.endMethod();
count = 0;
Method innerDefaultValue;
for (int i = 0; i < functions.length; i += 10) {
innerDefaultValue = new Method("udfDefaultValue" + (++count), Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, Types.INT_VALUE, Types.INT_VALUE, Types.OBJECT });
adapter = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, innerDefaultValue, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
writeUdfDefaultValueInner(new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, innerDefaultValue, writeLog(), suppressWSbeforeArg, output, returnValue), functions, i, i + 10 > functions.length ? functions.length : i + 10);
adapter.loadArg(DEFAULT_VALUE);
// adapter.visitInsn(Opcodes.ACONST_NULL);
adapter.returnValue();
adapter.endMethod();
}
}
// CONSTRUCTOR
List<Data> udfProperties = constr.getUDFProperties();
Iterator<Data> it = udfProperties.iterator();
String udfpropsClassName = Types.UDF_PROPERTIES_ARRAY.toString();
// new UDFProperties Array
constrAdapter.visitVarInsn(Opcodes.ALOAD, 0);
constrAdapter.push(udfProperties.size());
constrAdapter.newArray(Types.UDF_PROPERTIES);
constrAdapter.visitFieldInsn(Opcodes.PUTFIELD, getClassName(), "udfs", udfpropsClassName);
// set item
Data data;
while (it.hasNext()) {
data = it.next();
constrAdapter.visitVarInsn(Opcodes.ALOAD, 0);
constrAdapter.visitFieldInsn(Opcodes.GETFIELD, constr.getClassName(), "udfs", Types.UDF_PROPERTIES_ARRAY.toString());
constrAdapter.push(data.arrayIndex);
data.function.createUDFProperties(constr, data.valueIndex, data.type);
constrAdapter.visitInsn(Opcodes.AASTORE);
}
// setPageSource(pageSource);
constrAdapter.visitVarInsn(Opcodes.ALOAD, 0);
constrAdapter.visitVarInsn(Opcodes.ALOAD, 1);
constrAdapter.invokeVirtual(t, SET_PAGE_SOURCE);
constrAdapter.returnValue();
constrAdapter.endMethod();
// INIT KEYS
{
GeneratorAdapter aInit = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, INIT_KEYS, null, null, cw);
BytecodeContext bcInit = new BytecodeContext(optionalPS, constr, this, keys, cw, className, aInit, INIT_KEYS, writeLog(), suppressWSbeforeArg, output, returnValue);
registerFields(bcInit, keys);
aInit.returnValue();
aInit.endMethod();
}
// set field subs
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "subs", "[Llucee/runtime/CIPage;", null, null);
fv.visitEnd();
// create sub components/interfaces
if (comp != null && comp.isMain()) {
List<TagCIObject> subs = getSubs(null);
if (!ArrayUtil.isEmpty(subs)) {
Iterator<TagCIObject> _it = subs.iterator();
TagCIObject tc;
while (_it.hasNext()) {
tc = _it.next();
tc.writeOut(this);
}
writeGetSubPages(cw, className, subs, sourceCode.getDialect());
}
}
return cw.toByteArray();
}
use of lucee.transformer.expression.literal.LitString in project Lucee by lucee.
the class SourceLastModifiedClassAdapter method writeOutNewComponent.
private void writeOutNewComponent(ConstrBytecodeContext constr, List<LitString> keys, ClassWriter cw, Tag component, String name) throws TransformerException {
GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, NEW_COMPONENT_IMPL_INSTANCE, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
BytecodeContext bc = new BytecodeContext(null, constr, this, keys, cw, name, adapter, NEW_COMPONENT_IMPL_INSTANCE, writeLog(), suppressWSbeforeArg, output, returnValue);
Label methodBegin = new Label();
Label methodEnd = new Label();
adapter.visitLocalVariable("this", "L" + name + ";", null, methodBegin, methodEnd, 0);
ExpressionUtil.visitLine(bc, component.getStart());
adapter.visitLabel(methodBegin);
int comp = adapter.newLocal(Types.COMPONENT_IMPL);
adapter.newInstance(Types.COMPONENT_IMPL);
adapter.dup();
Attribute attr;
// ComponentPage
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.checkCast(Types.COMPONENT_PAGE_IMPL);
// !!! also check CFMLScriptTransformer.addMetaData if you do any change here !!!
// Output
attr = component.removeAttribute("output");
if (attr != null) {
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
} else
ASMConstants.NULL(adapter);
// synchronized
attr = component.removeAttribute("synchronized");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_VALUE);
else
adapter.push(false);
// extends
attr = component.removeAttribute("extends");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// implements
attr = component.removeAttribute("implements");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// hint
attr = component.removeAttribute("hint");
if (attr != null) {
Expression value = attr.getValue();
if (!(value instanceof Literal)) {
value = bc.getFactory().createLitString("[runtime expression]");
}
ExpressionUtil.writeOutSilent(value, bc, Expression.MODE_REF);
} else
adapter.push("");
// dspName
attr = component.removeAttribute("displayname");
if (attr == null)
attr = component.getAttribute("display");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// callpath
adapter.visitVarInsn(Opcodes.ALOAD, 2);
// realpath
adapter.visitVarInsn(Opcodes.ILOAD, 3);
// style
attr = component.removeAttribute("style");
if (attr != null)
ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
else
adapter.push("");
// persistent
attr = component.removeAttribute("persistent");
boolean persistent = false;
if (attr != null) {
persistent = ASMUtil.toBoolean(attr, component.getStart()).booleanValue();
}
// accessors
attr = component.removeAttribute("accessors");
boolean accessors = false;
if (attr != null) {
accessors = ASMUtil.toBoolean(attr, component.getStart()).booleanValue();
}
// modifier
attr = component.removeAttribute("modifier");
int modifiers = Component.MODIFIER_NONE;
if (attr != null) {
// type already evaluated in evaluator
LitString ls = (LitString) component.getFactory().toExprString(attr.getValue());
modifiers = ComponentUtil.toModifier(ls.getString(), lucee.runtime.Component.MODIFIER_NONE, lucee.runtime.Component.MODIFIER_NONE);
}
adapter.push(persistent);
adapter.push(accessors);
adapter.push(modifiers);
adapter.visitVarInsn(Opcodes.ILOAD, 4);
// adapter.visitVarInsn(Opcodes.ALOAD, 4);
createMetaDataStruct(bc, component.getAttributes(), component.getMetaData());
adapter.invokeConstructor(Types.COMPONENT_IMPL, CONSTR_COMPONENT_IMPL15);
adapter.storeLocal(comp);
// Component Impl(ComponentPage componentPage,boolean output, String extend, String hint, String dspName)
// initComponent(pc,c);
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.loadArg(0);
adapter.loadLocal(comp);
adapter.loadArg(4);
adapter.invokeVirtual(Types.COMPONENT_PAGE_IMPL, INIT_COMPONENT3);
adapter.visitLabel(methodEnd);
// return component;
adapter.loadLocal(comp);
adapter.returnValue();
// ExpressionUtil.visitLine(adapter, component.getEndLine());
adapter.endMethod();
}
use of lucee.transformer.expression.literal.LitString in project Lucee by lucee.
the class SourceLastModifiedClassAdapter method registerFields.
public static void registerFields(BytecodeContext bc, List<LitString> keys) throws TransformerException {
// if(keys.size()==0) return;
GeneratorAdapter ga = bc.getAdapter();
FieldVisitor fv = bc.getClassWriter().visitField(Opcodes.ACC_PRIVATE, "keys", Types.COLLECTION_KEY_ARRAY.toString(), null, null);
fv.visitEnd();
int index = 0;
LitString value;
Iterator<LitString> it = keys.iterator();
ga.visitVarInsn(Opcodes.ALOAD, 0);
ga.push(keys.size());
ga.newArray(Types.COLLECTION_KEY);
while (it.hasNext()) {
value = it.next();
ga.dup();
ga.push(index++);
// value.setExternalize(false);
ExpressionUtil.writeOutSilent(value, bc, Expression.MODE_REF);
ga.invokeStatic(KEY_IMPL, KEY_INTERN);
ga.visitInsn(Opcodes.AASTORE);
}
ga.visitFieldInsn(Opcodes.PUTFIELD, bc.getClassName(), "keys", Types.COLLECTION_KEY_ARRAY.toString());
}
use of lucee.transformer.expression.literal.LitString 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.literal.LitString 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;
}
Aggregations