use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Gen method appendString.
/**
* Append value (on tos) to string buffer (on tos - 1).
*/
void appendString(JCTree tree) {
Type t = tree.type.baseType();
if (!t.isPrimitive() && t.tsym != syms.stringType.tsym) {
t = syms.objectType;
}
items.makeMemberItem(getStringBufferAppend(tree, t), false).invoke();
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Gen method initCode.
private int initCode(JCMethodDecl tree, Env<GenContext> env, boolean fatcode) {
MethodSymbol meth = tree.sym;
// Create a new code structure.
meth.code = code = new Code(meth, fatcode, lineDebugInfo ? toplevel.lineMap : null, varDebugInfo, stackMap, debugCode, genCrt ? new CRTable(tree, env.toplevel.endPositions) : null, syms, types, pool);
items = new Items(pool, code, syms, types);
if (code.debugCode) {
System.err.println(meth + " for body " + tree);
}
// for `this'.
if ((tree.mods.flags & STATIC) == 0) {
Type selfType = meth.owner.type;
if (meth.isConstructor() && selfType != syms.objectType)
selfType = UninitializedType.uninitializedThis(selfType);
code.setDefined(code.newLocal(new VarSymbol(FINAL, names._this, selfType, meth.owner)));
}
// the method.
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
checkDimension(l.head.pos(), l.head.sym.type);
code.setDefined(code.newLocal(l.head.sym));
}
// Get ready to generate code for method body.
int startpcCrt = genCrt ? code.curCP() : 0;
code.entryPoint();
// Suppress initial stackmap
code.pendingStackMap = false;
return startpcCrt;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Gen method visitNewArray.
public void visitNewArray(JCNewArray tree) {
setTypeAnnotationPositions(tree.pos);
if (tree.elems != null) {
Type elemtype = types.elemtype(tree.type);
loadIntConst(tree.elems.length());
Item arr = makeNewArray(tree.pos(), tree.type, 1);
int i = 0;
for (List<JCExpression> l = tree.elems; l.nonEmpty(); l = l.tail) {
arr.duplicate();
loadIntConst(i);
i++;
genExpr(l.head, elemtype).load();
items.makeIndexedItem(elemtype).store();
}
result = arr;
} else {
for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
genExpr(l.head, syms.intType).load();
}
result = makeNewArray(tree.pos(), tree.type, tree.dims.length());
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Gen method genExpr.
/**
* Visitor method: generate code for an expression, catching and reporting
* any completion failures.
* @param tree The expression to be visited.
* @param pt The expression's expected type (proto-type).
*/
public Item genExpr(JCTree tree, Type pt) {
Type prevPt = this.pt;
try {
if (tree.type.constValue() != null) {
// Short circuit any expressions which are constants
tree.accept(classReferenceVisitor);
checkStringConstant(tree.pos(), tree.type.constValue());
result = items.makeImmediateItem(tree.type, tree.type.constValue());
} else {
this.pt = pt;
tree.accept(this);
}
return result.coerce(pt);
} catch (CompletionFailure ex) {
chk.completionError(tree.pos(), ex);
code.state.stacksize = 1;
return items.makeStackItem(pt);
} finally {
this.pt = prevPt;
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class TreeMaker method Type.
/**
* Create a tree representing given type.
*/
public JCExpression Type(Type t) {
if (t == null)
return null;
JCExpression tp;
switch(t.getTag()) {
case BYTE:
case CHAR:
case SHORT:
case INT:
case LONG:
case FLOAT:
case DOUBLE:
case BOOLEAN:
case VOID:
tp = TypeIdent(t.getTag());
break;
case TYPEVAR:
tp = Ident(t.tsym);
break;
case WILDCARD:
{
WildcardType a = ((WildcardType) t);
tp = Wildcard(TypeBoundKind(a.kind), Type(a.type));
break;
}
case CLASS:
Type outer = t.getEnclosingType();
JCExpression clazz = outer.hasTag(CLASS) && t.tsym.owner.kind == TYP ? Select(Type(outer), t.tsym) : QualIdent(t.tsym);
tp = t.getTypeArguments().isEmpty() ? clazz : TypeApply(clazz, Types(t.getTypeArguments()));
break;
case ARRAY:
tp = TypeArray(Type(types.elemtype(t)));
break;
case ERROR:
tp = TypeIdent(ERROR);
break;
default:
throw new AssertionError("unexpected type: " + t);
}
return tp.setType(t);
}
Aggregations