]>
Commit | Line | Data |
---|---|---|
0168a849 | 1 | /* Darwin support needed only by C/C++ frontends. |
acce4e77 | 2 | Copyright (C) 2001, 2003, 2004, 2005, 2007, 2008, 2010, 2011 |
66647d44 | 3 | Free Software Foundation, Inc. |
0168a849 SS |
4 | Contributed by Apple Computer Inc. |
5 | ||
7ec022b2 | 6 | This file is part of GCC. |
0168a849 | 7 | |
7ec022b2 | 8 | GCC is free software; you can redistribute it and/or modify |
0168a849 | 9 | it under the terms of the GNU General Public License as published by |
2f83c7d6 | 10 | the Free Software Foundation; either version 3, or (at your option) |
0168a849 SS |
11 | any later version. |
12 | ||
7ec022b2 | 13 | GCC is distributed in the hope that it will be useful, |
0168a849 SS |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
2f83c7d6 NC |
19 | along with GCC; see the file COPYING3. If not see |
20 | <http://www.gnu.org/licenses/>. */ | |
0168a849 SS |
21 | |
22 | #include "config.h" | |
23 | #include "system.h" | |
4977bab6 ZW |
24 | #include "coretypes.h" |
25 | #include "tm.h" | |
0168a849 SS |
26 | #include "cpplib.h" |
27 | #include "tree.h" | |
70f42967 | 28 | #include "target.h" |
e8a25ca8 | 29 | #include "incpath.h" |
39dabefd SB |
30 | #include "c-family/c-common.h" |
31 | #include "c-family/c-pragma.h" | |
91ebb981 | 32 | #include "c-family/c-format.h" |
718f9c0f | 33 | #include "diagnostic-core.h" |
43b3a5b1 | 34 | #include "flags.h" |
0168a849 | 35 | #include "tm_p.h" |
3dd53121 AP |
36 | #include "cppdefault.h" |
37 | #include "prefix.h" | |
acce4e77 JM |
38 | #include "c-family/c-target.h" |
39 | #include "c-family/c-target-def.h" | |
70f42967 | 40 | #include "cgraph.h" |
0168a849 SS |
41 | |
42 | /* Pragmas. */ | |
43 | ||
76ad5c10 MS |
44 | #define BAD(gmsgid) do { warning (OPT_Wpragmas, gmsgid); return; } while (0) |
45 | #define BAD2(msgid, arg) do { warning (OPT_Wpragmas, msgid, arg); return; } while (0) | |
0168a849 | 46 | |
94d1613b MS |
47 | static bool using_frameworks = false; |
48 | ||
e3c287c9 MS |
49 | static const char *find_subframework_header (cpp_reader *pfile, const char *header, |
50 | cpp_dir **dirp); | |
0168a849 SS |
51 | |
52 | typedef struct align_stack | |
53 | { | |
54 | int alignment; | |
55 | struct align_stack * prev; | |
56 | } align_stack; | |
57 | ||
58 | static struct align_stack * field_align_stack = NULL; | |
59 | ||
1f1d5130 MS |
60 | /* Maintain a small stack of alignments. This is similar to pragma |
61 | pack's stack, but simpler. */ | |
62 | ||
0168a849 | 63 | static void |
9c808aad | 64 | push_field_alignment (int bit_alignment) |
0168a849 | 65 | { |
5ed6ace5 | 66 | align_stack *entry = XNEW (align_stack); |
0168a849 SS |
67 | |
68 | entry->alignment = maximum_field_alignment; | |
69 | entry->prev = field_align_stack; | |
70 | field_align_stack = entry; | |
71 | ||
72 | maximum_field_alignment = bit_alignment; | |
73 | } | |
74 | ||
75 | static void | |
9c808aad | 76 | pop_field_alignment (void) |
0168a849 SS |
77 | { |
78 | if (field_align_stack) | |
79 | { | |
80 | align_stack *entry = field_align_stack; | |
81 | ||
82 | maximum_field_alignment = entry->alignment; | |
83 | field_align_stack = entry->prev; | |
84 | free (entry); | |
85 | } | |
86 | else | |
87 | error ("too many #pragma options align=reset"); | |
88 | } | |
89 | ||
90 | /* Handlers for Darwin-specific pragmas. */ | |
91 | ||
92 | void | |
9c808aad | 93 | darwin_pragma_ignore (cpp_reader *pfile ATTRIBUTE_UNUSED) |
0168a849 SS |
94 | { |
95 | /* Do nothing. */ | |
96 | } | |
97 | ||
98 | /* #pragma options align={mac68k|power|reset} */ | |
99 | ||
100 | void | |
9c808aad | 101 | darwin_pragma_options (cpp_reader *pfile ATTRIBUTE_UNUSED) |
0168a849 | 102 | { |
7ae8cf75 | 103 | const char *arg; |
0168a849 SS |
104 | tree t, x; |
105 | ||
75ce3d48 | 106 | if (pragma_lex (&t) != CPP_NAME) |
0168a849 SS |
107 | BAD ("malformed '#pragma options', ignoring"); |
108 | arg = IDENTIFIER_POINTER (t); | |
109 | if (strcmp (arg, "align")) | |
110 | BAD ("malformed '#pragma options', ignoring"); | |
75ce3d48 | 111 | if (pragma_lex (&t) != CPP_EQ) |
0168a849 | 112 | BAD ("malformed '#pragma options', ignoring"); |
75ce3d48 | 113 | if (pragma_lex (&t) != CPP_NAME) |
0168a849 SS |
114 | BAD ("malformed '#pragma options', ignoring"); |
115 | ||
75ce3d48 | 116 | if (pragma_lex (&x) != CPP_EOF) |
aea8e035 | 117 | warning (OPT_Wpragmas, "junk at end of '#pragma options'"); |
0168a849 SS |
118 | |
119 | arg = IDENTIFIER_POINTER (t); | |
120 | if (!strcmp (arg, "mac68k")) | |
121 | push_field_alignment (16); | |
122 | else if (!strcmp (arg, "power")) | |
123 | push_field_alignment (0); | |
124 | else if (!strcmp (arg, "reset")) | |
125 | pop_field_alignment (); | |
126 | else | |
213af8c8 | 127 | BAD ("malformed '#pragma options align={mac68k|power|reset}', ignoring"); |
0168a849 SS |
128 | } |
129 | ||
130 | /* #pragma unused ([var {, var}*]) */ | |
131 | ||
132 | void | |
9c808aad | 133 | darwin_pragma_unused (cpp_reader *pfile ATTRIBUTE_UNUSED) |
0168a849 SS |
134 | { |
135 | tree decl, x; | |
136 | int tok; | |
137 | ||
75ce3d48 | 138 | if (pragma_lex (&x) != CPP_OPEN_PAREN) |
0168a849 SS |
139 | BAD ("missing '(' after '#pragma unused', ignoring"); |
140 | ||
141 | while (1) | |
142 | { | |
75ce3d48 | 143 | tok = pragma_lex (&decl); |
0168a849 SS |
144 | if (tok == CPP_NAME && decl) |
145 | { | |
10e6657a | 146 | tree local = lookup_name (decl); |
0168a849 SS |
147 | if (local && (TREE_CODE (local) == PARM_DECL |
148 | || TREE_CODE (local) == VAR_DECL)) | |
3bd5cdeb IS |
149 | { |
150 | TREE_USED (local) = 1; | |
151 | DECL_READ_P (local) = 1; | |
152 | } | |
75ce3d48 | 153 | tok = pragma_lex (&x); |
0168a849 SS |
154 | if (tok != CPP_COMMA) |
155 | break; | |
156 | } | |
157 | } | |
158 | ||
159 | if (tok != CPP_CLOSE_PAREN) | |
160 | BAD ("missing ')' after '#pragma unused', ignoring"); | |
161 | ||
75ce3d48 | 162 | if (pragma_lex (&x) != CPP_EOF) |
213af8c8 | 163 | BAD ("junk at end of '#pragma unused'"); |
0168a849 | 164 | } |
94d1613b | 165 | |
16d6f994 EC |
166 | /* Parse the ms_struct pragma. */ |
167 | void | |
168 | darwin_pragma_ms_struct (cpp_reader *pfile ATTRIBUTE_UNUSED) | |
169 | { | |
170 | const char *arg; | |
171 | tree t; | |
172 | ||
173 | if (pragma_lex (&t) != CPP_NAME) | |
174 | BAD ("malformed '#pragma ms_struct', ignoring"); | |
175 | arg = IDENTIFIER_POINTER (t); | |
176 | ||
177 | if (!strcmp (arg, "on")) | |
178 | darwin_ms_struct = true; | |
179 | else if (!strcmp (arg, "off") || !strcmp (arg, "reset")) | |
180 | darwin_ms_struct = false; | |
181 | else | |
213af8c8 | 182 | BAD ("malformed '#pragma ms_struct {on|off|reset}', ignoring"); |
16d6f994 EC |
183 | |
184 | if (pragma_lex (&t) != CPP_EOF) | |
213af8c8 | 185 | BAD ("junk at end of '#pragma ms_struct'"); |
16d6f994 EC |
186 | } |
187 | ||
5ead67f6 | 188 | static struct frameworks_in_use { |
94d1613b MS |
189 | size_t len; |
190 | const char *name; | |
191 | cpp_dir* dir; | |
192 | } *frameworks_in_use; | |
193 | static int num_frameworks = 0; | |
194 | static int max_frameworks = 0; | |
195 | ||
196 | ||
197 | /* Remember which frameworks have been seen, so that we can ensure | |
198 | that all uses of that framework come from the same framework. DIR | |
199 | is the place where the named framework NAME, which is of length | |
e3c287c9 MS |
200 | LEN, was found. We copy the directory name from NAME, as it will be |
201 | freed by others. */ | |
94d1613b MS |
202 | |
203 | static void | |
204 | add_framework (const char *name, size_t len, cpp_dir *dir) | |
205 | { | |
e3c287c9 | 206 | char *dir_name; |
94d1613b MS |
207 | int i; |
208 | for (i = 0; i < num_frameworks; ++i) | |
209 | { | |
210 | if (len == frameworks_in_use[i].len | |
211 | && strncmp (name, frameworks_in_use[i].name, len) == 0) | |
212 | { | |
213 | return; | |
214 | } | |
215 | } | |
216 | if (i >= max_frameworks) | |
217 | { | |
218 | max_frameworks = i*2; | |
e3c287c9 | 219 | max_frameworks += i == 0; |
5ead67f6 KG |
220 | frameworks_in_use = XRESIZEVEC (struct frameworks_in_use, |
221 | frameworks_in_use, max_frameworks); | |
94d1613b | 222 | } |
5ed6ace5 | 223 | dir_name = XNEWVEC (char, len + 1); |
e3c287c9 MS |
224 | memcpy (dir_name, name, len); |
225 | dir_name[len] = '\0'; | |
226 | frameworks_in_use[num_frameworks].name = dir_name; | |
94d1613b MS |
227 | frameworks_in_use[num_frameworks].len = len; |
228 | frameworks_in_use[num_frameworks].dir = dir; | |
229 | ++num_frameworks; | |
230 | } | |
231 | ||
232 | /* Recall if we have seen the named framework NAME, before, and where | |
233 | we saw it. NAME is LEN bytes long. The return value is the place | |
234 | where it was seen before. */ | |
235 | ||
236 | static struct cpp_dir* | |
237 | find_framework (const char *name, size_t len) | |
238 | { | |
239 | int i; | |
240 | for (i = 0; i < num_frameworks; ++i) | |
241 | { | |
242 | if (len == frameworks_in_use[i].len | |
243 | && strncmp (name, frameworks_in_use[i].name, len) == 0) | |
244 | { | |
245 | return frameworks_in_use[i].dir; | |
246 | } | |
247 | } | |
248 | return 0; | |
249 | } | |
250 | ||
251 | /* There are two directories in a framework that contain header files, | |
252 | Headers and PrivateHeaders. We search Headers first as it is more | |
253 | common to upgrade a header from PrivateHeaders to Headers and when | |
254 | that is done, the old one might hang around and be out of data, | |
255 | causing grief. */ | |
256 | ||
257 | struct framework_header {const char * dirName; int dirNameLen; }; | |
258 | static struct framework_header framework_header_dirs[] = { | |
259 | { "Headers", 7 }, | |
260 | { "PrivateHeaders", 14 }, | |
261 | { NULL, 0 } | |
262 | }; | |
263 | ||
264 | /* Returns a pointer to a malloced string that contains the real pathname | |
265 | to the file, given the base name and the name. */ | |
266 | ||
267 | static char * | |
268 | framework_construct_pathname (const char *fname, cpp_dir *dir) | |
269 | { | |
b674cffe | 270 | const char *buf; |
94d1613b MS |
271 | size_t fname_len, frname_len; |
272 | cpp_dir *fast_dir; | |
273 | char *frname; | |
274 | struct stat st; | |
275 | int i; | |
276 | ||
277 | /* Framework names must have a / in them. */ | |
278 | buf = strchr (fname, '/'); | |
279 | if (buf) | |
280 | fname_len = buf - fname; | |
281 | else | |
282 | return 0; | |
283 | ||
284 | fast_dir = find_framework (fname, fname_len); | |
285 | ||
286 | /* Framework includes must all come from one framework. */ | |
287 | if (fast_dir && dir != fast_dir) | |
288 | return 0; | |
289 | ||
5ed6ace5 | 290 | frname = XNEWVEC (char, strlen (fname) + dir->len + 2 |
94d1613b MS |
291 | + strlen(".framework/") + strlen("PrivateHeaders")); |
292 | strncpy (&frname[0], dir->name, dir->len); | |
293 | frname_len = dir->len; | |
294 | if (frname_len && frname[frname_len-1] != '/') | |
295 | frname[frname_len++] = '/'; | |
296 | strncpy (&frname[frname_len], fname, fname_len); | |
297 | frname_len += fname_len; | |
298 | strncpy (&frname[frname_len], ".framework/", strlen (".framework/")); | |
299 | frname_len += strlen (".framework/"); | |
300 | ||
a68bdb0b MS |
301 | if (fast_dir == 0) |
302 | { | |
303 | frname[frname_len-1] = 0; | |
304 | if (stat (frname, &st) == 0) | |
305 | { | |
306 | /* As soon as we find the first instance of the framework, | |
307 | we stop and never use any later instance of that | |
308 | framework. */ | |
309 | add_framework (fname, fname_len, dir); | |
310 | } | |
311 | else | |
312 | { | |
313 | /* If we can't find the parent directory, no point looking | |
314 | further. */ | |
315 | free (frname); | |
316 | return 0; | |
317 | } | |
318 | frname[frname_len-1] = '/'; | |
319 | } | |
320 | ||
94d1613b MS |
321 | /* Append framework_header_dirs and header file name */ |
322 | for (i = 0; framework_header_dirs[i].dirName; i++) | |
323 | { | |
16d6f994 | 324 | strncpy (&frname[frname_len], |
94d1613b MS |
325 | framework_header_dirs[i].dirName, |
326 | framework_header_dirs[i].dirNameLen); | |
327 | strcpy (&frname[frname_len + framework_header_dirs[i].dirNameLen], | |
328 | &fname[fname_len]); | |
329 | ||
330 | if (stat (frname, &st) == 0) | |
a68bdb0b | 331 | return frname; |
94d1613b MS |
332 | } |
333 | ||
334 | free (frname); | |
335 | return 0; | |
336 | } | |
337 | ||
338 | /* Search for FNAME in sub-frameworks. pname is the context that we | |
339 | wish to search in. Return the path the file was found at, | |
340 | otherwise return 0. */ | |
341 | ||
342 | static const char* | |
343 | find_subframework_file (const char *fname, const char *pname) | |
344 | { | |
345 | char *sfrname; | |
346 | const char *dot_framework = ".framework/"; | |
b674cffe | 347 | const char *bufptr; |
16d6f994 | 348 | int sfrname_len, i, fname_len; |
94d1613b MS |
349 | struct cpp_dir *fast_dir; |
350 | static struct cpp_dir subframe_dir; | |
351 | struct stat st; | |
352 | ||
353 | bufptr = strchr (fname, '/'); | |
354 | ||
355 | /* Subframework files must have / in the name. */ | |
356 | if (bufptr == 0) | |
357 | return 0; | |
16d6f994 | 358 | |
94d1613b MS |
359 | fname_len = bufptr - fname; |
360 | fast_dir = find_framework (fname, fname_len); | |
361 | ||
362 | /* Sub framework header filename includes parent framework name and | |
363 | header name in the "CarbonCore/OSUtils.h" form. If it does not | |
364 | include slash it is not a sub framework include. */ | |
365 | bufptr = strstr (pname, dot_framework); | |
366 | ||
367 | /* If the parent header is not of any framework, then this header | |
1e5f1716 | 368 | cannot be part of any subframework. */ |
94d1613b MS |
369 | if (!bufptr) |
370 | return 0; | |
371 | ||
372 | /* Now translate. For example, +- bufptr | |
16d6f994 | 373 | fname = CarbonCore/OSUtils.h | |
94d1613b MS |
374 | pname = /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h |
375 | into | |
376 | sfrname = /System/Library/Frameworks/Foundation.framework/Frameworks/CarbonCore.framework/Headers/OSUtils.h */ | |
377 | ||
5ed6ace5 | 378 | sfrname = XNEWVEC (char, strlen (pname) + strlen (fname) + 2 + |
94d1613b MS |
379 | strlen ("Frameworks/") + strlen (".framework/") |
380 | + strlen ("PrivateHeaders")); | |
16d6f994 | 381 | |
94d1613b MS |
382 | bufptr += strlen (dot_framework); |
383 | ||
16d6f994 | 384 | sfrname_len = bufptr - pname; |
94d1613b MS |
385 | |
386 | strncpy (&sfrname[0], pname, sfrname_len); | |
387 | ||
388 | strncpy (&sfrname[sfrname_len], "Frameworks/", strlen ("Frameworks/")); | |
389 | sfrname_len += strlen("Frameworks/"); | |
390 | ||
391 | strncpy (&sfrname[sfrname_len], fname, fname_len); | |
392 | sfrname_len += fname_len; | |
393 | ||
394 | strncpy (&sfrname[sfrname_len], ".framework/", strlen (".framework/")); | |
395 | sfrname_len += strlen (".framework/"); | |
396 | ||
397 | /* Append framework_header_dirs and header file name */ | |
398 | for (i = 0; framework_header_dirs[i].dirName; i++) | |
399 | { | |
16d6f994 | 400 | strncpy (&sfrname[sfrname_len], |
94d1613b MS |
401 | framework_header_dirs[i].dirName, |
402 | framework_header_dirs[i].dirNameLen); | |
403 | strcpy (&sfrname[sfrname_len + framework_header_dirs[i].dirNameLen], | |
404 | &fname[fname_len]); | |
16d6f994 | 405 | |
94d1613b MS |
406 | if (stat (sfrname, &st) == 0) |
407 | { | |
408 | if (fast_dir != &subframe_dir) | |
409 | { | |
410 | if (fast_dir) | |
d4ee4d25 | 411 | warning (0, "subframework include %s conflicts with framework include", |
94d1613b MS |
412 | fname); |
413 | else | |
414 | add_framework (fname, fname_len, &subframe_dir); | |
415 | } | |
416 | ||
417 | return sfrname; | |
418 | } | |
419 | } | |
420 | free (sfrname); | |
421 | ||
422 | return 0; | |
423 | } | |
424 | ||
425 | /* Add PATH to the system includes. PATH must be malloc-ed and | |
426 | NUL-terminated. System framework paths are C++ aware. */ | |
427 | ||
428 | static void | |
429 | add_system_framework_path (char *path) | |
430 | { | |
431 | int cxx_aware = 1; | |
432 | cpp_dir *p; | |
433 | ||
5ed6ace5 | 434 | p = XNEW (cpp_dir); |
94d1613b MS |
435 | p->next = NULL; |
436 | p->name = path; | |
437 | p->sysp = 1 + !cxx_aware; | |
438 | p->construct = framework_construct_pathname; | |
439 | using_frameworks = 1; | |
440 | ||
441 | add_cpp_dir_path (p, SYSTEM); | |
442 | } | |
443 | ||
444 | /* Add PATH to the bracket includes. PATH must be malloc-ed and | |
445 | NUL-terminated. */ | |
446 | ||
447 | void | |
448 | add_framework_path (char *path) | |
449 | { | |
450 | cpp_dir *p; | |
451 | ||
5ed6ace5 | 452 | p = XNEW (cpp_dir); |
94d1613b MS |
453 | p->next = NULL; |
454 | p->name = path; | |
455 | p->sysp = 0; | |
456 | p->construct = framework_construct_pathname; | |
457 | using_frameworks = 1; | |
458 | ||
459 | add_cpp_dir_path (p, BRACKET); | |
460 | } | |
461 | ||
16d6f994 | 462 | static const char *framework_defaults [] = |
94d1613b MS |
463 | { |
464 | "/System/Library/Frameworks", | |
465 | "/Library/Frameworks", | |
94d1613b MS |
466 | }; |
467 | ||
3dd53121 AP |
468 | /* Register the GNU objective-C runtime include path if STDINC. */ |
469 | ||
470 | void | |
471 | darwin_register_objc_includes (const char *sysroot, const char *iprefix, | |
472 | int stdinc) | |
473 | { | |
474 | const char *fname; | |
475 | size_t len; | |
476 | /* We do not do anything if we do not want the standard includes. */ | |
477 | if (!stdinc) | |
478 | return; | |
16d6f994 | 479 | |
3dd53121 | 480 | fname = GCC_INCLUDE_DIR "-gnu-runtime"; |
16d6f994 | 481 | |
3dd53121 AP |
482 | /* Register the GNU OBJC runtime include path if we are compiling OBJC |
483 | with GNU-runtime. */ | |
484 | ||
485 | if (c_dialect_objc () && !flag_next_runtime) | |
486 | { | |
487 | char *str; | |
488 | /* See if our directory starts with the standard prefix. | |
112cdef5 | 489 | "Translate" them, i.e. replace /usr/local/lib/gcc... with |
3dd53121 AP |
490 | IPREFIX and search them first. */ |
491 | if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0 && !sysroot | |
492 | && !strncmp (fname, cpp_GCC_INCLUDE_DIR, len)) | |
493 | { | |
494 | str = concat (iprefix, fname + len, NULL); | |
495 | /* FIXME: wrap the headers for C++awareness. */ | |
496 | add_path (str, SYSTEM, /*c++aware=*/false, false); | |
497 | } | |
16d6f994 | 498 | |
3dd53121 AP |
499 | /* Should this directory start with the sysroot? */ |
500 | if (sysroot) | |
501 | str = concat (sysroot, fname, NULL); | |
502 | else | |
503 | str = update_path (fname, ""); | |
16d6f994 | 504 | |
3dd53121 AP |
505 | add_path (str, SYSTEM, /*c++aware=*/false, false); |
506 | } | |
507 | } | |
508 | ||
94d1613b MS |
509 | |
510 | /* Register all the system framework paths if STDINC is true and setup | |
511 | the missing_header callback for subframework searching if any | |
512 | frameworks had been registered. */ | |
513 | ||
514 | void | |
479ec1d1 | 515 | darwin_register_frameworks (const char *sysroot, |
3dd53121 | 516 | const char *iprefix ATTRIBUTE_UNUSED, int stdinc) |
94d1613b MS |
517 | { |
518 | if (stdinc) | |
519 | { | |
520 | size_t i; | |
521 | ||
522 | /* Setup default search path for frameworks. */ | |
523 | for (i=0; i<sizeof (framework_defaults)/sizeof(const char *); ++i) | |
524 | { | |
479ec1d1 DP |
525 | char *str; |
526 | if (sysroot) | |
527 | str = concat (sysroot, xstrdup (framework_defaults [i]), NULL); | |
528 | else | |
529 | str = xstrdup (framework_defaults[i]); | |
94d1613b | 530 | /* System Framework headers are cxx aware. */ |
479ec1d1 | 531 | add_system_framework_path (str); |
94d1613b MS |
532 | } |
533 | } | |
534 | ||
535 | if (using_frameworks) | |
536 | cpp_get_callbacks (parse_in)->missing_header = find_subframework_header; | |
537 | } | |
538 | ||
539 | /* Search for HEADER in context dependent way. The return value is | |
540 | the malloced name of a header to try and open, if any, or NULL | |
541 | otherwise. This is called after normal header lookup processing | |
542 | fails to find a header. We search each file in the include stack, | |
543 | using FUNC, starting from the most deeply nested include and | |
544 | finishing with the main input file. We stop searching when FUNC | |
0e40b5f2 | 545 | returns nonzero. */ |
94d1613b MS |
546 | |
547 | static const char* | |
e3c287c9 | 548 | find_subframework_header (cpp_reader *pfile, const char *header, cpp_dir **dirp) |
94d1613b MS |
549 | { |
550 | const char *fname = header; | |
551 | struct cpp_buffer *b; | |
552 | const char *n; | |
553 | ||
554 | for (b = cpp_get_buffer (pfile); | |
555 | b && cpp_get_file (b) && cpp_get_path (cpp_get_file (b)); | |
556 | b = cpp_get_prev (b)) | |
557 | { | |
558 | n = find_subframework_file (fname, cpp_get_path (cpp_get_file (b))); | |
559 | if (n) | |
e3c287c9 MS |
560 | { |
561 | /* Logically, the place where we found the subframework is | |
562 | the place where we found the Framework that contains the | |
563 | subframework. This is useful for tracking wether or not | |
564 | we are in a system header. */ | |
565 | *dirp = cpp_get_dir (cpp_get_file (b)); | |
566 | return n; | |
567 | } | |
94d1613b MS |
568 | } |
569 | ||
570 | return 0; | |
571 | } | |
ed5b9f96 GK |
572 | |
573 | /* Return the value of darwin_macosx_version_min suitable for the | |
574 | __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro, | |
e46b55d0 GK |
575 | so '10.4.2' becomes 1040. The lowest digit is always zero. |
576 | Print a warning if the version number can't be understood. */ | |
ed5b9f96 GK |
577 | static const char * |
578 | version_as_macro (void) | |
579 | { | |
580 | static char result[] = "1000"; | |
16d6f994 | 581 | |
ed5b9f96 GK |
582 | if (strncmp (darwin_macosx_version_min, "10.", 3) != 0) |
583 | goto fail; | |
584 | if (! ISDIGIT (darwin_macosx_version_min[3])) | |
585 | goto fail; | |
586 | result[2] = darwin_macosx_version_min[3]; | |
e46b55d0 GK |
587 | if (darwin_macosx_version_min[4] != '\0' |
588 | && darwin_macosx_version_min[4] != '.') | |
589 | goto fail; | |
16d6f994 | 590 | |
ed5b9f96 | 591 | return result; |
16d6f994 | 592 | |
ed5b9f96 | 593 | fail: |
d8a07487 | 594 | error ("unknown value %qs of -mmacosx-version-min", |
ed5b9f96 GK |
595 | darwin_macosx_version_min); |
596 | return "1000"; | |
597 | } | |
598 | ||
599 | /* Define additional CPP flags for Darwin. */ | |
600 | ||
601 | #define builtin_define(TXT) cpp_define (pfile, TXT) | |
602 | ||
603 | void | |
604 | darwin_cpp_builtins (cpp_reader *pfile) | |
605 | { | |
606 | builtin_define ("__MACH__"); | |
607 | builtin_define ("__APPLE__"); | |
608 | ||
609 | /* __APPLE_CC__ is defined as some old Apple include files expect it | |
610 | to be defined and won't work if it isn't. */ | |
611 | builtin_define_with_value ("__APPLE_CC__", "1", false); | |
612 | ||
26705988 IS |
613 | if (darwin_constant_cfstrings) |
614 | builtin_define ("__CONSTANT_CFSTRINGS__"); | |
615 | ||
e4cad568 GK |
616 | builtin_define_with_value ("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", |
617 | version_as_macro(), false); | |
560d6bd5 IS |
618 | |
619 | /* Since we do not (at 4.6) support ObjC gc for the NeXT runtime, the | |
620 | following will cause a syntax error if one tries to compile gc attributed | |
621 | items. However, without this, NeXT system headers cannot be parsed | |
622 | properly (on systems >= darwin 9). */ | |
623 | if (flag_objc_gc) | |
624 | { | |
625 | builtin_define ("__strong=__attribute__((objc_gc(strong)))"); | |
626 | builtin_define ("__weak=__attribute__((objc_gc(weak)))"); | |
627 | builtin_define ("__OBJC_GC__"); | |
628 | } | |
629 | else | |
630 | { | |
631 | builtin_define ("__strong="); | |
632 | builtin_define ("__weak="); | |
633 | } | |
d764a8e6 IS |
634 | |
635 | if (flag_objc_abi == 2) | |
636 | builtin_define ("__OBJC2__"); | |
ed5b9f96 | 637 | } |
1f1d5130 MS |
638 | |
639 | /* Handle C family front-end options. */ | |
640 | ||
641 | static bool | |
642 | handle_c_option (size_t code, | |
643 | const char *arg, | |
644 | int value ATTRIBUTE_UNUSED) | |
645 | { | |
646 | switch (code) | |
647 | { | |
648 | default: | |
649 | /* Unrecognized options that we said we'd handle turn into | |
650 | errors if not listed here. */ | |
651 | return false; | |
652 | ||
653 | case OPT_iframework: | |
654 | add_system_framework_path (xstrdup (arg)); | |
655 | break; | |
c40ce8f3 MS |
656 | |
657 | case OPT_fapple_kext: | |
658 | ; | |
1f1d5130 MS |
659 | } |
660 | ||
661 | /* We recognized the option. */ | |
662 | return true; | |
663 | } | |
664 | ||
26705988 | 665 | /* Allow ObjC* access to CFStrings. */ |
acce4e77 | 666 | static tree |
26705988 IS |
667 | darwin_objc_construct_string (tree str) |
668 | { | |
669 | if (!darwin_constant_cfstrings) | |
670 | { | |
671 | /* Even though we are not using CFStrings, place our literal | |
672 | into the cfstring_htab hash table, so that the | |
673 | darwin_constant_cfstring_p() function will see it. */ | |
674 | darwin_enter_string_into_cfstring_table (str); | |
675 | /* Fall back to NSConstantString. */ | |
676 | return NULL_TREE; | |
677 | } | |
678 | ||
679 | return darwin_build_constant_cfstring (str); | |
680 | } | |
91ebb981 IS |
681 | |
682 | /* The string ref type is created as CFStringRef by <CFBase.h> therefore, we | |
683 | must match for it explicitly, since it's outside the gcc code. */ | |
684 | ||
acce4e77 | 685 | static bool |
91ebb981 IS |
686 | darwin_cfstring_ref_p (const_tree strp) |
687 | { | |
688 | tree tn; | |
689 | if (!strp || TREE_CODE (strp) != POINTER_TYPE) | |
690 | return false; | |
691 | ||
692 | tn = TYPE_NAME (strp); | |
693 | if (tn) | |
694 | tn = DECL_NAME (tn); | |
695 | return (tn | |
696 | && IDENTIFIER_POINTER (tn) | |
697 | && !strncmp (IDENTIFIER_POINTER (tn), "CFStringRef", 8)); | |
698 | } | |
699 | ||
700 | /* At present the behavior of this is undefined and it does nothing. */ | |
acce4e77 | 701 | static void |
91ebb981 IS |
702 | darwin_check_cfstring_format_arg (tree ARG_UNUSED (format_arg), |
703 | tree ARG_UNUSED (args_list)) | |
704 | { | |
705 | } | |
706 | ||
707 | /* The extra format types we recognize. */ | |
3ee44df5 | 708 | EXPORTED_CONST format_kind_info darwin_additional_format_types[] = { |
91ebb981 IS |
709 | { "CFString", NULL, NULL, NULL, NULL, |
710 | NULL, NULL, | |
711 | FMT_FLAG_ARG_CONVERT|FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL, 0, 0, 0, 0, 0, 0, | |
712 | NULL, NULL | |
713 | } | |
714 | }; | |
acce4e77 | 715 | |
70f42967 SB |
716 | |
717 | /* Support routines to dump the class references for NeXT ABI v1, aka | |
718 | 32-bits ObjC-2.0, as top-level asms. | |
719 | The following two functions should only be called from | |
720 | objc/objc-next-runtime-abi-01.c. */ | |
721 | ||
722 | static void | |
723 | darwin_objc_declare_unresolved_class_reference (const char *name) | |
724 | { | |
725 | const char *lazy_reference = ".lazy_reference\t"; | |
726 | const char *hard_reference = ".reference\t"; | |
727 | const char *reference = MACHOPIC_INDIRECT ? lazy_reference : hard_reference; | |
728 | size_t len = strlen (reference) + strlen(name) + 2; | |
729 | char *buf = (char *) alloca (len); | |
730 | ||
731 | gcc_checking_assert (!strncmp (name, ".objc_class_name_", 17)); | |
732 | ||
733 | snprintf (buf, len, "%s%s", reference, name); | |
734 | add_asm_node (build_string (strlen (buf), buf)); | |
735 | } | |
736 | ||
737 | static void | |
738 | darwin_objc_declare_class_definition (const char *name) | |
739 | { | |
740 | const char *xname = targetm.strip_name_encoding (name); | |
741 | size_t len = strlen (xname) + 7 + 5; | |
742 | char *buf = (char *) alloca (len); | |
743 | ||
744 | gcc_checking_assert (!strncmp (name, ".objc_class_name_", 17) | |
745 | || !strncmp (name, "*.objc_category_name_", 21)); | |
746 | ||
747 | /* Mimic default_globalize_label. */ | |
748 | snprintf (buf, len, ".globl\t%s", xname); | |
749 | add_asm_node (build_string (strlen (buf), buf)); | |
750 | ||
751 | snprintf (buf, len, "%s = 0", xname); | |
752 | add_asm_node (build_string (strlen (buf), buf)); | |
753 | } | |
754 | ||
755 | #undef TARGET_HANDLE_C_OPTION | |
acce4e77 JM |
756 | #define TARGET_HANDLE_C_OPTION handle_c_option |
757 | ||
70f42967 | 758 | #undef TARGET_OBJC_CONSTRUCT_STRING_OBJECT |
acce4e77 JM |
759 | #define TARGET_OBJC_CONSTRUCT_STRING_OBJECT darwin_objc_construct_string |
760 | ||
70f42967 SB |
761 | #undef TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE |
762 | #define TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE \ | |
763 | darwin_objc_declare_unresolved_class_reference | |
764 | ||
765 | #undef TARGET_OBJC_DECLARE_CLASS_DEFINITION | |
766 | #define TARGET_OBJC_DECLARE_CLASS_DEFINITION \ | |
767 | darwin_objc_declare_class_definition | |
768 | ||
769 | #undef TARGET_STRING_OBJECT_REF_TYPE_P | |
acce4e77 JM |
770 | #define TARGET_STRING_OBJECT_REF_TYPE_P darwin_cfstring_ref_p |
771 | ||
772 | #undef TARGET_CHECK_STRING_OBJECT_FORMAT_ARG | |
773 | #define TARGET_CHECK_STRING_OBJECT_FORMAT_ARG darwin_check_cfstring_format_arg | |
774 | ||
775 | struct gcc_targetcm targetcm = TARGETCM_INITIALIZER; |