diff --git a/source/src/BNFC/Backend/C.hs b/source/src/BNFC/Backend/C.hs index 9f6f61bc..d4cecb24 100644 --- a/source/src/BNFC/Backend/C.hs +++ b/source/src/BNFC/Backend/C.hs @@ -62,7 +62,7 @@ makeC opts cf = do makefile :: String -> String -> String -> Doc makefile name prefix basename = vcat [ "CC = gcc -g" - , "CCFLAGS = --ansi -W -Wall -Wno-unused-parameter -Wno-unused-function -Wno-unneeded-internal-declaration ${CC_OPTS}" + , "CCFLAGS = --ansi -W -Wall -Wsign-conversion -Wno-unused-parameter -Wno-unused-function -Wno-unneeded-internal-declaration ${CC_OPTS}" -- The @#define _POSIX_C_SOURCE 200809L@ is now placed locally in -- the generated lexer. -- , "CCFLAGS = --ansi -W -Wall -Wno-unused-parameter -Wno-unused-function -Wno-unneeded-internal-declaration -D_POSIX_C_SOURCE=200809L ${CC_OPTS}" diff --git a/source/src/BNFC/Backend/C/CFtoCPrinter.hs b/source/src/BNFC/Backend/C/CFtoCPrinter.hs index 97236706..71054afd 100644 --- a/source/src/BNFC/Backend/C/CFtoCPrinter.hs +++ b/source/src/BNFC/Backend/C/CFtoCPrinter.hs @@ -155,6 +155,7 @@ mkCFile cf groups = concat "/*** Pretty Printer and Abstract Syntax Viewer ***/", "", "#include /* isspace */", + "#include /* size_t */", "#include ", "#include ", "#include ", @@ -164,8 +165,8 @@ mkCFile cf groups = concat "", "int _n_;", "char *buf_;", - "int cur_;", - "int buf_size;", + "size_t cur_;", + "size_t buf_size;", "" ] printBasics = unlines @@ -266,8 +267,8 @@ mkCFile cf groups = concat [ "void bufAppendS(const char *s)", "{", - " int len = strlen(s);", - " int n;", + " size_t len = strlen(s);", + " size_t n;", " while (cur_ + len >= buf_size)", " {", " buf_size *= 2; /* Double the buffer size */", @@ -314,7 +315,7 @@ mkCFile cf groups = concat " buf_ = temp;", "}", "char *buf_;", - "int cur_, buf_size;", + "size_t cur_, buf_size;", "" ] diff --git a/source/src/BNFC/Backend/CPP/Makefile.hs b/source/src/BNFC/Backend/CPP/Makefile.hs index eb264add..0ecc16d5 100644 --- a/source/src/BNFC/Backend/CPP/Makefile.hs +++ b/source/src/BNFC/Backend/CPP/Makefile.hs @@ -8,7 +8,7 @@ import BNFC.PrettyPrint makefile :: String -> String -> String -> Doc makefile prefix name basename = vcat [ mkVar "CC" "g++ -g" - , mkVar "CCFLAGS" "--ansi -W -Wall -Wno-unused-parameter -Wno-unused-function -Wno-unneeded-internal-declaration" + , mkVar "CCFLAGS" "--ansi -W -Wall -Wsign-conversion -Wno-unused-parameter -Wno-unused-function -Wno-unneeded-internal-declaration" , "" , mkVar "FLEX" "flex" , mkVar "FLEX_OPTS" ("-P" ++ prefix) diff --git a/source/src/BNFC/Backend/CPP/PrettyPrinter.hs b/source/src/BNFC/Backend/CPP/PrettyPrinter.hs index df64af51..1f1b6251 100644 --- a/source/src/BNFC/Backend/CPP/PrettyPrinter.hs +++ b/source/src/BNFC/Backend/CPP/PrettyPrinter.hs @@ -69,6 +69,7 @@ mkHFile useStl inPackage cf groups = unlines "", "#include \"Absyn.H\"", "#include ", + "#include ", "#include ", "#include ", "", @@ -111,11 +112,11 @@ mkHFile useStl inPackage cf groups = unlines [ " protected:", " char *buf_;", - " int cur_, buf_size;", + " std::size_t cur_, buf_size;", "", " void inline bufAppend(const char *s)", " {", - " int end = cur_ + strlen(s);", + " std::size_t end = cur_ + strlen(s);", " if (end >= buf_size) {", " do buf_size *= 2; /* Double the buffer size */", " while (end >= buf_size);", @@ -139,29 +140,20 @@ mkHFile useStl inPackage cf groups = unlines if useStl then render (nest 2 bufAppendString) else "", " void inline bufReset(void)", " {", - " if (buf_) free(buf_);", + " if (buf_) delete[] buf_;", " buf_size = " ++ nsDefine inPackage "BUFFER_INITIAL" ++ ";", - " buf_ = (char *) malloc(buf_size);", - " if (!buf_) {", - " fprintf(stderr, \"Error: Out of memory while allocating buffer!\\n\");", - " exit(1);", - " }", + " buf_ = new char[buf_size];", " memset(buf_, 0, buf_size);", " cur_ = 0;", " }", "", " void inline resizeBuffer(void)", " {", - " char *temp = (char *) malloc(buf_size);", - " if (!temp)", - " {", - " fprintf(stderr, \"Error: Out of memory while attempting to grow buffer!\\n\");", - " exit(1);", - " }", + " char *temp = new char[buf_size];", " if (buf_)", " {", " strcpy(temp, buf_);", - " free(buf_);", + " delete[] buf_;", " }", " buf_ = temp;", " }",