Commit 1df549be by Tianqi Yang

test(original_error): add test suite original_error for CE tests

Add test suite original_error for compilation error tests
parent b5a32c03
class Main {
int[] a;
static void main() {
}
void func() {
a = new int[-1]; // valid
a = new int["123"];
int a;
a.length();
a[1] = 2;
this.a.length(0);
a = this.a[false];
}
}
\ No newline at end of file
class Main {
int div;
static void main() {
Print(add(1));
Print(Main.add(1, new Main()));
new Main().length();
int[] a;
a = new int[true];
a.length(1);
int b;
b = 1;
b.length();
Main.sub(1, 2);
mul(1, 2);
Main.mul(1, 2);
new Main().mul();
new Main().div();
}
static int add(int a, int b) {
return a + b;
}
int sub(int a, int b) {
return a - b;
}
}
\ No newline at end of file
class Main {
int a;
static void main() {
class Main a;
int a;
int b;
b = 2;
if (b > 1) {
class B c;
}
void c;
void[] d;
}
void a() {
}
}
class A {
int a;
int b;
static void func() {
}
void func1(int a) {
int a;
}
}
class B extends A {
static int b() {
return 0;
}
void func() {
}
int func1;
}
class A {
}
class C extends D {
}
\ No newline at end of file
class Main {
static void main() {
int a;
int b;
bool d;
string s;
a = 1;
b = 1.2;
c = 1;
d = 1;
s = d;
a = b + s;
b = a - d;
c = c * d;
d = d / d;
a = a % d;
d = !a;
d = d && b;
d = d || c;
Main = 1;
a = Main + 1;
d = a > d;
d = a >= d;
d = b < d;
d = d <= d;
d = a != d;
d = b == d;
while (a);
for (;b;);
}
}
\ No newline at end of file
class Math {
static int abs(int a) {
if (a >= 0) {
return a;
} else {
return -a;
}
}
static int pow(int a, int b) {
int i;
int result;
result = 1;
for (i = 0; i < b; i = i + 1) {
result = result * a;
}
return result;
}
static int log(int a) {
if (a < 1) {
return -1;
}
int result;
result = 0;
while (a > 1) {
result = result + 1;
a = a / 2;
}
return result;
}
static int max(int a, int b) {
if (a > b) {
return a;
} else {
return b;
}
}
static int min(int a, int b) {
if (a < b) {
return a;
} else {
return b;
}
}
}
class Main {
static void main() {
Print(Math.abs(-1), "\n");
Print(Math.pow(2, 3), "\n");
Print(Math.log(16), "\n");
Print(Math.max(1, 2), "\n");
Print(Math.min(1, 2), "\n");
}
}
\ No newline at end of file
class Main {
static void main() {
Print(new Main(), 1);
if (true)
break;
Print(instanceof(1, Main));
class Main m;
m = (class Main)true;
return 1;
}
}
\ No newline at end of file
class Main {
static int main() {
}
}
class Main1 {
static void main(int i) {
}
}
\ No newline at end of file
class Main {
static void main() {
}
}
class A {
int func() {
}
class A func1(class A a) {
}
class B func2(class B b) {
}
class A func3(class B b) {
}
}
class B extends A {
void func() {
}
class B func1(class B b) {
}
class A func2(class A a) {
}
class B func3(class A a) {
}
}
class C1 extends C2 {
}
class C2 extends C1 {
}
\ No newline at end of file
class QueueItem {
int data;
class QueueItem next;
class QueueItem prev;
void Init(int data, class QueueItem next, class QueueItem prev) {
this.data = data;
this.next = next;
next.prev = this;
this.prev = prev;
prev.next = this;
}
int GetData() {
return this.data;
}
class QueueItem GetNext() {
return next;
}
class QueueItem GetPrev() {
return prev;
}
void SetNext(class QueueItem n) {
next = n;
}
void SetPrev(class QueueItem p) {
prev = p;
}
}
class Queue {
int sp;
class QueueItem head;
void Init() {
this.head = new QueueItem();
this.head.Init(0, this.head, this.head);
}
void EnQueue(int i) {
class QueueItem temp;
temp = new QueueItem();
temp.Init(i, this.head.GetNext(), this.head);
}
int DeQueue() {
int val;
if (this.head.GetPrev() == this.head) {
Print("Queue Is Empty");
return 0;
} else {
class QueueItem temp;
temp = this.head.GetPrev();
val = temp.GetData();
temp.GetPrev().SetNext(temp.GetNext());
temp.GetNext().SetPrev(temp.GetPrev());
}
return val;
}
}
class Main {
static void main() {
class Queue q;
int i;
q = new Queue();
q.Init();
for (i = 0; i < 10; i = i + 1)
q.EnQueue(i);
for (i = 0; i < 4; i = i + 1)
Print(q.DeQueue(), " ");
Print("\n");
for (i = 0; i < 10; i = i + 1)
q.EnQueue(i);
for (i = 0; i < 17; i = i + 1)
Print(q.DeQueue(), " ");
Print("\n");
}
}
class Main {
int a;
static void main() {
a = 1;
this.a = 1;
Main.a = 1;
func();
}
void func() {
new Test().b = 1;
}
}
class Test extends Main {
int b;
}
\ No newline at end of file
*** Error at (9,21): new array length must be an integer
*** Error at (11,11): 'length' can only be applied to arrays
*** Error at (12,9): [] can only be applied to arrays
*** Error at (13,16): function 'length' expects 0 argument(s) but 1 given
*** Error at (14,13): array subscript must be an integer
*** Error at (5,15): function 'add' expects 2 argument(s) but 1 given
*** Error at (6,27): incompatible argument 2: class : Main given, int expected
*** Error at (7,20): field 'length' not found in 'class : Main'
*** Error at (9,21): new array length must be an integer
*** Error at (10,11): function 'length' expects 0 argument(s) but 1 given
*** Error at (13,11): 'length' can only be applied to arrays
*** Error at (14,14): cannot access field 'sub' from 'class : Main'
*** Error at (15,9): field 'mul' not found in 'class : Main'
*** Error at (16,14): field 'mul' not found in 'class : Main'
*** Error at (17,20): field 'mul' not found in 'class : Main'
*** Error at (18,20): 'div' is not a method in class 'class : Main'
*** Error at (5,13): declaration of 'a' here conflicts with earlier declaration at (4,20)
*** Error at (11,14): cannot declare identifier 'c' as void type
*** Error at (12,9): array element type must be non-void known type
*** Error at (14,10): declaration of 'a' here conflicts with earlier declaration at (2,9)
*** Error at (27,10): declaration of 'a' here conflicts with earlier declaration at (26,20)
*** Error at (33,16): declaration of 'b' here conflicts with earlier declaration at (21,9)
*** Error at (37,10): declaration of 'func' here conflicts with earlier declaration at (23,17)
*** Error at (40,9): declaration of 'func1' here conflicts with earlier declarations :
*** note : previously declared at (26,10) : void func1(int)
*** Error at (43,1): declaration of 'A' here conflicts with earlier declaration at (18,1)
*** Error at (46,1): class 'D' not found
*** Error at (8,15): syntax error
GLOBAL SCOPE:
(1,1) -> class Math
(50,1) -> class Main
CLASS SCOPE OF 'Math':
(2,16) -> static function FUNCTION__2_16_____static_function_abs___int__int_2922738402 : int->int
(10,16) -> static function FUNCTION__10_16_____static_function_pow___int__int__int_1743071814 : int->int->int
(20,16) -> static function FUNCTION__20_16_____static_function_log___int__int_3631764223 : int->int
(33,16) -> static function FUNCTION__33_16_____static_function_max___int__int__int_2114371152 : int->int->int
(41,16) -> static function FUNCTION__41_16_____static_function_min___int__int__int_1365416843 : int->int->int
FORMAL SCOPE OF 'abs':
(2,24) -> variable @a : int
LOCAL SCOPE:
FORMAL SCOPE OF 'pow':
(10,24) -> variable @a : int
(10,31) -> variable @b : int
LOCAL SCOPE:
(11,13) -> variable i : int
(12,13) -> variable result : int
FORMAL SCOPE OF 'log':
(20,24) -> variable @a : int
LOCAL SCOPE:
(24,13) -> variable result : int
FORMAL SCOPE OF 'max':
(33,24) -> variable @a : int
(33,31) -> variable @b : int
LOCAL SCOPE:
FORMAL SCOPE OF 'min':
(41,24) -> variable @a : int
(41,31) -> variable @b : int
LOCAL SCOPE:
CLASS SCOPE OF 'Main':
(51,17) -> static function FUNCTION__51_17_____static_function_main___void_2757637063 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
*** Error at (3,15): incompatible argument 1: class : Main given, int/bool/string expected
*** Error at (5,13): 'break' is only allowed inside a loop
*** Error at (6,15): int is not a class type
*** Error at (8,25): bool is not a class type
*** Error at (9,9): incompatible return: int given, void expected
*** Error: no legal Main class named 'Main' was found
*** Error at (37,1): illegal class inheritance (should be a cyclic)
GLOBAL SCOPE:
(1,1) -> class QueueItem
(30,1) -> class Queue
(59,1) -> class Main
CLASS SCOPE OF 'QueueItem':
(2,9) -> variable data : int
(3,21) -> variable next : class : QueueItem
(4,21) -> variable prev : class : QueueItem
(6,10) -> function FUNCTION__6_10_____function_Init___class___QueueItem__int__class___QueueItem__class___QueueItem__void_2822974562 : class : QueueItem->int->class : QueueItem->class : QueueItem->void
(13,9) -> function FUNCTION__13_9_____function_GetData___class___QueueItem__int_2286976800 : class : QueueItem->int
(16,21) -> function FUNCTION__16_21_____function_GetNext___class___QueueItem__class___QueueItem_2813152152 : class : QueueItem->class : QueueItem
(19,21) -> function FUNCTION__19_21_____function_GetPrev___class___QueueItem__class___QueueItem_1726327475 : class : QueueItem->class : QueueItem
(22,10) -> function FUNCTION__22_10_____function_SetNext___class___QueueItem__class___QueueItem__void_622012255 : class : QueueItem->class : QueueItem->void
(25,10) -> function FUNCTION__25_10_____function_SetPrev___class___QueueItem__class___QueueItem__void_899906043 : class : QueueItem->class : QueueItem->void
FORMAL SCOPE OF 'Init':
(6,10) -> variable @this : class : QueueItem
(6,19) -> variable @data : int
(6,41) -> variable @next : class : QueueItem
(6,63) -> variable @prev : class : QueueItem
LOCAL SCOPE:
FORMAL SCOPE OF 'GetData':
(13,9) -> variable @this : class : QueueItem
LOCAL SCOPE:
FORMAL SCOPE OF 'GetNext':
(16,21) -> variable @this : class : QueueItem
LOCAL SCOPE:
FORMAL SCOPE OF 'GetPrev':
(19,21) -> variable @this : class : QueueItem
LOCAL SCOPE:
FORMAL SCOPE OF 'SetNext':
(22,10) -> variable @this : class : QueueItem
(22,34) -> variable @n : class : QueueItem
LOCAL SCOPE:
FORMAL SCOPE OF 'SetPrev':
(25,10) -> variable @this : class : QueueItem
(25,34) -> variable @p : class : QueueItem
LOCAL SCOPE:
CLASS SCOPE OF 'Queue':
(31,9) -> variable sp : int
(32,21) -> variable head : class : QueueItem
(34,10) -> function FUNCTION__34_10_____function_Init___class___Queue__void_136010224 : class : Queue->void
(38,10) -> function FUNCTION__38_10_____function_EnQueue___class___Queue__int__void_1300458479 : class : Queue->int->void
(43,9) -> function FUNCTION__43_9_____function_DeQueue___class___Queue__int_972130132 : class : Queue->int
FORMAL SCOPE OF 'Init':
(34,10) -> variable @this : class : Queue
LOCAL SCOPE:
FORMAL SCOPE OF 'EnQueue':
(38,10) -> variable @this : class : Queue
(38,22) -> variable @i : int
LOCAL SCOPE:
(39,25) -> variable temp : class : QueueItem
FORMAL SCOPE OF 'DeQueue':
(43,9) -> variable @this : class : Queue
LOCAL SCOPE:
(44,13) -> variable val : int
CLASS SCOPE OF 'Main':
(60,17) -> static function FUNCTION__60_17_____static_function_main___void_1800394802 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
(61,21) -> variable q : class : Queue
(62,13) -> variable i : int
*** Error at (5,9): can not reference a non-static field 'a' from static method 'main'
*** Error at (6,9): can not use this in static function
*** Error at (7,14): cannot access field 'a' from 'class : Main'
*** Error at (8,9): can not reference a non-static field 'func' from static method 'main'
*** Error at (12,20): field 'b' of 'class : Test' not accessible here
GLOBAL SCOPE:
(1,1) -> class Stack
(38,1) -> class Main
CLASS SCOPE OF 'Stack':
(2,9) -> variable sp : int
(3,11) -> variable elems : int[]
(5,10) -> function FUNCTION__5_10_____function_Init___class___Stack__void_1289757840 : class : Stack->void
(11,10) -> function FUNCTION__11_10_____function_Push___class___Stack__int__void_791113271 : class : Stack->int->void
(16,9) -> function FUNCTION__16_9_____function_Pop___class___Stack__int_1485412261 : class : Stack->int
(23,9) -> function FUNCTION__23_9_____function_NumElems___class___Stack__int_3682387132 : class : Stack->int
(27,17) -> static function FUNCTION__27_17_____static_function_main___void_1504488932 : void
FORMAL SCOPE OF 'Init':
(5,10) -> variable @this : class : Stack
LOCAL SCOPE:
FORMAL SCOPE OF 'Push':
(11,10) -> variable @this : class : Stack
(11,19) -> variable @i : int
LOCAL SCOPE:
FORMAL SCOPE OF 'Pop':
(16,9) -> variable @this : class : Stack
LOCAL SCOPE:
(17,13) -> variable val : int
FORMAL SCOPE OF 'NumElems':
(23,9) -> variable @this : class : Stack
LOCAL SCOPE:
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
(28,21) -> variable s : class : Stack
CLASS SCOPE OF 'Main':
(39,14) -> static function FUNCTION__39_14_____static_function_main___void_992693564 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
GLOBAL SCOPE:
(1,1) -> class Main
CLASS SCOPE OF 'Main':
(2,17) -> static function FUNCTION__2_17_____static_function_main___void_735708800 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
GLOBAL SCOPE:
(2,1) -> class Main
CLASS SCOPE OF 'Main':
(3,17) -> static function FUNCTION__3_17_____static_function_main___void_3198865941 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
(4,13) -> variable a : int
(5,16) -> variable b : string
(6,14) -> variable c : bool
GLOBAL SCOPE:
(1,1) -> class Main
CLASS SCOPE OF 'Main':
(2,17) -> static function FUNCTION__2_17_____static_function_main___void_735708800 : void
(12,16) -> static function FUNCTION__12_16_____static_function_test___int__int__int_1034013768 : int->int->int
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
(3,13) -> variable c : int
(4,16) -> variable s : string
FORMAL SCOPE OF 'test':
(12,25) -> variable @a : int
(12,32) -> variable @b : int
LOCAL SCOPE:
GLOBAL SCOPE:
(1,1) -> class Main
CLASS SCOPE OF 'Main':
(3,9) -> variable a : int
(4,14) -> variable b : string[]
(6,11) -> function FUNCTION__6_11_____function_tester___class___Main__int__int___2665879850 : class : Main->int->int[]
(11,10) -> function FUNCTION__11_10_____function_start___class___Main__void_3271319471 : class : Main->void
(28,17) -> static function FUNCTION__28_17_____static_function_main___void_1975271331 : void
FORMAL SCOPE OF 'tester':
(6,11) -> variable @this : class : Main
(6,22) -> variable @d : int
LOCAL SCOPE:
FORMAL SCOPE OF 'start':
(11,10) -> variable @this : class : Main
LOCAL SCOPE:
(12,13) -> variable a : int
(13,14) -> variable b : bool
(14,15) -> variable d : int[]
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
GLOBAL SCOPE:
(1,1) -> class Cow
(15,1) -> class Main
CLASS SCOPE OF 'Cow':
(2,9) -> variable height : int
(3,9) -> variable weight : int
(5,10) -> function FUNCTION__5_10_____function_Init___class___Cow__int__int__void_737927996 : class : Cow->int->int->void
(10,10) -> function FUNCTION__10_10_____function_Moo___class___Cow__void_2409883364 : class : Cow->void
FORMAL SCOPE OF 'Init':
(5,10) -> variable @this : class : Cow
(5,19) -> variable @w : int
(5,26) -> variable @h : int
LOCAL SCOPE:
FORMAL SCOPE OF 'Moo':
(10,10) -> variable @this : class : Cow
LOCAL SCOPE:
CLASS SCOPE OF 'Main':
(16,17) -> static function FUNCTION__16_17_____static_function_main___void_2528986641 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
(17,19) -> variable betsy : class : Cow
GLOBAL SCOPE:
(1,1) -> class Main
CLASS SCOPE OF 'Main':
(3,16) -> static function FUNCTION__3_16_____static_function_Binky___int__int____int____int_4188721883 : int->int[]->int[]->int
(7,17) -> static function FUNCTION__7_17_____static_function_main___void_2264566402 : void
FORMAL SCOPE OF 'Binky':
(3,26) -> variable @a : int
(3,35) -> variable @b : int[]
(3,44) -> variable @c : int[]
LOCAL SCOPE:
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
(8,15) -> variable c : int[]
(9,17) -> variable d : int[][]
GLOBAL SCOPE:
(1,1) -> class Computer
(10,1) -> class Mac : Computer
(17,1) -> class Main
CLASS SCOPE OF 'Computer':
(2,9) -> variable cpu : int
(3,10) -> function FUNCTION__3_10_____function_Crash___class___Computer__int__void_2869467784 : class : Computer->int->void
FORMAL SCOPE OF 'Crash':
(3,10) -> variable @this : class : Computer
(3,20) -> variable @numTimes : int
LOCAL SCOPE:
(4,13) -> variable i : int
CLASS SCOPE OF 'Mac':
(11,9) -> variable mouse : int
(12,10) -> function FUNCTION__12_10_____function_Crash___class___Mac__int__void_3285062364 : class : Mac->int->void
FORMAL SCOPE OF 'Crash':
(12,10) -> variable @this : class : Mac
(12,20) -> variable @numTimes : int
LOCAL SCOPE:
CLASS SCOPE OF 'Main':
(18,17) -> static function FUNCTION__18_17_____static_function_main___void_803012803 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
(19,19) -> variable powerbook : class : Mac
GLOBAL SCOPE:
(5,1) -> class Animal
(22,1) -> class Cow : Animal
(33,1) -> class Main
CLASS SCOPE OF 'Animal':
(6,9) -> variable height : int
(7,18) -> variable mother : class : Animal
(8,10) -> function FUNCTION__8_10_____function_InitAnimal___class___Animal__int__class___Animal__void_920603058 : class : Animal->int->class : Animal->void
(13,9) -> function FUNCTION__13_9_____function_GetHeight___class___Animal__int_1162800810 : class : Animal->int
(17,18) -> function FUNCTION__17_18_____function_GetMom___class___Animal__class___Animal_1184535072 : class : Animal->class : Animal
FORMAL SCOPE OF 'InitAnimal':
(8,10) -> variable @this : class : Animal
(8,25) -> variable @h : int
(8,41) -> variable @mom : class : Animal
LOCAL SCOPE:
FORMAL SCOPE OF 'GetHeight':
(13,9) -> variable @this : class : Animal
LOCAL SCOPE:
FORMAL SCOPE OF 'GetMom':
(17,18) -> variable @this : class : Animal
LOCAL SCOPE:
CLASS SCOPE OF 'Cow':
(23,10) -> variable isSpotted : bool
(24,10) -> function FUNCTION__24_10_____function_InitCow___class___Cow__int__class___Animal__bool__void_972390907 : class : Cow->int->class : Animal->bool->void
(28,10) -> function FUNCTION__28_10_____function_IsSpottedCow___class___Cow__bool_2222445457 : class : Cow->bool
FORMAL SCOPE OF 'InitCow':
(24,10) -> variable @this : class : Cow
(24,22) -> variable @h : int
(24,38) -> variable @m : class : Animal
(24,46) -> variable @spot : bool
LOCAL SCOPE:
FORMAL SCOPE OF 'IsSpottedCow':
(28,10) -> variable @this : class : Cow
LOCAL SCOPE:
CLASS SCOPE OF 'Main':
(34,17) -> static function FUNCTION__34_17_____static_function_main___void_3183264005 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
(35,19) -> variable betsy : class : Cow
(36,22) -> variable b : class : Animal
GLOBAL SCOPE:
(1,1) -> class Main
(7,1) -> class A : Main
CLASS SCOPE OF 'Main':
(2,9) -> variable a : int
(3,17) -> static function FUNCTION__3_17_____static_function_main___void_3198865941 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
CLASS SCOPE OF 'A':
(8,10) -> function FUNCTION__8_10_____function_func___class___A__void_1867549958 : class : A->void
FORMAL SCOPE OF 'func':
(8,10) -> variable @this : class : A
LOCAL SCOPE:
*** Error at (4,10): incompatible operands: string = int
*** Error at (8,5): incompatible operands: int = string
GLOBAL SCOPE:
(1,1) -> class Main
(40,1) -> class Base
(43,1) -> class Sub1 : Base
(46,1) -> class Sub2 : Base
(49,1) -> class Sub3 : Sub1
(52,1) -> class Sub4 : Sub3
CLASS SCOPE OF 'Main':
(2,17) -> static function FUNCTION__2_17_____static_function_main___void_735708800 : void
(25,17) -> static function FUNCTION__25_17_____static_function_printType___class___Base__void_2726434530 : class : Base->void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
(3,20) -> variable b : class : Base
(4,20) -> variable s1 : class : Sub1
(5,20) -> variable s2 : class : Sub2
(6,20) -> variable s3 : class : Sub3
(7,20) -> variable s4 : class : Sub4
FORMAL SCOPE OF 'printType':
(25,38) -> variable @base : class : Base
LOCAL SCOPE:
CLASS SCOPE OF 'Base':
CLASS SCOPE OF 'Sub1':
CLASS SCOPE OF 'Sub2':
CLASS SCOPE OF 'Sub3':
CLASS SCOPE OF 'Sub4':
*** Error at (3,8): field 'a' not found in 'class : Main'
GLOBAL SCOPE:
(3,1) -> class Main
(10,1) -> class NQueues
CLASS SCOPE OF 'Main':
(5,17) -> static function FUNCTION__5_17_____static_function_main___void_2003445225 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
CLASS SCOPE OF 'NQueues':
(11,9) -> variable N : int
(12,11) -> variable col : int[]
(13,11) -> variable row : int[]
(14,11) -> variable di1 : int[]
(15,11) -> variable di2 : int[]
(18,19) -> function FUNCTION__18_19_____function_init___class___NQueues__int__class___NQueues_3814191010 : class : NQueues->int->class : NQueues
(29,10) -> function FUNCTION__29_10_____function_solve___class___NQueues__void_4162186674 : class : NQueues->void
(34,11) -> function FUNCTION__34_11_____function_clearArray___class___NQueues__int____int___2458791393 : class : NQueues->int[]->int[]
(45,10) -> function FUNCTION__45_10_____function_printBoard___class___NQueues__int____int__void_3930325007 : class : NQueues->int[]->int->void
(65,10) -> function FUNCTION__65_10_____function_try___class___NQueues__int__int____int____int____int____void_1087009282 : class : NQueues->int->int[]->int[]->int[]->int[]->void
FORMAL SCOPE OF 'init':
(18,19) -> variable @this : class : NQueues
(18,28) -> variable @n : int
LOCAL SCOPE:
FORMAL SCOPE OF 'solve':
(29,10) -> variable @this : class : NQueues
LOCAL SCOPE:
FORMAL SCOPE OF 'clearArray':
(34,11) -> variable @this : class : NQueues
(34,28) -> variable @a : int[]
LOCAL SCOPE:
(35,13) -> variable i : int
FORMAL SCOPE OF 'printBoard':
(45,10) -> variable @this : class : NQueues
(45,27) -> variable @col : int[]
(45,36) -> variable @N : int
LOCAL SCOPE:
(46,13) -> variable i : int
FORMAL SCOPE OF 'try':
(65,10) -> variable @this : class : NQueues
(65,18) -> variable @c : int
(65,27) -> variable @row : int[]
(65,38) -> variable @col : int[]
(65,49) -> variable @diag1 : int[]
(65,62) -> variable @diag2 : int[]
LOCAL SCOPE:
(66,13) -> variable N : int
(67,13) -> variable r : int
*** Error at (22,13): can not use this in static function
*** Error at (7,9): can not reference a non-static field 'i' from static method 'main'
*** Error at (9,24): can not reference a non-static field 'i' from static method 'main'
*** Error at (13,24): can not reference a non-static field 'i' from static method 'main'
GLOBAL SCOPE:
(1,1) -> class MultipleFormals
(20,1) -> class Main
CLASS SCOPE OF 'MultipleFormals':
(3,9) -> function FUNCTION__3_9_____function_foo___class___MultipleFormals__int__int__int__int_1545538432 : class : MultipleFormals->int->int->int->int
(7,9) -> function FUNCTION__7_9_____function_method___class___MultipleFormals__int_2678803193 : class : MultipleFormals->int
FORMAL SCOPE OF 'foo':
(3,9) -> variable @this : class : MultipleFormals
(3,17) -> variable @x : int
(3,24) -> variable @y : int
(3,31) -> variable @z : int
LOCAL SCOPE:
FORMAL SCOPE OF 'method':
(7,9) -> variable @this : class : MultipleFormals
LOCAL SCOPE:
(8,13) -> variable x : int
(9,13) -> variable y : int
(10,13) -> variable z : int
CLASS SCOPE OF 'Main':
(21,14) -> static function FUNCTION__21_14_____static_function_main___void_3413895949 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
GLOBAL SCOPE:
(1,1) -> class Father
(13,1) -> class Child : Father
(25,1) -> class Main
CLASS SCOPE OF 'Father':
(2,9) -> variable field : int
(4,9) -> function FUNCTION__4_9_____function_method___class___Father__int__int_521466537 : class : Father->int->int
FORMAL SCOPE OF 'method':
(4,9) -> variable @this : class : Father
(4,20) -> variable @f : int
LOCAL SCOPE:
CLASS SCOPE OF 'Child':
(14,10) -> function FUNCTION__14_10_____function_start___class___Child__void_3524117785 : class : Child->void
FORMAL SCOPE OF 'start':
(14,10) -> variable @this : class : Child
LOCAL SCOPE:
(15,22) -> variable p : class : Father
CLASS SCOPE OF 'Main':
(26,14) -> static function FUNCTION__26_14_____static_function_main___void_2546714724 : void
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
*** Error at (9,9): undeclared variable 'c'
*** Error at (10,11): incompatible operands: bool = int
*** Error at (11,11): incompatible operands: string = bool
*** Error at (12,15): incompatible operands: int + string
*** Error at (13,15): incompatible operands: int - bool
*** Error at (14,9): undeclared variable 'c'
*** Error at (14,13): undeclared variable 'c'
*** Error at (15,15): incompatible operands: bool / bool
*** Error at (16,15): incompatible operands: int % bool
*** Error at (17,13): incompatible operand: ! int
*** Error at (18,15): incompatible operands: bool && int
*** Error at (19,18): undeclared variable 'c'
*** Error at (20,9): undeclared variable 'Main'
*** Error at (21,13): undeclared variable 'Main'
*** Error at (22,15): incompatible operands: int > bool
*** Error at (23,15): incompatible operands: int >= bool
*** Error at (24,15): incompatible operands: int < bool
*** Error at (25,15): incompatible operands: bool <= bool
*** Error at (26,15): incompatible operands: int != bool
*** Error at (27,15): incompatible operands: int == bool
*** Error at (28,16): test expression must have bool type
*** Error at (29,15): test expression must have bool type
GLOBAL SCOPE:
(1,1) -> class Main
CLASS SCOPE OF 'Main':
(2,6) -> variable x : int
(3,7) -> function FUNCTION__3_7_____function_set___class___Main__int__void_3638050410 : class : Main->int->void
(6,6) -> function FUNCTION__6_6_____function_get___class___Main__int_337688862 : class : Main->int
(11,14) -> static function FUNCTION__11_14_____static_function_main___void_2434454637 : void
FORMAL SCOPE OF 'set':
(3,7) -> variable @this : class : Main
(3,15) -> variable @x : int
LOCAL SCOPE:
FORMAL SCOPE OF 'get':
(6,6) -> variable @this : class : Main
LOCAL SCOPE:
(7,7) -> variable x : int
FORMAL SCOPE OF 'main':
LOCAL SCOPE:
(12,14) -> variable f : class : Main
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ts=4 sw=4 expandtab:
"""
此脚本自动测试当前目录下所有 *.decaf 程序,输出到 output 目录下,
并与 result 目录下的标准答案比较。
请注意我们在判分时会有更多的测试用例。
"""
import os
import subprocess
import sys
def read_txt_file(filename):
with open(filename,'r') as f:
txt = f.read().strip()
# Python should be able to do it automatically, but just in case...
txt = txt.replace('\r','')
return txt
def main():
decaf_jar = os.path.join('..', '..', 'result', 'decaf.jar')
# in case output dir not exists
try:
if not os.path.isdir('output'):
os.makedirs('output')
except:
os.makedirs('output', exist_ok=True)
names = sys.argv[1:]
if not names:
names = sorted(os.listdir('.'))
for name in names:
bname,ext = os.path.splitext(name)
if ext != '.decaf':
continue
# Run the test case, redirecting stdout/stderr to output/bname.result
subprocess.call(['java', '-jar', decaf_jar, '-l', '1', name],
stdout=open(os.path.join('output', bname + '.result'), 'w'),
stderr=subprocess.STDOUT)
# Check the result
expected = read_txt_file(os.path.join('result',bname+'.result'))
actual = read_txt_file(os.path.join('output',bname+'.result'))
if expected == actual:
info = 'OK :)'
else:
info = 'ERROR!'
print('{0:<60}{1}'.format(name,info))
if os.name == 'nt':
print('Press Enter to continue...')
try:
raw_input() # Python 2
except:
input() # Python 3
if __name__ == '__main__':
main()
class Stack {
int sp;
int[] elems;
void Init() {
elems = new int[100];
sp = 0;
Push(3);
}
void Push(int i) {
elems[sp] = i;
sp = sp + 1;
}
int Pop() {
int val;
val = elems[sp - 1];
sp = sp - 1;
return val;
}
int NumElems() {
return sp;
}
static void main() {
class Stack s;
s = new Stack();
s.Init();
s.Push(3);
s.Push(7);
s.Push(4);
Print(s.NumElems(), " ", s.Pop(), " ", s.Pop(), " ", s.Pop(), " ", s.NumElems());
}
}
class Main {
static void main() {
Stack.main();
}
}
class Main {
static void main() {
Print("hello world");
}
}
class Main {
static void main() {
int a;
string b;
bool c;
c = true;
b = "wow!";
a = 3;
if (c)
a = a * 5;
Print(c, " ", a);
}
}
class Main {
static void main() {
int c;
string s;
s = "hello";
c = test(4, 5);
Print(c);
Print(s);
}
static int test(int a, int b) {
return a + b;
}
}
\ No newline at end of file
class Main {
int a;
string[] b;
int[] tester(int d) {
b = new string[1];
return new int[d];
}
void start() {
int a;
bool b;
int[] d;
a = 1;
while (a < 5) {
int[] array;
if (a % 2 == 0) {
d = tester(a);
break;
}
Print("Loop ", a, "\n");
a = a + 1;
}
d[0] = 0;
Print(d[d[0]], "\n", d.length(), "\n");
}
static void main() {
new Main().start();
}
}
class Cow {
int height;
int weight;
void Init(int w, int h) {
weight = w;
height = h;
}
void Moo() {
Print ( this.height, " ", this.weight, "\n" );
}
}
class Main {
static void main() {
class Cow betsy;
betsy = new Cow();
betsy.Init(100, 122);
betsy.Moo();
}
}
class Main {
static int Binky(int a, int[] b, int[] c) {
return b[c[0]];
}
static void main() {
int[] c;
int [][]d;
d = new int[][5];
d[0] = new int[12];
c = new int[10];
c[0] = 4 + 5 * 3 / 4 % 2;
d[0][c[0]] = 55;
Print(c[0], " ", 2 * Binky(100, d[0], c));
}
}
class Computer {
int cpu;
void Crash(int numTimes) {
int i;
for (i = 0; i < numTimes; i = i + 1)
Print("sad\n");
}
}
class Mac extends Computer {
int mouse;
void Crash(int numTimes) {
Print("ack!");
}
}
class Main {
static void main() {
class Mac powerbook;
powerbook = new Mac();
powerbook.Crash(2);
}
}
//
// Classes with inheritance
//
class Animal {
int height;
class Animal mother;
void InitAnimal(int h, class Animal mom) {
this.height = h;
mother = mom;
}
int GetHeight() {
return height;
}
class Animal GetMom() {
return this.mother;
}
}
class Cow extends Animal {
bool isSpotted;
void InitCow(int h, class Animal m, bool spot) {
isSpotted = spot;
InitAnimal(h,m);
}
bool IsSpottedCow () {
return isSpotted;
}
}
class Main {
static void main() {
class Cow betsy;
class Animal b;
betsy = new Cow();
betsy.InitCow(5, null, true);
b = betsy;
b.GetMom();
Print(instanceof(b, Cow));
betsy = (class Cow)b;
Print("spots: ",betsy.IsSpottedCow(), " height: ", b.GetHeight());
}
}
class Main {
int a;
static void main() {
}
}
class A extends Main {
void func() {
a = new Main().a; // no error
}
}
\ No newline at end of file
class Main {
string x;
void set(int x) {
this.x = x;
}
int get() {
int x;
x = this.x;
return x;
}
static void main() {
class Main f;
f = new Main();
f.set(5);
f.set(f.get()+f.get());
}
}
class Main {
static void main() {
class Base b;
class Sub1 s1;
class Sub2 s2;
class Sub3 s3;
class Sub4 s4;
b = new Base();
s1 = new Sub1();
s2 = new Sub2();
s3 = new Sub3();
s4 = new Sub4();
printType(b);
printType(s1);
printType(s2);
printType(s3);
printType(s4);
b = s4;
printType(b);
s1 = (class Sub1)b;
printType(s1);
}
static void printType(class Base base) {
if (instanceof(base, Sub4)) {
Print("Sub4\n");
} else if (instanceof(base, Sub3)) {
Print("Sub3\n");
} else if (instanceof(base, Sub2)) {
Print("Sub2\n");
} else if (instanceof(base, Sub1)) {
Print("Sub1\n");
} else if (instanceof(base, Base)) {
Print("Base\n");
}
}
}
class Base {
}
class Sub1 extends Base {
}
class Sub2 extends Base {
}
class Sub3 extends Sub1 {
}
class Sub4 extends Sub3 {
}
\ No newline at end of file
class Main {
void foo() {
this.a = "Hello world";
}
static void main() {
}
}
// a program to solve the N-queens problem (from Cornell CS412 website)
class Main {
static void main() {
new NQueues().init(8).solve();
}
}
class NQueues {
int N;
int[] col;
int[] row;
int[] di1;
int[] di2;
class NQueues init(int n) {
N = n;
col = clearArray(new int[N]);
row = clearArray(new int[N]);
di1 = clearArray(new int[N]);
di2 = clearArray(new int[N]);
return this;
}
void solve() {
try(0, col, row, di1, di2);
}
int[] clearArray(int[] a) {
int i;
i = a.length() - 1;
while (i >= 0) {
a[i] = 0;
}
return a;
}
void printBoard(int[] col, int N) {
int i;
i = 0;
while (i < N) {
int j;
j = 0;
while (j < N) {
if (col[i] == j) {
Print(1);
} else {
Print(0);
}
}
Print("\n");
i = i + 1;
}
}
void try(int c, int[] row, int[] col, int[] diag1, int[] diag2) {
int N;
int r;
N = col.length();
r = 0;
if (c == N) {
printBoard(col, N);
} else {
while (r < N) {
if (row[r] == 0 && diag1[r+c] == 0 && diag2[r+(N-1)-c] == 0) {
row[r] = 1;
diag1[r+c] = 1;
diag2[r+(N-1)-c] = 1;
col[c] = r;
try(c+1, row, col, diag1, diag2);
row[r] = 0;
diag1[r+c] = 0;
diag2[r+(N-1)-c] = 0;
}
r = r + 1;
}
}
}
}
class Main {
bool field;
class Main another;
int[] foo(int y) {
int[] q;
int i;
q = new int[y];
i = 0;
while (i < y) {
q[i] = i;
i = i + 1;
}
return q;
}
static void main() {
int l;
l = this.foo(5).length();
}
}
class Main {
int i;
static void main() {
class Hoo h;
i = 4;
h = new Goo();
h.printNumbers(i);
Print(instanceof(h, Goo));
class Goo g;
g = (class Goo)h;
g.printNumbers(i);
}
}
class Hoo {
int printNumbers(int n) {
int i;
if (10 < n) {
n = 10;
}
i = 0;
while (i < n) {
Print(i);
i = i * 2;
}
Print("\n");
return i;
}
}
class Goo extends Hoo {
int printNumbers(int n) {
Print(n);
return 1;
}
}
\ No newline at end of file
class MultipleFormals {
int foo(int x, int y, int z) {
return (x + y + z)/3;
}
int method() {
int x;
int y;
int z;
x = 3;
y = x + x * x;
z = (x - y / x) % y;
return foo(x, y, z);
}
}
class Main {
static void main () {
}
}
class Father {
int field;
int method(int f) {
if (f > 0 && f < 10) {
f = f - 3;
return method(f);
}
return f;
}
}
class Child extends Father {
void start() {
class Father p;
p = this;
p.field = 5;
p = null;
Print(this.field);
}
}
class Main {
static void main() {
}
}
class Main {
static void main() {
int a;
int b;
bool d;
string s;
a = 1;
b = 2;
c = 1;
d = 1;
s = d;
a = b + s;
b = a - d;
c = c * d;
d = d / d;
a = a % d;
d = !a;
d = d && b;
d = d || c;
Main = 1;
a = Main + 1;
d = a > d;
d = a >= d;
d = b < d;
d = d <= d;
d = a != d;
d = b == d;
while (a);
for (;b;);
}
}
class Main {
int x;
void set(int x) {
this.x = x;
}
int get() {
int x;
x = this.x;
return x;
}
static void main() {
class Main f;
f = new Main();
f.set(5);
f.set(f.get()+f.get());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment