1 /* Code to maintain a C++ template repository.
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Contributed by Jason Merrill (jason@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* My strategy here is as follows:
23 Everything should be emitted in a translation unit where it is used.
24 The results of the automatic process should be easily reproducible with
27 I'm thinking of compiling with -frepo, running a Perl script to update
28 files, and then being able to rebuild everything with -fno-implicit.
29 Full automation can come later. */
36 extern char * rindex ();
38 static tree pending_repo
;
39 static char repo_name
[1024];
40 static FILE *repo_file
;
42 extern int flag_use_repository
;
43 extern int errorcount
, sorrycount
;
45 static int repo_changed
;
47 #define IDENTIFIER_REPO_USED(NODE) (TREE_LANG_FLAG_3 (NODE))
48 #define IDENTIFIER_REPO_CHOSEN(NODE) (TREE_LANG_FLAG_4 (NODE))
50 /* Record the flags used to compile this translation unit. */
53 repo_compile_flags (argc
, argv
)
59 /* If this template has not been seen before, add a note to the repository
60 saying where the declaration was. This may be used to find the
61 definition at link time. */
64 repo_template_declared (t
)
68 /* Note where the definition of a template lives so that instantiations can
69 be generated later. */
72 repo_template_defined (t
)
76 /* Note where the definition of a class lives to that template
77 instantiations can use it. */
80 repo_class_defined (t
)
84 /* Note that a template has been used. If we can see the definition, offer
88 repo_template_used (t
)
93 if (! flag_use_repository
)
96 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
98 id
= DECL_ASSEMBLER_NAME (TYPE_MAIN_DECL (t
));
99 if (IDENTIFIER_REPO_CHOSEN (id
))
100 mark_class_instantiated (t
, 0);
102 else if (TREE_CODE_CLASS (TREE_CODE (t
)) == 'd')
104 id
= DECL_ASSEMBLER_NAME (t
);
105 if (IDENTIFIER_REPO_CHOSEN (id
))
106 mark_function_instantiated (t
, 0);
109 my_friendly_abort (1);
111 if (! IDENTIFIER_REPO_USED (id
))
114 IDENTIFIER_REPO_USED (id
) = 1;
116 pending_repo
= perm_tree_cons (NULL_TREE
, t
, pending_repo
);
119 /* Note that the vtable for a class has been used, and offer to emit it. */
125 if (! flag_use_repository
)
128 pending_repo
= perm_tree_cons (NULL_TREE
, t
, pending_repo
);
131 /* Note that an inline with external linkage has been used, and offer to
135 repo_inline_used (fn
)
138 if (! flag_use_repository
)
141 /* Member functions of polymorphic classes go with their vtables. */
142 if (DECL_FUNCTION_MEMBER_P (fn
) && TYPE_VIRTUAL_P (DECL_CLASS_CONTEXT (fn
)))
144 repo_vtable_used (DECL_CLASS_CONTEXT (fn
));
148 pending_repo
= perm_tree_cons (NULL_TREE
, fn
, pending_repo
);
151 /* Note that a particular typeinfo node has been used, and offer to
161 open_repo_file (filename
)
164 register char *p
, *q
;
165 char *file
= filename
;
166 char *s
= rindex (file
, '/');
172 for (p
= repo_name
, q
= file
; q
< s
; )
178 repo_file
= fopen (repo_name
, "r");
187 if (! flag_use_repository
)
190 open_repo_file (filename
);
195 while (fgets (buf
, 1024, repo_file
))
197 int len
= strlen (buf
) - 1;
198 if (buf
[len
] != '\n')
199 error ("repository info line too long in %s", repo_name
);
210 tree id
= get_identifier (&buf
[2]);
211 IDENTIFIER_REPO_USED (id
) = 1;
213 IDENTIFIER_REPO_CHOSEN (id
) = 1;
217 error ("mysterious repository information in %s", repo_name
);
223 reopen_repo_file_for_write ()
227 repo_file
= fopen (repo_name
, "w");
231 error ("man't create repository information file `%s'", repo_name
);
232 flag_use_repository
= 0;
236 /* Emit any pending repos. */
244 if (! flag_use_repository
)
247 /* Do we have to write out a new info file? */
249 if (! repo_changed
|| errorcount
|| sorrycount
)
252 reopen_repo_file_for_write ();
257 for (t
= pending_repo
; t
; t
= TREE_CHAIN (t
))
259 tree val
= TREE_VALUE (t
);
262 if (TREE_CODE_CLASS (TREE_CODE (val
)) == 't')
263 val
= TYPE_MAIN_DECL (val
);
264 val
= DECL_ASSEMBLER_NAME (val
);
266 if (! IDENTIFIER_REPO_USED (val
))
268 IDENTIFIER_REPO_USED (val
) = 0;
270 type
= IDENTIFIER_REPO_CHOSEN (val
) ? 'C' : 'O';
272 fprintf (repo_file
, "%c %s\n", type
, IDENTIFIER_POINTER (val
));