use of lucee.transformer.util.PageSourceCode in project Lucee by lucee.
the class Function method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag, FunctionLib[] flibs) throws EvaluatorException {
// Body p=(Body) tag.getParent();
// Statement pp = p.getParent();
boolean isCI = true;
try {
isCI = ASMUtil.getAncestorPage(tag).isComponent() || ASMUtil.getAncestorPage(tag).isInterface();
} catch (TransformerException e) {
}
Attribute attrName = tag.getAttribute("name");
if (attrName != null) {
Expression expr = attrName.getValue();
PageSource ps = null;
if (expr instanceof LitString && !isCI) {
Page p = ASMUtil.getAncestorPage(tag, null);
if (p != null) {
SourceCode sc = p.getSourceCode();
if (sc instanceof PageSourceCode) {
PageSourceCode psc = (PageSourceCode) sc;
ps = psc.getPageSource();
}
}
checkFunctionName(((LitString) expr).getString(), flibs, ps);
}
}
// attribute modifier
boolean isStatic = false;
{
Attribute attrModifier = tag.getAttribute("modifier");
if (attrModifier != null) {
ExprString expr = tag.getFactory().toExprString(attrModifier.getValue());
if (!(expr instanceof Literal))
throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
String modifier = StringUtil.emptyIfNull(((Literal) expr).getString()).trim();
if (!StringUtil.isEmpty(modifier) && !"abstract".equalsIgnoreCase(modifier) && !"final".equalsIgnoreCase(modifier) && !"static".equalsIgnoreCase(modifier))
throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
isStatic = "static".equalsIgnoreCase(modifier);
boolean abstr = "abstract".equalsIgnoreCase(modifier);
if (abstr)
throwIfNotEmpty(tag);
}
}
// cachedWithin
{
Attribute attrCachedWithin = tag.getAttribute("cachedwithin");
if (attrCachedWithin != null) {
Expression val = attrCachedWithin.getValue();
tag.addAttribute(new Attribute(attrCachedWithin.isDynamicType(), attrCachedWithin.getName(), ASMUtil.cachedWithinValue(val), attrCachedWithin.getType()));
}
}
// Attribute localMode
{
Attribute attrLocalMode = tag.getAttribute("localmode");
if (attrLocalMode != null) {
Expression expr = attrLocalMode.getValue();
String str = ASMUtil.toString(expr, null);
if (!StringUtil.isEmpty(str) && AppListenerUtil.toLocalMode(str, -1) == -1)
throw new EvaluatorException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)");
// boolean output = ((LitBoolean)expr).getBooleanValue();
// if(!output) ASMUtil.removeLiterlChildren(tag, true);
}
}
// Attribute Output
{
Attribute attrOutput = tag.getAttribute("output");
if (attrOutput != null) {
Expression expr = tag.getFactory().toExprBoolean(attrOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute output of the Tag Function, must be a literal boolean value (true or false, yes or no)");
}
}
// Buffer output
{
Attribute attrBufferOutput = tag.getAttribute("bufferoutput");
if (attrBufferOutput != null) {
Expression expr = tag.getFactory().toExprBoolean(attrBufferOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute bufferOutput of the Tag Function, must be a literal boolean value (true or false, yes or no)");
}
}
// check attribute values
Map<String, Attribute> attrs = tag.getAttributes();
Iterator<Attribute> it = attrs.values().iterator();
while (it.hasNext()) {
checkAttributeValue(tag, it.next());
}
// add to static scope
if (isStatic) {
// remove that tag from parent
ASMUtil.remove(tag);
Body body = (Body) tag.getParent();
StaticBody sb = Static.getStaticBody(body);
sb.addStatement(tag);
}
}
use of lucee.transformer.util.PageSourceCode in project Lucee by lucee.
the class Import method executePT.
private TagLib executePT(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, SourceCode sc) throws TemplateException {
// Attribute prefix
String nameSpace = ASMUtil.getAttributeString(tag, "prefix", null);
if (nameSpace == null)
throw new TemplateException(sc, "attribute [prefix] must be a constant value");
nameSpace = nameSpace.trim();
String nameSpaceSeparator = StringUtil.isEmpty(nameSpace) ? "" : ":";
// Attribute taglib
String textTagLib = ASMUtil.getAttributeString(tag, "taglib", null);
if (textTagLib == null)
throw new TemplateException(sc, "attribute [taglib] must be a constant value");
textTagLib = textTagLib.replace('\\', '/');
textTagLib = ConfigWebUtil.replacePlaceholder(textTagLib, config);
// File TagLib
String ext = ResourceUtil.getExtension(textTagLib, null);
boolean hasTldExtension = "tld".equalsIgnoreCase(ext) || "tldx".equalsIgnoreCase(ext);
Resource absFile = config.getResource(textTagLib);
// TLD
if (absFile.isFile())
return _executeTLD(config, absFile, nameSpace, nameSpaceSeparator, sc);
// Second Change
if (textTagLib.startsWith("/")) {
// config.getPhysical(textTagLib);
PageSource ps = ((ConfigImpl) config).getPageSourceExisting(null, null, textTagLib, false, false, true, false);
// config.getConfigDir()
if (ps != null) {
if (ps.physcalExists()) {
Resource file = ps.getPhyscalFile();
// TLD
if (file.isFile())
return _executeTLD(config, file, nameSpace, nameSpaceSeparator, sc);
}
// CTD
if (!hasTldExtension)
return _executeCTD(textTagLib, nameSpace, nameSpaceSeparator);
}
} else {
PageSource ps = sc instanceof PageSourceCode ? ((PageSourceCode) sc).getPageSource() : null;
Resource sourceFile = ps == null ? null : ps.getPhyscalFile();
if (sourceFile != null) {
Resource file = sourceFile.getParentResource().getRealResource(textTagLib);
// TLD
if (file.isFile())
return _executeTLD(config, file, nameSpace, nameSpaceSeparator, sc);
// CTD
if (!hasTldExtension)
return _executeCTD(textTagLib, nameSpace, nameSpaceSeparator);
}
}
throw new TemplateException(sc, "invalid definition of the attribute taglib [" + textTagLib + "]");
}
use of lucee.transformer.util.PageSourceCode in project Lucee by lucee.
the class ProcessingDirective method execute.
@Override
public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
// dot notation
Boolean dotNotationUpperCase = null;
if (tag.containsAttribute("preservecase")) {
Boolean preservecase = ASMUtil.getAttributeBoolean(tag, "preservecase", null);
if (preservecase == null)
throw new TemplateException(data.srcCode, "attribute [preserveCase] of the tag [processingdirective] must be a constant boolean value");
dotNotationUpperCase = preservecase.booleanValue() ? Boolean.FALSE : Boolean.TRUE;
if (dotNotationUpperCase == data.settings.dotNotationUpper)
dotNotationUpperCase = null;
}
// page encoding
Charset cs = null;
if (tag.containsAttribute("pageencoding")) {
String str = ASMUtil.getAttributeString(tag, "pageencoding", null);
if (str == null)
throw new TemplateException(data.srcCode, "attribute [pageencoding] of the tag [processingdirective] must be a constant value");
cs = CharsetUtil.toCharset(str);
PageSourceCode psc = data.srcCode instanceof PageSourceCode ? (PageSourceCode) data.srcCode : null;
if (psc == null || cs.equals(psc.getCharset())) {
cs = null;
}
}
// execution log
Boolean exeLog = null;
if (tag.containsAttribute("executionlog")) {
String strExeLog = ASMUtil.getAttributeString(tag, "executionlog", null);
exeLog = Caster.toBoolean(strExeLog, null);
if (exeLog == null)
throw new TemplateException(data.srcCode, "attribute [executionlog] of the tag [processingdirective] must be a constant boolean value");
if (exeLog.booleanValue() == data.srcCode.getWriteLog())
exeLog = null;
}
if (cs != null || exeLog != null || dotNotationUpperCase != null) {
if (cs == null) {
if (data.srcCode instanceof PageSourceCode)
cs = ((PageSourceCode) data.srcCode).getCharset();
else
cs = CharsetUtil.UTF8;
}
if (exeLog == null)
exeLog = data.srcCode.getWriteLog() ? Boolean.TRUE : Boolean.FALSE;
if (dotNotationUpperCase == null)
dotNotationUpperCase = data.settings.dotNotationUpper;
throw new ProcessingDirectiveException(data.srcCode, cs, dotNotationUpperCase, exeLog);
}
return null;
}
use of lucee.transformer.util.PageSourceCode in project Lucee by lucee.
the class CFMLTransformer method transform.
/**
* Startmethode zum transfomieren einer CFMLString.
* <br />
* EBNF:<br />
* <code>{body}</code>
* @param config
* @param sc CFMLString
* @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 sourceLastModified
* @param dotNotationUpperCase
* @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
*/
public Page transform(Factory factory, ConfigImpl config, SourceCode sc, TagLib[] tlibs, FunctionLib[] flibs, long sourceLastModified, Boolean dotNotationUpperCase, boolean returnValue, boolean ignoreScope) throws TemplateException {
boolean dnuc;
if (dotNotationUpperCase == null) {
if (sc instanceof PageSourceCode)
dnuc = sc.getDialect() == CFMLEngine.DIALECT_CFML && ((MappingImpl) ((PageSourceCode) sc).getPageSource().getMapping()).getDotNotationUpperCase();
else
dnuc = sc.getDialect() == CFMLEngine.DIALECT_CFML && config.getDotNotationUpperCase();
} else
dnuc = dotNotationUpperCase;
TagLib[][] _tlibs = new TagLib[][] { null, new TagLib[0] };
_tlibs[TAG_LIB_GLOBAL] = tlibs;
// reset page tlds
if (_tlibs[TAG_LIB_PAGE].length > 0) {
_tlibs[TAG_LIB_PAGE] = new TagLib[0];
}
Page page = new Page(factory, config, sc, null, ConfigWebUtil.getEngine(config).getInfo().getFullVersionInfo(), sourceLastModified, sc.getWriteLog(), sc.getDialect() == CFMLEngine.DIALECT_LUCEE || config.getSuppressWSBeforeArg(), config.getDefaultFunctionOutput(), returnValue, ignoreScope);
TagData data = new TagData(factory, _tlibs, flibs, config.getCoreTagLib(sc.getDialect()).getScriptTags(), sc, page, dnuc, ignoreScope);
// Body body=page;
try {
do {
body(data, page, false, null);
if (data.srcCode.isAfterLast())
break;
if (data.srcCode.forwardIfCurrent("</")) {
int pos = data.srcCode.getPos();
TagLib tagLib = nameSpace(data);
if (tagLib == null) {
page.addPrintOut(data.factory, "</", null, null);
} else {
String name = identifier(data.srcCode, true, true);
if (tagLib.getIgnoreUnknowTags()) {
TagLibTag tlt = tagLib.getTag(name);
if (tlt == null) {
data.srcCode.setPos(pos);
page.addPrintOut(data.factory, "</", null, null);
}
} else
throw new TemplateException(sc, "no matching start tag for end tag [" + tagLib.getNameSpaceAndSeparator() + name + "]");
}
} else
throw new TemplateException(sc, "Error while transforming CFML File");
} while (true);
// call-back of evaluators
data.ep.run();
return page;
} catch (TemplateException e) {
data.ep.clear();
throw e;
}
}
use of lucee.transformer.util.PageSourceCode 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();
}
Aggregations