use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class SerializationHelper method serializeGetter.
private static void serializeGetter(final Node that, final String typename, final Class owner, final List<Value> vals, final Class supertype, GenerateJsVisitor gen) {
gen.out(typename, ".ser$get$=function(ref,o){");
if (!vals.isEmpty()) {
gen.out("var n=ref.attribute.qualifiedName;");
}
boolean first = true;
for (Value v : vals) {
if (first) {
first = false;
} else {
gen.out("else ");
}
final String vname = name(owner, v, gen);
gen.out("if(n==='", v.getQualifiedNameString(), "')return o.", vname);
if (v.isLate()) {
gen.out("===undefined?", gen.getClAlias(), "uninitializedLateValue$serialization():o.", vname);
}
gen.endLine(true);
}
if (!first) {
gen.out("else ");
}
if (supertype != null) {
gen.out("return ");
gen.qualify(that, supertype);
gen.out(gen.getNames().name(supertype), ".ser$get$(ref,o);");
} else {
gen.out("throw new TypeError('unknown attribute');");
}
gen.endBlockNewLine(true);
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class SerializationHelper method serializeRefs.
private static void serializeRefs(final Node that, final String typename, final Class owner, final List<Value> vals, final Class supertype, GenerateJsVisitor gen) {
if (supertype == null) {
gen.out(typename, ".ser$refs$=function(o){return [");
} else {
gen.out(typename, ".ser$refs$=function(o){var a=");
gen.qualify(that, supertype);
gen.out(gen.getNames().name(supertype), ".ser$refs$(o);a.push(");
}
boolean first = true;
final String pkgname = owner.getUnit().getPackage().getNameAsString();
for (Value v : vals) {
if (first) {
first = false;
} else {
gen.out(",");
}
gen.out(gen.getClAlias(), "MemberImpl$impl(", gen.getClAlias(), "OpenValue$jsint(", gen.getClAlias(), "lmp$(ex$,'", "ceylon.language".equals(pkgname) ? "$" : pkgname, "'),o.", gen.getNames().getter(v, true), "))");
}
if (supertype == null) {
gen.out("];");
} else {
gen.out(");return a;");
}
gen.endBlockNewLine(true);
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class Singletons method valueConstructor.
static void valueConstructor(final Tree.ClassDefinition cdef, final Tree.Enumerated that, final GenerateJsVisitor gen) {
final Value d = that.getDeclarationModel();
final Constructor c = that.getEnumerated();
final Tree.DelegatedConstructor dc = that.getDelegatedConstructor();
final TypeDeclaration td = (TypeDeclaration) c.getContainer();
final String objvar = gen.getNames().createTempVariable();
final String selfvar = gen.getNames().self(td);
final String typevar = gen.getNames().name(td);
final String singvar = gen.getNames().name(d);
final boolean nested = cdef.getDeclarationModel().isClassOrInterfaceMember();
final String constructorName = typevar + gen.getNames().constructorSeparator(c) + singvar;
gen.out(nested ? "this." : "var ", objvar, "=undefined;function ", constructorName, "(){if(", nested ? "this." : "", objvar, "===undefined){");
if (dc == null) {
gen.out("$init$", typevar, "();");
}
if (nested) {
gen.out("var ", selfvar, "=");
} else {
gen.out(objvar, "=");
}
gen.out("new ", typevar, ".$$;");
if (td.isClassOrInterfaceMember()) {
gen.out(nested ? selfvar : objvar, ".outer$=this;");
}
if (dc != null) {
Tree.InvocationExpression invoke = dc.getInvocationExpression();
invoke.getPrimary().visit(gen);
gen.out("(");
// For now, only positional invocations are allowed here
gen.getInvoker().generatePositionalArguments(invoke.getPrimary(), invoke.getPositionalArgumentList(), invoke.getPositionalArgumentList().getPositionalArguments(), false, false);
if (!invoke.getPositionalArgumentList().getPositionalArguments().isEmpty()) {
gen.out(",");
}
if (!dc.getType().getTypeModel().getTypeArguments().isEmpty()) {
TypeUtils.printTypeArguments(dc, dc.getType().getTypeModel().getTypeArguments(), gen, false, dc.getType().getTypeModel().getVarianceOverrides());
gen.out(",");
}
gen.out(nested ? selfvar : objvar, ")");
gen.endLine(true);
}
if (!nested) {
gen.out("var ", selfvar, "=", objvar, ";");
}
ClassGenerator.addFunctionTypeArguments(cdef.getDeclarationModel(), objvar, gen);
ClassGenerator.callSupertypes(cdef, cdef.getDeclarationModel(), typevar, gen);
List<? extends Tree.Statement> stmts = Constructors.classStatementsBetweenConstructors(cdef, null, that, gen);
if (!stmts.isEmpty()) {
gen.generateConstructorStatements(that, stmts);
}
stmts = Constructors.classStatementsAfterConstructor(cdef, that);
if (!stmts.isEmpty()) {
gen.visitStatements(stmts);
}
if (nested) {
gen.out("this.", objvar, "=", selfvar, ";");
}
gen.out("}return ", nested ? "this." : "", objvar, ";};", constructorName, ".$crtmm$=");
TypeUtils.encodeForRuntime(that, that.getDeclarationModel(), that.getAnnotationList(), gen);
gen.out(";");
if (td.isClassOrInterfaceMember()) {
gen.outerSelf(td);
gen.out(".", constructorName, "=", constructorName, ";");
} else if (td.isShared()) {
gen.out("ex$.", constructorName, "=", constructorName, ";");
}
gen.out(gen.getNames().name(td), ".", constructorName, "=", constructorName);
gen.endLine(true);
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class Destructurer method visit.
public void visit(final Tree.VariablePattern that) {
Tree.Variable v = that.getVariable();
final Value d = v.getDeclarationModel();
if (directAccess != null) {
directAccess.add(d);
}
if (d.isClassOrInterfaceMember()) {
attribs.add(d);
}
if (d.isJsCaptured()) {
caps.add(d);
}
added.add(v);
if (first) {
first = false;
} else if (jsw != null) {
jsw.write(",");
}
if (jsw != null) {
jsw.write(names.name(d), "=");
int minLength = spread.containsKey(v) ? spread.get(v) : 0;
if (minLength > 0) {
jsw.write(gen.getClAlias(), "$cksprdstr$(", Integer.toString(minLength), ",\'", v.getDeclarationModel().getType().asString(), "','", v.getIdentifier().getText(), "','", v.getLocation(), "','", v.getUnit().getFilename(), "',");
}
jsw.write(expvar);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class BmeGenerator method generateStaticReference.
static void generateStaticReference(Node n, Declaration d, GenerateJsVisitor gen) {
Declaration orig = d instanceof TypedDeclaration ? ((TypedDeclaration) d).getOriginalDeclaration() : d;
ClassOrInterface coi = (ClassOrInterface) (orig == null ? d : orig).getContainer();
gen.qualify(n, coi);
gen.out(gen.getNames().name(coi), ".$st$.", gen.getNames().name(d));
if (d instanceof Value && ((Value) d).getType().getDeclaration().isAnonymous()) {
gen.out("()");
}
}
Aggregations