Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C and CPP backends: use size_t for things such as sizes. #391

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/src/BNFC/Backend/C.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
11 changes: 6 additions & 5 deletions source/src/BNFC/Backend/C/CFtoCPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ mkCFile cf groups = concat
"/*** Pretty Printer and Abstract Syntax Viewer ***/",
"",
"#include <ctype.h> /* isspace */",
"#include <stddef.h> /* size_t */",
"#include <stdio.h>",
"#include <string.h>",
"#include <stdlib.h>",
Expand All @@ -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
Expand Down Expand Up @@ -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 */",
Expand Down Expand Up @@ -314,7 +315,7 @@ mkCFile cf groups = concat
" buf_ = temp;",
"}",
"char *buf_;",
"int cur_, buf_size;",
"size_t cur_, buf_size;",
""
]

Expand Down
2 changes: 1 addition & 1 deletion source/src/BNFC/Backend/CPP/Makefile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 7 additions & 15 deletions source/src/BNFC/Backend/CPP/PrettyPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ mkHFile useStl inPackage cf groups = unlines
"",
"#include \"Absyn.H\"",
"#include <stdio.h>",
"#include <stddef.h>",
"#include <string.h>",
"#include <stdlib.h>",
"",
Expand Down Expand Up @@ -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);",
Expand All @@ -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;",
" }",
Expand Down