Java Uast: Initial implementation
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
class ControlStructures {
|
||||
public static void main(String[] args) {
|
||||
if (args.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
String mode = args.length == 1 ? "singleArg" : "multiArgs";
|
||||
|
||||
for (String arg : args) {
|
||||
System.out.println(arg);
|
||||
}
|
||||
|
||||
for (int i = 0; i < args.length; ++i) {
|
||||
System.out.println(i + ": " + args[i]);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while (i < args.length) {
|
||||
System.out.println("Index " + i);
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
do {
|
||||
System.out.println(i);
|
||||
i += 1;
|
||||
} while (i < args.length);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class Lambda {
|
||||
void example() {
|
||||
doJob(arg -> arg + arg, "Mary");
|
||||
}
|
||||
|
||||
void doJob(Job job, String arg) {
|
||||
System.out.println(job.doJob(arg));
|
||||
}
|
||||
}
|
||||
|
||||
interface Job {
|
||||
String doJob(String arg);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
class NestedClasses {
|
||||
public static class Nested {
|
||||
void func1() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class Inner {
|
||||
void func2() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class Simple {
|
||||
private String name;
|
||||
|
||||
public Simple(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
class SpecialExpressions {
|
||||
boolean test() {
|
||||
assert 5 > 3;
|
||||
assert 5 > 3 : "Message";
|
||||
|
||||
synchronized (this) {
|
||||
System.out.println("A");
|
||||
}
|
||||
|
||||
int a = 5, b = 7, c;
|
||||
|
||||
while (a > 0) {
|
||||
if (a == 3) {
|
||||
break;
|
||||
}
|
||||
if (a % 5 == 0) {
|
||||
continue;
|
||||
}
|
||||
a--;
|
||||
}
|
||||
|
||||
this.test();
|
||||
super.hashCode();
|
||||
|
||||
String x;
|
||||
switch (a) {
|
||||
case 1: {
|
||||
x = "1";
|
||||
break;
|
||||
}
|
||||
case 3: x = "3";
|
||||
case 4: x = "4";
|
||||
default: x = "";
|
||||
}
|
||||
|
||||
if (System.getProperty("abc", "").equals("1")) {
|
||||
throw new AssertionError("Err");
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
} finally {
|
||||
a = 3;
|
||||
}
|
||||
|
||||
{
|
||||
a = 5;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
UFile (package = null)
|
||||
UClass (_Dummy_, enum = false, interface = false, object = false)
|
||||
UClass (ControlStructures, enum = false, interface = false, object = false)
|
||||
UFunction (main, kind = function, paramCount = 1)
|
||||
UBlockExpression
|
||||
UIfExpression
|
||||
UBinaryExpression (===)
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (args)
|
||||
USimpleReferenceExpression (length)
|
||||
ULiteralExpression (0)
|
||||
UBlockExpression
|
||||
USpecialExpressionList (return)
|
||||
|
||||
EmptyExpression
|
||||
UDeclarationsExpression
|
||||
UVariable (mode, kind = local)
|
||||
UIfExpression
|
||||
UBinaryExpression (===)
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (args)
|
||||
USimpleReferenceExpression (length)
|
||||
ULiteralExpression (1)
|
||||
ULiteralExpression ("singleArg")
|
||||
ULiteralExpression ("multiArgs")
|
||||
UForEachExpression (arg)
|
||||
USimpleReferenceExpression (args)
|
||||
UBlockExpression
|
||||
UQualifiedExpression
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (System)
|
||||
USimpleReferenceExpression (out)
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||
USimpleReferenceExpression (println)
|
||||
USimpleReferenceExpression (arg)
|
||||
UForExpression
|
||||
UDeclarationsExpression
|
||||
UVariable (i, kind = local)
|
||||
ULiteralExpression (0)
|
||||
UBinaryExpression (<)
|
||||
USimpleReferenceExpression (i)
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (args)
|
||||
USimpleReferenceExpression (length)
|
||||
UPrefixExpression (++)
|
||||
USimpleReferenceExpression (i)
|
||||
UBlockExpression
|
||||
UQualifiedExpression
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (System)
|
||||
USimpleReferenceExpression (out)
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||
USimpleReferenceExpression (println)
|
||||
UBinaryExpression (+)
|
||||
UBinaryExpression (+)
|
||||
USimpleReferenceExpression (i)
|
||||
ULiteralExpression (": ")
|
||||
UArrayAccessExpression
|
||||
USimpleReferenceExpression (args)
|
||||
USimpleReferenceExpression (i)
|
||||
UDeclarationsExpression
|
||||
UVariable (i, kind = local)
|
||||
ULiteralExpression (0)
|
||||
UWhileExpression
|
||||
UBinaryExpression (<)
|
||||
USimpleReferenceExpression (i)
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (args)
|
||||
USimpleReferenceExpression (length)
|
||||
UBlockExpression
|
||||
UQualifiedExpression
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (System)
|
||||
USimpleReferenceExpression (out)
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||
USimpleReferenceExpression (println)
|
||||
UBinaryExpression (+)
|
||||
ULiteralExpression ("Index ")
|
||||
USimpleReferenceExpression (i)
|
||||
UPostfixExpression (++)
|
||||
USimpleReferenceExpression (i)
|
||||
UAssignmentExpression (=)
|
||||
USimpleReferenceExpression (i)
|
||||
ULiteralExpression (0)
|
||||
UDoWhileExpression
|
||||
UBinaryExpression (<)
|
||||
USimpleReferenceExpression (i)
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (args)
|
||||
USimpleReferenceExpression (length)
|
||||
UBlockExpression
|
||||
UQualifiedExpression
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (System)
|
||||
USimpleReferenceExpression (out)
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||
USimpleReferenceExpression (println)
|
||||
USimpleReferenceExpression (i)
|
||||
UAssignmentExpression (+=)
|
||||
USimpleReferenceExpression (i)
|
||||
ULiteralExpression (1)
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
UFile (package = null)
|
||||
UClass (_Dummy_, enum = false, interface = false, object = false)
|
||||
UClass (Lambda, enum = false, interface = false, object = false)
|
||||
UFunction (example, kind = function, paramCount = 0)
|
||||
UBlockExpression
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 2)
|
||||
USimpleReferenceExpression (doJob)
|
||||
ULambdaExpression
|
||||
UVariable (arg, kind = parameter)
|
||||
<no initializer>
|
||||
UBinaryExpression (+)
|
||||
USimpleReferenceExpression (arg)
|
||||
USimpleReferenceExpression (arg)
|
||||
ULiteralExpression ("Mary")
|
||||
UFunction (doJob, kind = function, paramCount = 2)
|
||||
UBlockExpression
|
||||
UQualifiedExpression
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (System)
|
||||
USimpleReferenceExpression (out)
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||
USimpleReferenceExpression (println)
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (job)
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||
USimpleReferenceExpression (doJob)
|
||||
USimpleReferenceExpression (arg)
|
||||
UClass (Job, enum = false, interface = true, object = false)
|
||||
UFunction (doJob, kind = function, paramCount = 1)
|
||||
EmptyExpression
|
||||
@@ -0,0 +1,11 @@
|
||||
UFile (package = null)
|
||||
UClass (_Dummy_, enum = false, interface = false, object = false)
|
||||
UClass (NestedClasses, enum = false, interface = false, object = false)
|
||||
UClass (Nested, enum = false, interface = false, object = false)
|
||||
UFunction (func1, kind = function, paramCount = 0)
|
||||
UBlockExpression
|
||||
|
||||
UClass (Inner, enum = false, interface = false, object = false)
|
||||
UFunction (func2, kind = function, paramCount = 0)
|
||||
UBlockExpression
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
UFile (package = null)
|
||||
UClass (_Dummy_, enum = false, interface = false, object = false)
|
||||
UClass (Simple, enum = false, interface = false, object = false)
|
||||
UVariable (name, kind = member)
|
||||
EmptyExpression
|
||||
UFunction (Simple, kind = function, paramCount = 1)
|
||||
UBlockExpression
|
||||
UAssignmentExpression (=)
|
||||
UQualifiedExpression
|
||||
UThisExpression
|
||||
USimpleReferenceExpression (name)
|
||||
USimpleReferenceExpression (name)
|
||||
UFunction (getName, kind = function, paramCount = 0)
|
||||
UBlockExpression
|
||||
USpecialExpressionList (return)
|
||||
USimpleReferenceExpression (name)
|
||||
UFunction (setName, kind = function, paramCount = 1)
|
||||
UBlockExpression
|
||||
UAssignmentExpression (=)
|
||||
UQualifiedExpression
|
||||
UThisExpression
|
||||
USimpleReferenceExpression (name)
|
||||
USimpleReferenceExpression (name)
|
||||
@@ -0,0 +1,130 @@
|
||||
UFile (package = null)
|
||||
UClass (_Dummy_, enum = false, interface = false, object = false)
|
||||
UClass (SpecialExpressions, enum = false, interface = false, object = false)
|
||||
UFunction (test, kind = function, paramCount = 0)
|
||||
UBlockExpression
|
||||
USpecialExpressionList (assert)
|
||||
UBinaryExpression (>)
|
||||
ULiteralExpression (5)
|
||||
ULiteralExpression (3)
|
||||
EmptyExpression
|
||||
USpecialExpressionList (assert)
|
||||
UBinaryExpression (>)
|
||||
ULiteralExpression (5)
|
||||
ULiteralExpression (3)
|
||||
ULiteralExpression ("Message")
|
||||
USpecialExpressionList (synchronized)
|
||||
UThisExpression
|
||||
UBlockExpression
|
||||
UQualifiedExpression
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (System)
|
||||
USimpleReferenceExpression (out)
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||
USimpleReferenceExpression (println)
|
||||
ULiteralExpression ("A")
|
||||
UDeclarationsExpression
|
||||
UVariable (a, kind = local)
|
||||
ULiteralExpression (5)
|
||||
UVariable (b, kind = local)
|
||||
ULiteralExpression (7)
|
||||
UVariable (c, kind = local)
|
||||
EmptyExpression
|
||||
UWhileExpression
|
||||
UBinaryExpression (>)
|
||||
USimpleReferenceExpression (a)
|
||||
ULiteralExpression (0)
|
||||
UBlockExpression
|
||||
UIfExpression
|
||||
UBinaryExpression (===)
|
||||
USimpleReferenceExpression (a)
|
||||
ULiteralExpression (3)
|
||||
UBlockExpression
|
||||
USpecialExpressionList (break)
|
||||
|
||||
EmptyExpression
|
||||
UIfExpression
|
||||
UBinaryExpression (===)
|
||||
UBinaryExpression (%)
|
||||
USimpleReferenceExpression (a)
|
||||
ULiteralExpression (5)
|
||||
ULiteralExpression (0)
|
||||
UBlockExpression
|
||||
USpecialExpressionList (continue)
|
||||
|
||||
EmptyExpression
|
||||
UPostfixExpression (--)
|
||||
USimpleReferenceExpression (a)
|
||||
UQualifiedExpression
|
||||
UThisExpression
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 0)
|
||||
USimpleReferenceExpression (test)
|
||||
|
||||
UQualifiedExpression
|
||||
USuperExpression
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 0)
|
||||
USimpleReferenceExpression (hashCode)
|
||||
|
||||
UDeclarationsExpression
|
||||
UVariable (x, kind = local)
|
||||
EmptyExpression
|
||||
USwitchExpression
|
||||
USimpleReferenceExpression (a)
|
||||
UBlockExpression
|
||||
UExpressionSwitchClauseExpression
|
||||
ULiteralExpression (1)
|
||||
UBlockExpression
|
||||
UAssignmentExpression (=)
|
||||
USimpleReferenceExpression (x)
|
||||
ULiteralExpression ("1")
|
||||
USpecialExpressionList (break)
|
||||
|
||||
UExpressionSwitchClauseExpression
|
||||
ULiteralExpression (3)
|
||||
UAssignmentExpression (=)
|
||||
USimpleReferenceExpression (x)
|
||||
ULiteralExpression ("3")
|
||||
UExpressionSwitchClauseExpression
|
||||
ULiteralExpression (4)
|
||||
UAssignmentExpression (=)
|
||||
USimpleReferenceExpression (x)
|
||||
ULiteralExpression ("4")
|
||||
UDefaultSwitchClause
|
||||
UAssignmentExpression (=)
|
||||
USimpleReferenceExpression (x)
|
||||
ULiteralExpression ("")
|
||||
UIfExpression
|
||||
UQualifiedExpression
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (System)
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 2)
|
||||
USimpleReferenceExpression (getProperty)
|
||||
ULiteralExpression ("abc")
|
||||
ULiteralExpression ("")
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||
USimpleReferenceExpression (equals)
|
||||
ULiteralExpression ("1")
|
||||
UBlockExpression
|
||||
USpecialExpressionList (throw)
|
||||
UFunctionCallExpression (CONSTRUCTOR_CALL, argCount = 1)
|
||||
<no element>
|
||||
ULiteralExpression ("Err")
|
||||
EmptyExpression
|
||||
UTryExpression
|
||||
UBlockExpression
|
||||
UQualifiedExpression
|
||||
USimpleReferenceExpression (Thread)
|
||||
UFunctionCallExpression (FUNCTION_CALL, argCount = 1)
|
||||
USimpleReferenceExpression (sleep)
|
||||
ULiteralExpression (1000) UCatchClause
|
||||
UBlockExpression
|
||||
UBlockExpression
|
||||
UAssignmentExpression (=)
|
||||
USimpleReferenceExpression (a)
|
||||
ULiteralExpression (3)
|
||||
UBlockExpression
|
||||
UAssignmentExpression (=)
|
||||
USimpleReferenceExpression (a)
|
||||
ULiteralExpression (5)
|
||||
USpecialExpressionList (return)
|
||||
ULiteralExpression (true)
|
||||
@@ -0,0 +1,33 @@
|
||||
default class _Dummy_ {
|
||||
default inner class ControlStructures {
|
||||
public fun main(args: java.lang.String[]): void {
|
||||
if (args.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
var mode: String = (args.length === 1) ? ("singleArg") : ("multiArgs")
|
||||
for (arg : args) {
|
||||
System.out.println(arg)
|
||||
}
|
||||
|
||||
for (var i: int = 0; i < args.length; ++i) {
|
||||
System.out.println(i + ": " + args[i])
|
||||
}
|
||||
|
||||
var i: int = 0
|
||||
while (i < args.length) {
|
||||
System.out.println("Index " + i)
|
||||
i++
|
||||
}
|
||||
|
||||
i = 0
|
||||
do {
|
||||
System.out.println(i)
|
||||
i += 1
|
||||
}
|
||||
while (i < args.length)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
default class _Dummy_ {
|
||||
default inner class Lambda {
|
||||
default fun example(): void {
|
||||
doJob({ arg: String ->
|
||||
arg + arg
|
||||
}, "Mary")
|
||||
}
|
||||
|
||||
default fun doJob(job: Job, arg: String): void {
|
||||
System.out.println(job.doJob(arg))
|
||||
}
|
||||
|
||||
}
|
||||
default abstract interface Job {
|
||||
public fun doJob(arg: String): String = EmptyExpression
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
default class _Dummy_ {
|
||||
default inner class NestedClasses {
|
||||
public class Nested {
|
||||
default fun func1(): void {
|
||||
}
|
||||
|
||||
}
|
||||
public inner class Inner {
|
||||
default fun func2(): void {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
default class _Dummy_ {
|
||||
default inner class Simple {
|
||||
var name: String
|
||||
|
||||
public fun Simple(name: String) {
|
||||
this.name = name
|
||||
}
|
||||
|
||||
public fun getName(): String {
|
||||
return name
|
||||
}
|
||||
|
||||
public fun setName(name: String): void {
|
||||
this.name = name
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
default class _Dummy_ {
|
||||
default inner class SpecialExpressions {
|
||||
default fun test(): boolean {
|
||||
assert 5 > 3 : EmptyExpression
|
||||
assert 5 > 3 : "Message"
|
||||
synchronized this : {
|
||||
System.out.println("A")
|
||||
}
|
||||
|
||||
var a: int = 5
|
||||
var b: int = 7
|
||||
var c: int
|
||||
while (a > 0) {
|
||||
if (a === 3) {
|
||||
break
|
||||
}
|
||||
|
||||
if (a % 5 === 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
a--
|
||||
}
|
||||
|
||||
this.test()
|
||||
super.hashCode()
|
||||
var x: String
|
||||
switch (a)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
x = "1"
|
||||
break
|
||||
}
|
||||
|
||||
case 3:
|
||||
x = "3"
|
||||
case 4:
|
||||
x = "4"
|
||||
else:
|
||||
x = ""
|
||||
}
|
||||
|
||||
|
||||
if (System.getProperty("abc", "").equals("1")) {
|
||||
throw <noref>("Err")
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
|
||||
catch (e) {
|
||||
}
|
||||
|
||||
finally {
|
||||
a = 3
|
||||
}
|
||||
|
||||
{
|
||||
a = 5
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user