Started the preprocessor situation *sigh*; fixed an issue with how I was handling UNC paths

master
Allen Webster 2018-06-10 14:35:28 -07:00
parent ed625f4e09
commit 6b7d09b9d5
9 changed files with 432 additions and 27 deletions

View File

@ -0,0 +1,11 @@
/*
4coder_cpp_preprocessor.cpp - An unoptimized non-in-place preprocessor.
*/
// TOP
// BOTTOM

16
4coder_cpp_preprocessor.h Normal file
View File

@ -0,0 +1,16 @@
/*
4coder_cpp_preprocessor.h - An unoptimized non-in-place preprocessor.
*/
// TOP
#if !defined(FCODER_CPP_PREPROCESSOR_H)
#define FCODER_CPP_PREPROCESSOR_H
#endif
// BOTTOM

View File

@ -119,6 +119,20 @@ Sys_Memory_Free_Sig(system_memory_free){
// Files
//
internal String
win32_remove_unc_prefix_characters(String path){
if (match_part(path, make_lit_string("\\\\?\\UNC"))){
path.size -= 6;
memmove(path.str, path.str + 6, path.size);
path.str[0] = '\\';
}
else if (match_part(path, make_lit_string("\\\\?\\"))){
path.size -= 4;
memmove(path.str, path.str + 4, path.size);
}
return(path);
}
internal
Sys_Set_File_List_Sig(system_set_file_list){
b32 clear_list = true;
@ -134,12 +148,19 @@ Sys_Set_File_List_Sig(system_set_file_list){
DWORD final_length = GetFinalPathNameByHandle_utf8(dir_handle, (u8*)dir_space, sizeof(dir_space), 0);
CloseHandle(dir_handle);
if (final_length + 2 < sizeof(dir_space)){
if (final_length + 3 < sizeof(dir_space)){
u8 *c_str_dir = (u8*)dir_space;
if (c_str_dir[final_length - 1] == 0){
--final_length;
}
String str_dir = make_string(c_str_dir, final_length);
String adjusted_str_dir = win32_remove_unc_prefix_characters(str_dir);
c_str_dir = (u8*)adjusted_str_dir.str;
final_length = adjusted_str_dir.size;
c_str_dir[final_length] = '\\';
c_str_dir[final_length+1] = '*';
c_str_dir[final_length+2] = 0;
c_str_dir[final_length + 1] = '*';
c_str_dir[final_length + 2] = 0;
if (canon_directory_out != 0){
if (final_length+1 < canon_directory_max){
@ -264,12 +285,14 @@ Sys_Get_Canonical_Sig(system_get_canonical){
if (file != INVALID_HANDLE_VALUE){
DWORD final_length = GetFinalPathNameByHandle_utf8(file, (u8*)buffer, max, 0);
if (final_length < max && final_length >= 4){
if (final_length + 3 < max){
if (buffer[final_length - 1] == 0){
--final_length;
}
//final_length -= 4;
//memmove(buffer, buffer+4, final_length);
String str_dir = make_string(buffer, final_length);
String adjusted_str_dir = win32_remove_unc_prefix_characters(str_dir);
buffer = adjusted_str_dir.str;
final_length = adjusted_str_dir.size;
buffer[final_length] = 0;
result = final_length;
}
@ -289,12 +312,14 @@ Sys_Get_Canonical_Sig(system_get_canonical){
if (dir != INVALID_HANDLE_VALUE){
DWORD final_length = GetFinalPathNameByHandle_utf8(dir, (u8*)buffer, max, 0);
if (final_length < max && final_length >= 4){
if (final_length + 3 < max){
if (buffer[final_length-1] == 0){
--final_length;
}
final_length -= 4;
memmove(buffer, buffer+4, final_length);
String str_dir = make_string(buffer, final_length);
String adjusted_str_dir = win32_remove_unc_prefix_characters(str_dir);
buffer = adjusted_str_dir.str;
final_length = adjusted_str_dir.size;
buffer[final_length++] = '\\';
memcpy(buffer + final_length, front_str.str, front_str.size);
final_length += front_str.size;

View File

@ -32,14 +32,14 @@ command_list = {
{"echo build: x64 & ./build.sh", .os = "mac" }, }, },
{ .name = "build site",
.out = "*site*", .footer_panel = false, .save_dirty_files = true,
.cmd = { {"build_site.bat", .os = "win" },
{"./build_site.sh" , .os = "linux"},
{"./build_site.sh" , .os = "mac" }, }, },
.cmd = { {"build_site.bat" , .os = "win" },
{"./build_site.sh", .os = "linux"},
{"./build_site.sh", .os = "mac" }, }, },
{ .name = "build string",
.out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { {"build_string.bat", .os = "win" },
{"./build_string.sh" , .os = "linux"},
{"./build_string.sh" , .os = "mac" }, }, },
.cmd = { {"build_string.bat" , .os = "win" },
{"./build_string.sh", .os = "linux"},
{"./build_string.sh", .os = "mac" }, }, },
{ .name = "build x86",
.out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { {build_x86_win32, .os = "win" },
@ -47,24 +47,32 @@ command_list = {
{build_x86_mac , .os = "mac" }, }, },
{ .name = "build metadata",
.out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { {"build_metadata.bat", .os = "win" },
{"./build_metadata.sh" , .os = "linux"},
{"./build_metadata.sh" , .os = "mac" }, }, },
.cmd = { {"build_metadata.bat" , .os = "win" },
{"./build_metadata.sh", .os = "linux"},
{"./build_metadata.sh", .os = "mac" }, }, },
{ .name = "package",
.out = "*package*", .footer_panel = false, .save_dirty_files = true,
.cmd = { {"package.bat", .os = "win" },
{"./package.sh" , .os = "linux"},
{"./package.sh" , .os = "mac" }, }, },
.cmd = { {"package.bat" , .os = "win" },
{"./package.sh", .os = "linux"},
{"./package.sh", .os = "mac" }, }, },
{ .name = "build config parser generator",
.out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { {"build_config_parser_generator.bat", .os = "win" },
{"./build_config_parser_generator.sh" , .os = "linux"},
{"./build_config_parser_generator.sh" , .os = "mac" }, }, },
.cmd = { {"build_config_parser_generator.bat" , .os = "win" },
{"./build_config_parser_generator.sh", .os = "linux"},
{"./build_config_parser_generator.sh", .os = "mac" }, }, },
{ .name = "generate config parser",
.out = "*gen*", .footer_panel = false, .save_dirty_files = true,
.cmd = { {"..\\build\\generate_config_parser", .os = "win" },
{"../build/generate_config_parser", .os = "linux"},
{"../build/generate_config_parser", .os = "mac" }, }, },
{"../build/generate_config_parser" , .os = "linux"},
{"../build/generate_config_parser" , .os = "mac" }, }, },
{ .name = "build cpp preproc test",
.out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { {"pushd test_preproc & build.bat", .os = "win"},
}, },
{ .name = "run cpp preproc test",
.out = "*run*", .footer_panel = false, .save_dirty_files = true,
.cmd = { {"pushd test_preproc & ..\\..\\build\\test_preproc test_1_src.cpp test_1_res.i", .os = "win"},
}, },
};
fkey_command[1] = "build x64";
@ -76,3 +84,5 @@ fkey_command[6] = "build config parser generator";
fkey_command[7] = "generate config parser";
fkey_command[12] = "package";
//fkey_command[1] = "build cpp preproc test";
//fkey_command[2] = "run cpp preproc test";

View File

@ -1,5 +1,5 @@
1
0
115
116

7
test_preproc/build.bat Normal file
View File

@ -0,0 +1,7 @@
@echo off
set opts=-FC -GR- -EHa- -nologo -Zi
set code=%cd%
pushd ..\..\build
cl %opts% %code%\test_preproc_main.cpp -Fetest_preproc
popd

139
test_preproc/test_1_res.i Normal file
View File

@ -0,0 +1,139 @@
#line 1 "test_1_src.cpp"
0;
1;
#line 26 "test_1_src.cpp"
2;
#line 30 "test_1_src.cpp"
3;
#line 49 "test_1_src.cpp"
#line 59 "test_1_src.cpp"
4;
#line 63 "test_1_src.cpp"
(5 + (0));
(5 + (4));
(5 + ((5 + (4))));
(((4 + (0))) + ((4 + (1))) + ((4 + (2))));
(baz(4, 4, 4, 4));
FOO;
BAR;
FOO(0) + 20;
(a) + 2*(b) + (c)/2 +(d) + 2*(e) + (f)/2 +(g) + 2*(h) + (i)/2 +(j) + 2*(k) + (l)/2 +(m) + 2*(n) + (o)/2 +(p) + 2*(q) + (r)/2 +(s) + 2*(t) + (u)/2 + 0;
#line 138 "test_1_src.cpp"

138
test_preproc/test_1_src.cpp Normal file
View File

@ -0,0 +1,138 @@
// F0
#if !defined(FOO)
#define FOO 0
FOO;
// F1
#undef FOO
#define FOO 1
FOO;
// F2
#undef FOO
#define FOO 2
#if !defined(FOO)
2;
#else
FOO;
#endif
// F3
#undef FOO
#define BAR 3
#ifdef FOO
FOO;
#elif defined(BAR)
BAR;
#else
3;
#endif
// F4
#define FOO 4
#if FOO < BAR
BAR;
#else
FOO;
#endif
// F5
#undef BAR
#define BAR(a) (5 + (a))
BAR(0);
// F9
BAR(FOO);
// F14
BAR(BAR(FOO));
// F15
#undef BAR
#define BAR(a,b,c) ((a) + (b) + (c))
#undef FOO
#define FOO(n) (4 + (n))
BAR(FOO(0), FOO(1), FOO(2));
// F16
#undef BAR
#define BAR(a,...) (a(__VA_ARGS__))
BAR(baz, 4, 4, 4, 4);
// F17
#undef FOO
#define FOO FOO
FOO;
// F18
#undef FOO
#define FOO BAR
#undef BAR
#define BAR FOO
BAR;
// F20
#undef FOO
#define FOO(a) FOO(a) + 20
FOO(0);
// L1
#undef FOO
#define FOO(x)\
x(a,b,c)\
x(d,e,f)\
x(g,h,i)\
x(j,k,l)\
x(m,n,o)\
x(p,q,r)\
x(s,t,u)
#undef BAR
#define BAR(x,y,z) (x) + 2*(y) + (z)/2 +
FOO(BAR) 0;
#endif

View File

@ -0,0 +1,59 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 10.06.2018
*
* Test bed for developing 4coder_cpp_preprocessor
*
*/
// TOP
#include "../4ed_defines.h"
#include "../meta/4ed_meta_defines.h"
#include "../4coder_file.h"
#include "../4coder_lib/4coder_mem.h"
#include "../4coder_lib/4cpp_lexer.h"
#include "../4coder_cpp_preprocessor.h"
#include "../4coder_cpp_preprocessor.cpp"
void
print_usage(void){
fprintf(stdout, "test_preproc src correct_result\n");
}
int main(int argc, char **argv){
if (argc != 3){
print_usage();
exit(1);
}
char *input_file_name = argv[1];
char *compare_file_name = argv[2];
i32 memory_size = MB(512);
void *memory = malloc(memory_size);
Partition part = make_part(memory, memory_size);
String text = file_dump(&part, input_file_name);
if (text.str != 0){
String compare_text = file_dump(&part, compare_file_name);
if (compare_text.str != 0){
if (text.size != compare_text.size ||
memcmp(text.str, compare_text.str, text.size) != 0){
fprintf(stdout, "dif failed\n");
}
}
else{
fprintf(stdout, "could not open comparison file %s\n", compare_file_name);
}
}
else{
fprintf(stdout, "could not open input %s\n", input_file_name);
}
return(0);
}
// BOTTOM