Skip to content

Commit b4a44bb

Browse files
authored
Merge pull request #128 from thoni56/cgreen_mocker_to_generate_casts
Cgreen mocker to generate casts
2 parents 3d412d4 + 283162c commit b4a44bb

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ all: build
2020
debug: build
2121
cd build; cmake -DCMAKE_BUILD_TYPE:string=Debug ..; make
2222

23+
# TODO: verify that we're not already on CygwinXX, in that case "make" should suffice
24+
.PHONY:cygwin32
25+
cygwin32: build
26+
cd build; cmake -DCMAKE_C_COMPILER=i686-pc-cygwin-gcc -DCMAKE_CXX_COMPILER=i686-pc-cygwin-g++ -DCMAKE_INSTALL_BINDIR:string=bin32 -DCMAKE_INSTALL_LIBDIR:string=lib32 ..; make
27+
28+
.PHONY:cygwin64
29+
cygwin64: build
30+
cd build; cmake -DCMAKE_C_COMPILER=i686-pc-cygwin-gcc -DCMAKE_CXX_COMPILER=i686-pc-cygwin-g++ ..; make
31+
2332
.PHONY:test
2433
test: build
2534
cd build; make check

contrib/cgreen-mocker/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
all:
22
@echo "With the command:"
3-
@echo
3+
@echo "-----------------"
44
./cgreen-mocker.py double.h > double.mock
5-
@echo
5+
@echo "-----------------"
66
@echo "'cgreen-mocker' reads a C header file and transforms any"
77
@echo "function declarations into corresponding Cgreen mocks."
88
@echo "Here's the input:"
9-
@echo
9+
@echo "-----------------"
1010
@cat double.h
11-
@echo
11+
@echo "-----------------"
1212
@echo "And here's the resulting mock declaration:"
13-
@echo
13+
@echo "------------------------------------------"
1414
@cat double.mock
15+
@echo "------------------------------------------"

contrib/cgreen-mocker/cgreen-mocker.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
# Since it uses pycparser it will only handle C functions
1919
# and you will probably need the pycparsers "fake_libc_include"
2020
# to avoid parsing the whole world of libc headers. You can
21-
# point to it using a command line 'cpp_directive' arg.
21+
# make a soft link in your directory to a copy of the pycparser
22+
# source, and cgreen-mocker will pick it up or you can point
23+
# to it using a command line 'cpp_directive' arg.
2224
#
2325
# You can find pycparser at https://github.com/eliben/pycparser
2426
#
@@ -58,7 +60,7 @@ def visit_FuncDecl(self, node):
5860
print()
5961

6062
def arg_list(args):
61-
if len(args.params) > 0:
63+
if args != None and len(args.params) > 0:
6264
return [el for el in map(parameter_name_or_box_double, args.params) if el is not None]
6365
else:
6466
return []
@@ -70,10 +72,15 @@ def parameter_name_or_box_double(node):
7072
return node.name
7173

7274
def should_return(node):
75+
generator = c_generator.CGenerator()
7376
if isdouble_decl(node):
7477
print(" return unbox_double(", end="")
7578
elif not isvoid_decl(node):
76-
print(" return ", end="")
79+
print(" return (", end="")
80+
print(generator.visit(node.type), end="")
81+
if isinstance(node.type, c_ast.PtrDecl):
82+
print(" *", end="")
83+
print(") ", end="")
7784
else:
7885
print(" ", end="")
7986

0 commit comments

Comments
 (0)