Fixes to tester for multiple file support.

This commit is contained in:
Christoffer Lerno
2020-07-27 10:30:15 +02:00
committed by Christoffer Lerno
parent 7b7abf5d4a
commit a533cbb1a7
10 changed files with 178 additions and 43 deletions

View File

@@ -0,0 +1,7 @@
module baz;
import bar;
public func void runBar()
{
bar::notVisible(); // #error: 'notVisible' is not visible from this module.
}

View File

@@ -0,0 +1,6 @@
module bar;
func void notVisible()
{
}

View File

@@ -145,31 +145,6 @@ union SimpleUnion
double f;
}
struct ExtraSimple
{
int a;
int b;
struct c
{
double e;
double f0;
double f1;
double f;
double j;
}
struct
{
int r;
int s;
}
union
{
double o0;
int o1;
}
int g;
}
func void testIf()
{
@@ -200,12 +175,7 @@ func void testIf()
}
}
func void testSimple()
{
ExtraSimple a = { c.j = 3.3 };
a.c.j = 3.4;
printf("a = %d, c.e = %f, c.f = %f, c.j = %f, g = %d, o0 = %f, r = %d, s = %d\n", a.a, a.c.e, a.c.f, a.c.j, a.g, a.o0, a.r, a.s);
}
func void testPointer()
{
int i = 0;
@@ -1407,7 +1377,6 @@ func int main(int x)
show();
testMacros();
testTypeof();
testSimple();
testAllErrors();
//testErrorBug();
//testErrors();

View File

@@ -59,7 +59,7 @@ static Decl *sema_resolve_path_symbol(Context *context, const char *symbol, Path
{
if (!path_found)
{
SEMA_ERROR(path, "Unknown module %.*s.", path->len, path->module);
SEMA_ERROR(path, "Unknown module '%.*s', did you forget to import it?", path->len, path->module);
return poisoned_decl;
}
return NULL;

View File

@@ -18,8 +18,9 @@ class File:
self.filename = os.path.basename(filepath)
class TargetFile:
def __init__(self, filepath, is_target):
def __init__(self, filepath, is_target, line_offset):
self.is_target = is_target
self.line_offset = line_offset
if is_target:
self.file = open(filepath, mode="w")
else:
@@ -110,7 +111,7 @@ class Issues:
def parse_single(self):
self.current_file = TargetFile(TEST_DIR + self.sourcefile.filename, True)
self.current_file = TargetFile(TEST_DIR + self.sourcefile.filename, True, 1)
lines = len(self.sourcefile.content)
while self.line < lines:
line = self.sourcefile.content[self.line].strip()
@@ -132,14 +133,14 @@ class Issues:
if self.current_file:
self.current_file.close()
line = line[5:].strip()
self.current_file = TargetFile(TEST_DIR + line, True)
self.current_file = TargetFile(TEST_DIR + line, True, -self.line)
self.files.append(self.current_file)
return
elif (line.startswith("expect:")):
line = line[7:].strip()
if self.current_file:
self.current_file.close()
self.current_file = TargetFile(TEST_DIR + line, False)
self.current_file = TargetFile(TEST_DIR + line, False, 0)
self.files.append(self.current_file)
return
else:
@@ -152,7 +153,7 @@ class Issues:
exit(-1)
elif (line.startswith("error:")):
line = line[6:].strip()
self.errors[self.current_file.filename + ":%d" % (self.line + 1)] = line
self.errors[self.current_file.filename + ":%d" % (self.line + self.current_file.line_offset)] = line
else:
self.exit_error("unknown trailing directive " + line)
@@ -162,13 +163,14 @@ class Issues:
line = self.sourcefile.content[self.line].strip()
if line.startswith("// #"):
self.parse_header_directive(line)
self.line += 1
continue
elif "// #" in line:
self.parse_trailing_directive(line)
else:
if not self.current_file:
self.current_file = TargetFile(TEST_DIR + self.sourcefile.filename[:-4] + ".c3", True)
self.files.append(self.current_file)
self.current_file.write(self.sourcefile.content[self.line])
if not self.current_file:
self.current_file = TargetFile(TEST_DIR + self.sourcefile.filename[:-4] + ".c3", True, 1)
self.files.append(self.current_file)
self.current_file.write(self.sourcefile.content[self.line])
self.line += 1
if self.current_file:

View File

@@ -0,0 +1,81 @@
extern func void printf(char* c, ...);
struct ExtraSimple
{
int a;
int b;
struct c
{
double e;
double f0;
double f1;
double f;
double j;
}
struct
{
int r;
int s;
}
union
{
double o0;
int o1;
}
int g;
}
func void testSimple()
{
ExtraSimple a = { c.j = 3.3 };
a.c.j = 3.4;
printf("a = %d, c.e = %f, c.f = %f, c.j = %f, g = %d, o0 = %f, r = %d, s = %d\n", a.a, a.c.e, a.c.f, a.c.j, a.g, a.o0, a.r, a.s);
}
// #expect: pointer_access.ll
%pointer_access.ExtraSimple = type { i32, i32, %pointer_access.c, %pointer_access.anon, %pointer_access.anon.0, i32 }
%pointer_access.c = type { double, double, double, double, double }
%pointer_access.anon = type { i32, i32 }
%pointer_access.anon.0 = type { double }
@ExtraSimple = linkonce_odr constant i8 1
entry:
%a = alloca %pointer_access.ExtraSimple
%0 = bitcast %pointer_access.ExtraSimple* %a to i8*
call void @llvm.memset.p0i8.i64(i8* align 8 %0, i8 0, i64 72, i1 false)
%c = getelementptr inbounds %pointer_access.ExtraSimple, %pointer_access.ExtraSimple* %a, i32 0, i32 2
%double = getelementptr inbounds %pointer_access.c, %pointer_access.c* %c, i32 0, i32 4
store double 3.300000e+00, double* %double
%1 = load %pointer_access.ExtraSimple, %pointer_access.ExtraSimple* %a
%c1 = getelementptr inbounds %pointer_access.ExtraSimple, %pointer_access.ExtraSimple* %a, i32 0, i32 2
%j = getelementptr inbounds %pointer_access.c, %pointer_access.c* %c1, i32 0, i32 4
store double 3.400000e+00, double* %j
%a2 = getelementptr inbounds %pointer_access.ExtraSimple, %pointer_access.ExtraSimple* %a, i32 0, i32 0
%2 = load i32, i32* %a2
%c3 = getelementptr inbounds %pointer_access.ExtraSimple, %pointer_access.ExtraSimple* %a, i32 0, i32 2
%e = getelementptr inbounds %pointer_access.c, %pointer_access.c* %c3, i32 0, i32 0
%3 = load double, double* %e
%c4 = getelementptr inbounds %pointer_access.ExtraSimple, %pointer_access.ExtraSimple* %a, i32 0, i32 2
%f = getelementptr inbounds %pointer_access.c, %pointer_access.c* %c4, i32 0, i32 3
%4 = load double, double* %f
%c5 = getelementptr inbounds %pointer_access.ExtraSimple, %pointer_access.ExtraSimple* %a, i32 0, i32 2
%j6 = getelementptr inbounds %pointer_access.c, %pointer_access.c* %c5, i32 0, i32 4
%5 = load double, double* %j6
%g = getelementptr inbounds %pointer_access.ExtraSimple, %pointer_access.ExtraSimple* %a, i32 0, i32 5
%6 = load i32, i32* %g
%anon = getelementptr inbounds %pointer_access.ExtraSimple, %pointer_access.ExtraSimple* %a, i32 0, i32 4
%o0 = bitcast %pointer_access.anon.0* %anon to double*
%7 = load double, double* %o0
%anon7 = getelementptr inbounds %pointer_access.ExtraSimple, %pointer_access.ExtraSimple* %a, i32 0, i32 3
%r = getelementptr inbounds %pointer_access.anon, %pointer_access.anon* %anon7, i32 0, i32 0
%8 = load i32, i32* %r
%anon8 = getelementptr inbounds %pointer_access.ExtraSimple, %pointer_access.ExtraSimple* %a, i32 0, i32 3
%s = getelementptr inbounds %pointer_access.anon, %pointer_access.anon* %anon8, i32 0, i32 1
%9 = load i32, i32* %s
call void (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @0, i32 0, i32 0), i32 %2, double %3, double %4, double %5, i32 %6, double %7, i32 %8, i32 %9)
ret void
}

View File

@@ -0,0 +1,23 @@
// #file: file1.c3
module baz;
public func void runBar()
{
visible();
bar::barFunc(); // #error: Unknown module 'bar'
}
// #file: file2.c3
module baz;
import bar;
func void visible()
{
bar::barFunc();
}
// #file: file3.c3
module bar;
public func void barFunc()
{}

View File

@@ -0,0 +1,16 @@
// #file: file1.c3
module baz;
import bar;
public func void runBar()
{
bar::notVisible(); // #error: 'notVisible' is not visible from this module.
}
// #file: file2.c3
module bar;
func void notVisible()
{
}

View File

@@ -0,0 +1,15 @@
// #file: file1.c3
module baz;
public func void runBar()
{
visible();
}
// #file: file2.c3
module baz;
func void visible()
{
}

View File

@@ -0,0 +1,16 @@
// #file: file1.c3
module baz;
import bar;
public func void runBar()
{
bar::visible();
}
// #file: file2.c3
module bar;
public func void visible()
{
}