Skip to content

Commit 45b5972

Browse files
author
casse
committed
Fixed bug in print_type causing bad output of the types.
Should create clash somewhere else. Be careful.
1 parent 57fdd58 commit 45b5972

File tree

10 files changed

+139
-5
lines changed

10 files changed

+139
-5
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ include Makefile.head
44
PROJECT=Frontc
55
VERSION=3.3
66
RELEASE=2
7-
SUBDIRS = frontc ctoxml
7+
SUBDIRS = frontc ctoxml printc
88
DIST+=AUTHORS ChangeLog COPYING INSTALL NEWS README
99

1010
include Makefile.tail
11+
12+
doc:
13+
test -d autodoc || mkdir autodoc
14+
cd frontc; $(MAKE) doc

Makefile.head

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ SUBDIRS =
2121
export PREFIX=/usr
2222
export BIN_DIR = $(PREFIX)/bin
2323
export LIB_DIR = $(PREFIX)/lib
24+
export DATA_DIR = $(PREFIX)/share/$(PROJECT)
25+
26+
# User hooks
27+
INSTALL_BEFORE=
28+
INSTALL_AFTER=
2429

2530
# OCAML Predefinitions
2631
OCAMLC = ocamlc

Makefile.tail

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Development rules
23
_all: _subdirs_all $(_ALL)
34

@@ -56,7 +57,7 @@ endif
5657

5758

5859
# Install rules
59-
install: all _subdirs_install $(_INSTALL)
60+
install: all $(INSTALL_BEFORE) _subdirs_install $(_INSTALL) $(INSTALL_AFTER)
6061

6162
_subdirs_install:
6263
ifdef SUBDIRS
@@ -69,7 +70,10 @@ endif
6970

7071
$(BIN_DIR):
7172
install -d $(BIN_DIR)
72-
73+
74+
$(DATA_DIR):
75+
install -d $(DATA_DIR)
76+
7377

7478
# OCAML Rules
7579
OCAMLC_CFLAGS += $(patsubst %,-I %,$(OCAMLC_INC) $(OCAML_INC))

frontc/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# $Id$
22
include ../Makefile.head
33

4+
# Library
45
SOURCES = \
56
cabs.ml \
67
cxml.ml \
@@ -12,4 +13,22 @@ SOURCES = \
1213

1314
$(eval $(call ocaml_lib,frontc,$(SOURCES)))
1415

16+
INSTALL_AFTER += install_doc
1517
include ../Makefile.tail
18+
19+
20+
# Documentation
21+
DOCS = \
22+
cabs.ml \
23+
cxml.ml \
24+
cprint.ml \
25+
ctoxml.ml \
26+
frontc.ml
27+
28+
DOC_FLAGS=-colorize-code -I .
29+
doc:
30+
ocamldoc -html -d ../autodoc -t "FrontC" $(DOCS)
31+
32+
install_doc: doc $(DATA_DIR)
33+
cp -R ../autodoc $(DATADIR)
34+

frontc/cabs.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ and base_type =
7777
| VOLATILE of base_type
7878
(** "volatile" modifier *)
7979
| GNU_TYPE of gnu_attrs * base_type
80+
(** Not a type, just to record the file/line of an identifier. *)
81+
| TYPE_LINE of string * int * base_type
8082

8183
(** A name in a declaration with identifier, full type, GNU attributes and
8284
* initialization expression. *)

frontc/cparser.mly

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ let apply_mod (typ, sto) modi =
7070
| (CONST typ, _) -> CONST (mod_root typ)
7171
| (VOLATILE typ, _) -> VOLATILE (mod_root typ)
7272
| (GNU_TYPE (attrs, typ), _) -> GNU_TYPE (attrs, mod_root typ)
73+
| (TYPE_LINE (f, l, t), _) -> TYPE_LINE (f, l, mod_root t)
7374
| _ -> raise BadModifier in
7475
let check_access typ =
7576
match typ with
@@ -104,6 +105,7 @@ let set_type tst tin =
104105
| OLD_PROTO (typ, pars, ell) -> OLD_PROTO (set typ, pars, ell)
105106
| CONST typ -> CONST (set typ)
106107
| VOLATILE typ -> VOLATILE (set typ)
108+
| TYPE_LINE (f, l, t) -> TYPE_LINE (f, l, set t)
107109
| BITFIELD (NO_SIGN, exp) ->
108110
(match tst with
109111
INT (_, sign) -> BITFIELD (sign, exp)
@@ -158,6 +160,11 @@ let set_eline (file, line) expr =
158160
then Cabs.EXPR_LINE (expr, file, line)
159161
else expr
160162
163+
let set_tline _type =
164+
if Clexer.linerec !Clexer.current_handle
165+
then Cabs.TYPE_LINE (Clexer.curfile (), Clexer.curline(), _type)
166+
else _type
167+
161168
%}
162169

163170
%token <string> IDENT
@@ -335,7 +342,7 @@ global_def:
335342
;
336343
global_dec:
337344
IDENT
338-
{($1, NO_TYPE)}
345+
{($1, set_tline NO_TYPE)}
339346
| LPAREN global_dec RPAREN
340347
{$2}
341348
| STAR global_dec

frontc/cprint.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ let rec print_base_type typ =
196196
| CONST typ -> print_base_type typ
197197
| VOLATILE typ -> print_base_type typ
198198
| GNU_TYPE (attrs, typ) -> print_attributes attrs; print_base_type typ
199+
| TYPE_LINE (_, _, _type) -> print_base_type _type
199200

200201
and print_fields id (flds : name_group list) =
201202
print id;
@@ -254,7 +255,7 @@ and print_pointer typ =
254255
| CONST typ -> print_pointer typ; print " const "
255256
| VOLATILE typ -> print_pointer typ; print " volatile "
256257
| ARRAY (typ, _) -> print_pointer typ
257-
| _ -> print_base_type typ
258+
| _ -> (*print_base_type typ*) ()
258259

259260
and print_array typ =
260261
match typ with

frontc/ctoxml.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ and convert_type _type =
296296
| GNU_TYPE (attrs, _type) ->
297297
Cxml.add_children (convert_type _type) (List.map convert_gnu_attr attrs)
298298

299+
| TYPE_LINE (file, line, t) ->
300+
Cxml.new_elt "type_line"
301+
[ ("file", file); ("line", string_of_int line) ]
302+
[convert_type _type]
303+
299304
and convert_gnu_attr attr =
300305
match attr with
301306
GNU_NONE

printc/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# $Id$
2+
include ../Makefile.head
3+
4+
SOURCES = \
5+
printc_bin.ml
6+
7+
OCAML_INC += ../frontc
8+
OCAML_LIB += unix ../frontc/frontc
9+
10+
$(eval $(call ocaml_prog,printc,$(SOURCES)))
11+
12+
include ../Makefile.tail

printc/printc_bin.ml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
(*
2+
* $Id$
3+
* Copyright (c) 2007, Hugues Cassé <[email protected]>
4+
*
5+
* Pretty printer of C files.
6+
*)
7+
8+
open Frontc
9+
10+
11+
(* Options *)
12+
let banner =
13+
"printc V1.0 (10/01/07)\n" ^
14+
"Copyright (c) 2007, Hugues Cassé <[email protected]>\n\n" ^
15+
"SYNTAX:\tprintc [options] files...\n" ^
16+
"\tprintc [options] --\n"
17+
let args: parsing_arg list ref = ref []
18+
let files: string list ref = ref []
19+
let out_file = ref ""
20+
let from_stdin = ref false
21+
22+
23+
(* Options scanning *)
24+
let opts = [
25+
("-o", Arg.Set_string out_file,
26+
"Output to the given file.");
27+
("-pp", Arg.Unit (fun _ -> args := USE_CPP :: !args),
28+
"Preprocess the input files.");
29+
("-nogcc", Arg.Unit (fun _ -> args := (GCC_SUPPORT false) :: !args),
30+
"Do not use the GCC extensions.");
31+
("-proc", Arg.String (fun cpp -> args := (PREPROC cpp) :: !args),
32+
"Use the given preprocessor");
33+
("-i", Arg.String (fun file -> args := (INCLUDE file) :: !args),
34+
"Include the given file.");
35+
("-I", Arg.String (fun dir -> args := (INCLUDE_DIR dir) :: !args),
36+
"Include retrieval directory");
37+
("-D", Arg.String (fun def -> args := (DEF def) :: !args),
38+
"Pass this definition to the preprocessor.");
39+
("-U", Arg.String (fun undef -> args := (UNDEF undef) :: !args),
40+
"Pass this undefinition to the preprocessor.");
41+
("--", Arg.Set from_stdin,
42+
"Takes input from standard input.");
43+
]
44+
45+
46+
(* Main Program *)
47+
let _ =
48+
49+
(* Parse arguments *)
50+
Arg.parse opts (fun file -> files := file :: !files) banner;
51+
52+
(* Get the output *)
53+
let (output, close) =
54+
if !out_file = "" then (stdout,false)
55+
else ((open_out !out_file), true) in
56+
57+
58+
(* Process the input *)
59+
let process opts =
60+
match Frontc.parse opts with
61+
PARSING_ERROR -> ()
62+
| PARSING_OK file ->
63+
Cprint.print output file in
64+
65+
(* Process the inputs *)
66+
let _ =
67+
if !from_stdin || !files = []
68+
then process !args
69+
else
70+
List.iter (fun file -> process ((FROM_FILE file) :: !args)) !files in
71+
72+
(* Close the output if needed *)
73+
if close then close_out output
74+
75+

0 commit comments

Comments
 (0)