Search in sources :

Example 16 with FunctionOrValue

use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.

the class JsIdentifierNames method name.

public String name(Parameter param) {
    if (param == null) {
        return null;
    }
    String name = param.getName();
    FunctionOrValue decl = param.getModel();
    final boolean nonLocal = decl.isShared() && decl.isMember() || decl.isToplevel() && decl instanceof Function;
    if (nonLocal) {
        // The identifier might be accessed from other .js files, so it must
        // be reliably reproducible. In most cases simply using the original
        // name is ok because otherwise it would result in a name collision in
        // Ceylon too. We just have to take care of a few exceptions:
        String suffix = nestingSuffix(decl, false);
        if (suffix.length() > 0) {
            // nested type
            name += suffix;
        } else if (reservedWords.contains(name)) {
            // JavaScript keyword
            name = "$_" + name;
        }
    } else {
        // The identifier will not be used outside the generated .js file,
        // so we can simply disambiguate it with a numeric ID.
        name = uniquePrivateName(decl, false);
    }
    return JsUtils.escapeStringLiteral(name);
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 17 with FunctionOrValue

use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.

the class TestModuleManager method tmptest.

@Test
public void tmptest() {
    System.out.println("-----------------------");
    ClassOrInterface d0 = (ClassOrInterface) srclang.getDirectMember("Iterable", null, false);
    Assert.assertNotNull("ContainerWithFirstElement from srclang", d0);
    ClassOrInterface d1 = (ClassOrInterface) jslang.getDirectMember("Iterable", null, false);
    Assert.assertNotNull("ContainerWithFirstElement from jslang", d1);
    Type seq0 = null, seq1 = null;
    for (Type pt : d0.getSatisfiedTypes()) {
        System.out.println(d0 + " satisfies " + pt);
        if (pt.asString().startsWith("Null[]")) {
            seq0 = pt;
            break;
        }
    }
    for (Type pt : d1.getSatisfiedTypes()) {
        if (pt.asString().startsWith("Null[]")) {
            seq1 = pt;
            break;
        }
    }
    compareTypes(seq0, seq1, new ArrayList<String>());
    System.out.println("src " + seq0 + " - js " + seq1);
    compareTypeDeclarations(d0, d1);
    FunctionOrValue m0 = (FunctionOrValue) d0.getDirectMember("last", null, false);
    FunctionOrValue m1 = (FunctionOrValue) d1.getDirectMember("last", null, false);
    System.out.println("Iterable.last " + m0 + " vs " + m1);
    System.out.println("refined member " + d0.getRefinedMember("last", null, false).getContainer() + " vs " + d1.getRefinedMember("last", null, false).getContainer());
    System.out.println("last is transient? " + m0.isTransient() + " vs " + m1.isTransient());
    System.out.println("refined " + m0.getRefinedDeclaration().getContainer() + " vs " + m1.getRefinedDeclaration().getContainer());
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Type(org.eclipse.ceylon.model.typechecker.model.Type) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Test(org.junit.Test)

Example 18 with FunctionOrValue

use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.

the class RefinementVisitor method checkSmallRefinement.

private void checkSmallRefinement(Node that, Declaration refiningDeclaration, Declaration refinedDeclaration) {
    if (refiningDeclaration instanceof FunctionOrValue && refinedDeclaration instanceof FunctionOrValue) {
        FunctionOrValue refiningFunctionOrValue = (FunctionOrValue) refiningDeclaration;
        FunctionOrValue refinedFunctionOrValue = (FunctionOrValue) refinedDeclaration;
        boolean refiningSmall = refiningFunctionOrValue.isSmall();
        boolean refinedSmall = refinedFunctionOrValue.isSmall();
        if (refiningSmall && !refinedSmall) {
            that.addUsageWarning(Warning.smallIgnored, "small annotation on actual member " + message(refiningDeclaration) + " will be ignored: " + message(refinedDeclaration) + " is not small");
        }
        refiningFunctionOrValue.setSmall(refinedSmall);
    }
}
Also used : FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 19 with FunctionOrValue

use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.

the class SelfReferenceVisitor method visit.

@Override
public void visit(Tree.AssignmentOp that) {
    super.visit(that);
    if (inBody()) {
        Tree.Term lt = that.getLeftTerm();
        Tree.Term rt = that.getRightTerm();
        if (lt instanceof Tree.MemberOrTypeExpression && rt instanceof Tree.This) {
            MemberOrTypeExpression mte = (Tree.MemberOrTypeExpression) lt;
            Declaration d = mte.getDeclaration();
            if (d instanceof FunctionOrValue) {
                FunctionOrValue fov = (FunctionOrValue) d;
                if (fov.isLate()) {
                    // NOTE: EARLY EXIT!!
                    return;
                }
            }
        }
        checkSelfReference(that, rt);
    }
}
Also used : MemberOrTypeExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.MemberOrTypeExpression) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) MemberOrTypeExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.MemberOrTypeExpression) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 20 with FunctionOrValue

use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.

the class SpecificationVisitor method specification.

private void specification(Tree.SpecifierStatement that, Tree.StaticMemberOrTypeExpression bme) {
    boolean constant = !isVariable() && !isLate();
    Scope scope = that.getScope();
    if (constant && (!declaration.isDefinedInScope(scope) || declaration instanceof FunctionOrValue && ((FunctionOrValue) declaration).isShortcutRefinement())) {
    // this error is added by ExpressionVisitor
    // that.addError("inherited member is not variable and may not be specified here: " +
    // name());
    } else if (!declared && constant) {
        bme.addError(shortdesc() + " is not yet declared: " + name());
    } else if (loopDepth > 0 && constant && !(endsInReturnThrow && lastContinue == null || endsInBreak && allOuterLoopsBreak && lastContinue == null)) {
        if (definitely) {
            bme.addError(longdesc() + " is aready definitely specified: " + name(), 803);
        } else {
            bme.addError(longdesc() + " is not definitely unspecified in loop: " + name(), 803);
            // to eliminate dupe error
            specify();
        }
    } else if (specificationDisabled && constant) {
        if (withinDeclaration) {
            bme.addError("cannot specify " + shortdesc() + " from within its own body: " + name());
        } else {
            bme.addError("cannot specify " + shortdesc() + " declared in outer scope: " + name(), 803);
        }
    } else if (possibly && constant) {
        if (definitely) {
            bme.addError(longdesc() + " is aready definitely specified: " + name(), 803);
        } else {
            bme.addError(longdesc() + " is not definitely unspecified: " + name(), 803);
            // to eliminate dupe error
            specify();
        }
    } else {
        specify();
        bme.visit(this);
    }
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Aggregations

FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)65 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)28 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)27 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)26 Type (org.eclipse.ceylon.model.typechecker.model.Type)25 Value (org.eclipse.ceylon.model.typechecker.model.Value)24 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)22 Function (org.eclipse.ceylon.model.typechecker.model.Function)22 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)21 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)19 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)13 ArrayList (java.util.ArrayList)12 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)11 TypedReference (org.eclipse.ceylon.model.typechecker.model.TypedReference)10 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)9 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)9 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)9 ModelUtil.genericFunctionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType)9 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)9 ModelUtil.unionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType)9