use of lucee.transformer.expression.literal.LitString in project Lucee by lucee.
the class GetTickCount method execute.
@Override
public void execute(BIF bif, FunctionLibFunction flf) throws TemplateException {
Argument[] args = bif.getArguments();
if (ArrayUtil.isEmpty(args))
return;
Argument arg = args[0];
Expression value = arg.getValue();
if (value instanceof LitString) {
String unit = ((LitString) value).getString();
if ("nano".equalsIgnoreCase(unit))
arg.setValue(bif.getFactory().createLitDouble(lucee.runtime.functions.other.GetTickCount.UNIT_NANO), "number");
else if ("milli".equalsIgnoreCase(unit))
arg.setValue(bif.getFactory().createLitDouble(lucee.runtime.functions.other.GetTickCount.UNIT_MILLI), "number");
else if ("micro".equalsIgnoreCase(unit))
arg.setValue(bif.getFactory().createLitDouble(lucee.runtime.functions.other.GetTickCount.UNIT_MICRO), "number");
else if ("second".equalsIgnoreCase(unit))
arg.setValue(bif.getFactory().createLitDouble(lucee.runtime.functions.other.GetTickCount.UNIT_SECOND), "number");
}
}
use of lucee.transformer.expression.literal.LitString in project Lucee by lucee.
the class IsDefined method execute.
@Override
public void execute(BIF bif, FunctionLibFunction flf) throws TemplateException {
Argument arg = bif.getArguments()[0];
Expression value = arg.getValue();
if (value instanceof LitString) {
String str = ((LitString) value).getString();
StringList sl = VariableInterpreter.parse(str, false);
if (sl != null) {
// scope
str = sl.next();
int scope = VariableInterpreter.scopeString2Int(bif.ts.ignoreScopes, str);
if (scope == Scope.SCOPE_UNDEFINED)
sl.reset();
// keys
String[] arr = sl.toArray();
ArrayUtil.trim(arr);
// update first arg
arg.setValue(bif.getFactory().createLitDouble(scope), "number");
if (arr.length == 1) {
// LitString.toExprString(str);
Expression expr = new CollectionKey(bif.getFactory(), arr[0]);
arg = new Argument(expr, Collection.Key.class.getName());
bif.addArgument(arg);
} else {
CollectionKeyArray expr = new CollectionKeyArray(bif.getFactory(), arr);
// LiteralStringArray expr = new LiteralStringArray(arr);
arg = new Argument(expr, Collection.Key[].class.getName());
bif.addArgument(arg);
}
}
}
// print.out("bif:"+arg.getValue().getClass().getName());
}
use of lucee.transformer.expression.literal.LitString in project Lucee by lucee.
the class Component method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag tlt) throws EvaluatorException {
/*if(tag instanceof TagOther) {
print.e(((TagOther)tag).getFullname());
}*/
TagCIObject tc = (TagCIObject) tag;
Statement pPage = tag.getParent();
// String className=tag.getTagLibTag().getTagClassName();
Page page;
// move components inside script to root
if (pPage instanceof Page) {
page = (Page) pPage;
} else {
// is in script
Tag p = ASMUtil.getParentTag(tag);
if ((pPage = p.getParent()) instanceof Page && p.getTagLibTag().getName().equalsIgnoreCase(((Page) pPage).getSourceCode().getDialect() == CFMLEngine.DIALECT_CFML ? Constants.CFML_SCRIPT_TAG_NAME : Constants.LUCEE_SCRIPT_TAG_NAME)) {
// chnaged order of the condition, not sure if this is ok
page = (Page) pPage;
// move imports from script to component body
List<Statement> children = p.getBody().getStatements();
Iterator<Statement> it = children.iterator();
Statement stat;
Tag t;
while (it.hasNext()) {
stat = it.next();
if (!(stat instanceof Tag))
continue;
t = (Tag) stat;
if (t.getTagLibTag().getName().equals("import")) {
tag.getBody().addStatement(t);
}
}
// move to page
ASMUtil.move(tag, page);
// if(!inline)ASMUtil.replace(p, tag, false);
} else
throw new EvaluatorException("Wrong Context, tag " + tlt.getFullName() + " can't be inside other tags, tag is inside tag " + p.getFullname());
}
// Page page=(Page) pPage;
Boolean insideCITemplate = isInsideCITemplate(page);
boolean main = isMainComponent(page, tc);
// is a full grown component or a inline component
if (insideCITemplate == Boolean.FALSE) {
throw new EvaluatorException("Wrong Context, " + tlt.getFullName() + " tag must be inside a file with the extension " + Constants.getCFMLComponentExtension() + " or " + Constants.getLuceeComponentExtension());
}
// if(count>1)
// throw new EvaluatorException("inside one cfc file only one tag "+tlt.getFullName()+" is allowed, now we have "+count);
boolean isComponent = tlt.getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Component");
/*boolean isInterface="lucee.runtime.tag.Interface".equals(tlt.getTagClassName());
if(main) {
if(isComponent) page.setIsComponent(true);
else if(isInterface) page.setIsInterface(true);
}*/
tc.setMain(main);
// Attributes
// Name
String name = null;
if (!main) {
Map<String, Attribute> attrs = tag.getAttributes();
if (attrs.size() > 0) {
Attribute first = attrs.values().iterator().next();
if (first.isDefaultValue()) {
name = first.getName();
}
}
if (name == null) {
Attribute attr = tag.getAttribute("name");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Name of the component " + tlt.getFullName() + ", must be a literal string value");
name = ((LitString) expr).getString();
} else
throw new EvaluatorException("Missing name of the component " + tlt.getFullName() + "");
}
tc.setName(name);
}
// output
// "output=true" is handled in "lucee.transformer.cfml.attributes.impl.Function"
Attribute attr = tag.getAttribute("output");
if (attr != null) {
Expression expr = tag.getFactory().toExprBoolean(attr.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute output of the Tag " + tlt.getFullName() + ", must contain a static boolean value (true or false, yes or no)");
// boolean output = ((LitBoolean)expr).getBooleanValue();
// if(!output) ASMUtil.removeLiterlChildren(tag, true);
}
// extends
attr = tag.getAttribute("extends");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Attribute extends of the Tag " + tlt.getFullName() + ", must contain a literal string value");
}
// implements
if (isComponent) {
attr = tag.getAttribute("implements");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Attribute implements of the Tag " + tlt.getFullName() + ", must contain a literal string value");
}
}
// modifier
if (isComponent) {
attr = tag.getAttribute("modifier");
if (attr != null) {
Expression expr = tag.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("Attribute modifier of the Tag " + tlt.getFullName() + ", must contain a literal string value");
LitString ls = (LitString) expr;
int mod = ComponentUtil.toModifier(ls.getString(), lucee.runtime.Component.MODIFIER_NONE, -1);
if (mod == -1)
throw new EvaluatorException("Value [" + ls.getString() + "] from attribute modifier of the Tag " + tlt.getFullName() + " is invalid,valid values are [none,abstract,final]");
}
}
}
use of lucee.transformer.expression.literal.LitString in project Lucee by lucee.
the class Continue method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
String ns = libTag.getTagLib().getNameSpaceAndSeparator();
String loopName = ns + "loop";
String whileName = ns + "while";
// label
String label = null;
Attribute attrLabel = tag.getAttribute("label");
if (attrLabel != null) {
TagContinue tc = (TagContinue) tag;
label = Break.variableToString(tag, attrLabel, null);
if (label != null) {
tc.setLabel(label = label.trim());
tag.removeAttribute("label");
} else if (ASMUtil.isLiteralAttribute(tag, attrLabel, ASMUtil.TYPE_STRING, false, true)) {
LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
label = ls.getString();
if (!StringUtil.isEmpty(label, true)) {
tc.setLabel(label = label.trim());
tag.removeAttribute("label");
} else
label = null;
}
}
if (ASMUtil.isLiteralAttribute(tag, "label", ASMUtil.TYPE_STRING, false, true)) {
LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
TagContinue tc = (TagContinue) tag;
label = ls.getString();
if (!StringUtil.isEmpty(label, true)) {
tc.setLabel(label = label.trim());
tag.removeAttribute("label");
} else
label = null;
}
if (!ASMUtil.hasAncestorContinueFCStatement(tag, label)) {
if (tag.isScriptBase()) {
if (StringUtil.isEmpty(label))
throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a loop (for,while,loop ...)");
throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a loop (for,while,loop ...) with the label [" + label + "]");
}
if (StringUtil.isEmpty(label))
throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + loopName + " or " + whileName + " tag");
throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + loopName + " or " + whileName + " tag with the label [" + label + "]");
}
}
use of lucee.transformer.expression.literal.LitString in project Lucee by lucee.
the class While method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag tagLibTag, FunctionLib[] flibs) throws EvaluatorException {
TagWhile whil = (TagWhile) tag;
// label
if (ASMUtil.isLiteralAttribute(tag, "label", ASMUtil.TYPE_STRING, false, true)) {
LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
String l = ls.getString();
if (!StringUtil.isEmpty(l, true)) {
whil.setLabel(l.trim());
tag.removeAttribute("label");
}
}
}
Aggregations