diff --git a/.gitignore b/.gitignore index f5669a6..becd9cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build -.vscode/ +.vs +.vscode diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index ccb8b5c..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -cmake_minimum_required(VERSION 2.8.6) - -include(CTest) - -add_subdirectory(source/compiler) -if(BUILD_TESTING) - enable_testing() - add_subdirectory(tests) -endif() \ No newline at end of file diff --git a/source/compiler/CMakeLists.txt b/source/compiler/CMakeLists.txt index 86b6bfa..b8db9b4 100644 --- a/source/compiler/CMakeLists.txt +++ b/source/compiler/CMakeLists.txt @@ -159,6 +159,13 @@ if(MSVC) DESTINATION bin) endif() +# Generate tests (only if enabled, i.e. BUILD_TESTING=ON) +include(CTest) +if(BUILD_TESTING) + enable_testing() + add_subdirectory(tests) +endif() + # Generate a binary package with CPack set(CPACK_PACKAGE_NAME pawnc) set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 92070c4..dba0a3b 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -396,11 +396,8 @@ static void readline(unsigned char *line) *line='\0'; /* delete line */ cont=FALSE; } else { - /* check whether to erase leading spaces */ + /* check whether to erase leading whitespace after '\\' on next line */ if (cont) { - unsigned char *ptr=line; - while (*ptr<=' ' && *ptr!='\0') - ptr++; if (ptr!=line) memmove(line,ptr,strlen((char*)ptr)+1); } /* if */ @@ -417,10 +414,6 @@ static void readline(unsigned char *line) ptr--; /* skip trailing whitespace */ if (*ptr=='\\') { cont=TRUE; - /* set '\a' at the position of '\\' to make it possible to check - * for a line continuation in a single line comment (error 49) - */ - *ptr++='\a'; *ptr='\0'; /* erase '\n' (and any trailing whitespace) */ } /* if */ } /* if */ @@ -445,7 +438,7 @@ static void readline(unsigned char *line) * * Global references: icomment (private to "stripcom") */ -static void stripcom(unsigned char *line) +static void stripcomment(unsigned char *line) { char c; #if !defined SC_LIGHT @@ -519,8 +512,6 @@ static void stripcom(unsigned char *line) if (icomment==2) *line++=' '; } else if (*line=='/' && *(line+1)=='/'){ /* comment to end of line */ - if (strchr((char*)line,'\a')!=NULL) - error(49); /* invalid line continuation */ #if !defined SC_LIGHT if (*(line+2)=='/' && *(line+3)<=' ') { /* documentation comment */ @@ -1859,8 +1850,8 @@ SC_FUNC void preprocess(void) return; do { readline(pline); - stripcom(pline); /* ??? no need for this when reading back from list file (in the second pass) */ - lptr=pline; /* set "line pointer" to start of the parsing buffer */ + stripcomment(pline); /* ??? no need for this when reading back from list file (in the second pass) */ + lptr=pline; /* set "line pointer" to start of the parsing buffer */ iscommand=command(); if (iscommand!=CMD_NONE) errorset(sRESET,0); /* reset error flag ("panic mode") on empty line or directive */ @@ -1895,10 +1886,6 @@ static const unsigned char *unpackedstring(const unsigned char *lptr,int *flags) while (*lptr==' ' || *lptr=='\t') /* this is as defines with parameters may add them */ lptr++; /* when you use a space after , in a match pattern */ while (*lptr!='\0') { - if (*lptr=='\a') { - lptr++; - continue; - } /* if */ if (!instring) { if (*lptr=='\"') { instring=1; @@ -1969,10 +1956,6 @@ static const unsigned char *packedstring(const unsigned char *lptr,int *flags) i=sizeof(ucell)-(sCHARBITS/8); /* start at most significant byte */ val=0; while (*lptr!='\0') { - if (*lptr=='\a') { /* ignore '\a' (which was inserted at a line concatenation) */ - lptr++; - continue; - } /* if */ if (!instring) { if (*lptr=='\"') { instring=1; diff --git a/source/compiler/tests/CMakeLists.txt b/source/compiler/tests/CMakeLists.txt new file mode 100644 index 0000000..c676ab3 --- /dev/null +++ b/source/compiler/tests/CMakeLists.txt @@ -0,0 +1,20 @@ +set(DEFAULT_COMPILER_OPTIONS + -i${CMAKE_SOURCE_DIR}/include + "-\;+" + "-(+") + +function(add_compiler_test test_name options) + add_test(NAME ${test_name} + COMMAND $ ${DEFAULT_COMPILER_OPTIONS} ${options}) + set_tests_properties(${test_name} PROPERTIES + ENVIRONMENT PATH=$) +endfunction() + +add_compiler_test(gh_217 ${CMAKE_CURRENT_SOURCE_DIR}/gh_217.pwn) +set_tests_properties(gh_217 PROPERTIES PASS_REGULAR_EXPRESSION +".*: warning 237: user warning: this is warning 1[\r\n]+\ +.*: warning 237: user warning: this iswarning 2[\r\n]+\ +.*: warning 237: user warning: this is warning 3[\r\n]+\ +.*: warning 237: user warning: this is warning 4[\r\n]+\ +.*: warning 234: function is deprecated \\(symbol \"f\"\\) don't use this functionplease[\r\n]+\ +.*: warning 234: function is deprecated \\(symbol \"f\"\\) don't use this functionplease") diff --git a/source/compiler/tests/gh_217.amx b/source/compiler/tests/gh_217.amx new file mode 100644 index 0000000..ecc17c2 Binary files /dev/null and b/source/compiler/tests/gh_217.amx differ diff --git a/source/compiler/tests/gh_217.pwn b/source/compiler/tests/gh_217.pwn new file mode 100644 index 0000000..2d2d24c --- /dev/null +++ b/source/compiler/tests/gh_217.pwn @@ -0,0 +1,33 @@ +// TODO: Check that string literals are concatenated correctly + +native print(const s[]); + +#define d1\ + print("ok") +#define d2 \ + print("ok") + +#warning this is\ + warning 1 +#warning this is\ +warning 2 +#warning this is \ +warning 3 +#warning this is \ + warning 4 + +// single-line comments can span \ +multiple lines if you really want it + +#pragma deprecated don't\ + use \ +this \ + function\ +please +f() {} + +main() { + d1; + d2; + f(); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index 2ac54d5..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set(DEFAULT_COMPILER_OPTIONS - -i${CMAKE_SOURCE_DIR}/include - "-\;+" - "-(+") - -function(add_compiler_test test_name options) - add_test(NAME ${test_name} - COMMAND $ ${DEFAULT_COMPILER_OPTIONS} ${options}) - set_tests_properties(${test_name} PROPERTIES - ENVIRONMENT PATH=$) -endfunction() - -add_subdirectory(compiler) \ No newline at end of file diff --git a/tests/compiler/CMakeLists.txt b/tests/compiler/CMakeLists.txt deleted file mode 100644 index d0778c1..0000000 --- a/tests/compiler/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_compiler_test(main ${CMAKE_CURRENT_SOURCE_DIR}/main.pwn) \ No newline at end of file diff --git a/tests/compiler/main.pwn b/tests/compiler/main.pwn deleted file mode 100644 index 2fa312e..0000000 --- a/tests/compiler/main.pwn +++ /dev/null @@ -1,5 +0,0 @@ -#include - -main() { - print("Hello World!"); -} \ No newline at end of file