Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert annotations provided by the new parser to IR #3784

Merged
merged 4 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion engine/runtime/src/main/java/org/enso/compiler/TreeToIr.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.enso.compiler.core.IR$Module$Scope$Import$Module;
import org.enso.compiler.core.IR$Module$Scope$Import$Polyglot;
import org.enso.compiler.core.IR$Module$Scope$Import$Polyglot$Java;
import org.enso.compiler.core.IR$Name$Annotation;
import org.enso.compiler.core.IR$Name$Blank;
import org.enso.compiler.core.IR$Name$Literal;
import org.enso.compiler.core.IR$Name$MethodReference;
Expand Down Expand Up @@ -151,6 +152,12 @@ IR.Module translateModule(Tree module) {
var t = translateComment(app);
bindings = cons(t, bindings);
}
case Tree.Annotated anno -> {
var n = new IR$Name$Annotation("@" + anno.getAnnotation().codeRepr(), getIdentifiedLocation(anno), meta(), diag());
bindings = cons(n, bindings);
var t = translateModuleSymbol(anno.getExpression());
bindings = cons(t, bindings);
}
case null -> {
}
default -> {
Expand Down Expand Up @@ -404,7 +411,7 @@ case Left(reason) =>
}
*/
}
default -> new IR$Error$Syntax(inputAst, new IR$Error$Syntax$UnexpectedExpression$(), meta(), diag());
default -> new IR$Error$Syntax(inputAst, new IR$Error$Syntax$UnexpectedExpression$(), meta(), diag());
};
}

Expand Down Expand Up @@ -817,6 +824,10 @@ yield switch (ast) {
case Tree.Wildcard wild -> {
yield new IR$Name$Blank(getIdentifiedLocation(wild), meta(), diag());
}
case Tree.Annotated anno -> {
var ir = new IR$Name$Annotation("@" + anno.getAnnotation().codeRepr(), getIdentifiedLocation(anno), meta(), diag());
yield translateAnnotation(ir, anno.getExpression(), nil());
}
default -> throw new UnhandledEntity(tree, "translateExpression");
};
/*
Expand Down Expand Up @@ -947,6 +958,30 @@ yield switch (ast) {
*/
}

private IR$Application$Prefix translateAnnotation(IR$Name$Annotation ir, Tree expr, List<IR.CallArgument> callArgs) {
boolean insideTypeSignature = false;
return switch (expr) {
case Tree.App fn -> {
var fnAsArg = translateCallArgument(fn.getArg(), insideTypeSignature);
yield translateAnnotation(ir, fn.getFunc(), cons(fnAsArg, callArgs));
}
case Tree.ArgumentBlockApplication fn -> {
var fnAsArg = translateCallArgument(fn.getLhs(), insideTypeSignature);
var arg = translateCallArgument(expr, insideTypeSignature);
callArgs = cons(fnAsArg, cons(arg, callArgs));
yield translateAnnotation(ir, null, callArgs);
}
case null -> {
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
yield new IR$Application$Prefix(ir, callArgs, false, ir.location(), meta(), diag());
}
default -> {
var arg = translateCallArgument(expr, insideTypeSignature);
callArgs = cons(arg, callArgs);
yield translateAnnotation(ir, null, callArgs);
}
};
}

IR.Expression translateDecimalLiteral(Tree.Number ast) {
return translateDecimalLiteral(ast, ast.getInteger(), ast.getFractionalDigits());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,51 @@ public void testComments() throws Exception {
""");
}

@Test
public void testAnnotation0() throws Exception {
parseTest("""
dont_stop = @Tail_Call dont_stop
""");
}

@Test
public void testAnnotation1() throws Exception {
parseTest("""
go t = @Tail_Call go t-1
""");
}

@Test
public void testAnnotation2() throws Exception {
parseTest("""
go t x = @Tail_Call go t-1 x
""");
}

@Test
public void testAnnotationBlock() throws Exception {
parseTest("""
go a b = @Tail_Call go
a
b
""");
}

@Test
public void testBuiltinTypeAnnotation() throws Exception {
parseTest("""
@Builtin_Type
type Date
""");
}

@Test
public void testBuiltinMethodAnnotation() throws Exception {
parseTest("""
normalize x = @Builtin_Method "File.normalize"
""");
}

@Test
@Ignore
public void testMetadataRaw() throws Exception {
Expand Down