summaryrefslogtreecommitdiff
path: root/command_line/CmdLine/Src/Callbacks/CLCompilerLinkerDropin_V10.cpp
blob: 070bc07344a368778471e2f2978dc33440bda22c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
#include "cmdline.h"
#include "plugin_internal.h"

extern char STSbuf[256];

CWResult UCBCachePrecompiledHeader(CWPluginContext context, const CWFileSpec *filespec, CWMemHandle pchhandle) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBCachePrecompiledHeader");

    OSSpec spec;
    Handle handle;
    OS_FSSpec_To_OSSpec(filespec, &spec);
    UCBSecretDetachHandle(context, pchhandle, &handle);
    CacheIncludeFile(&spec, handle, 1);
    return cwNoErr;
}

CWResult UCBLoadObjectData(CWPluginContext context, SInt32 whichfile, CWMemHandle *objectdata) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBLoadObjectData");

    File *file = Files_GetFile(&gTarg->files, whichfile);
    if (!file)
        return cwErrUnknownFile;

    if (file->objectdata) {
        UCBSecretAttachHandle(context, file->objectdata, objectdata);
        return cwNoErr;
    } else {
        return cwErrRequestFailed;
    }
}

CWResult UCBStoreObjectData(CWPluginContext context, SInt32 whichfile, CWObjectData *object) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBStoreObjectData");

    if (CheckForUserBreak())
        return cwErrUserCanceled;

    File *filedata = Files_GetFile(&gTarg->files, whichfile);
    if (!filedata)
        return cwErrUnknownFile;

    if (!object->objectfile) {
        Handle objecthand;
        Handle browsehand;
        UCBSecretDetachHandle(context, object->objectdata, &objecthand);
        UCBSecretDetachHandle(context, object->browsedata, &browsehand);
        filedata->objectdata = objecthand;
        filedata->browsedata = browsehand;
        UCBSecretAttachHandle(context, objecthand, &object->objectdata);
        UCBSecretAttachHandle(context, browsehand, &object->browsedata);
    } else {
        if (filedata->outfileowner && filedata->outfileowner != CmdLineStageMask_Cg) {
#line 240
            DO_INTERNAL_ERROR("Cannot store object file spec for '%s'\n", filedata->srcfilename);
        }
        OS_FSSpec_To_OSSpec(object->objectfile, &filedata->outfss);
        filedata->wroteToDisk |= CmdLineStageMask_Cg;
    }

    filedata->codesize = object->codesize;
    filedata->udatasize = object->udatasize;
    filedata->idatasize = object->idatasize;
    filedata->compiledlines = object->compiledlines;
    if (filedata->dropinflags & kGeneratesrsrcs)
        filedata->hasresources = 1;
    else
        filedata->hasobjectcode = 1;
    filedata->recompileDependents = object->dependencyCount && object->interfaceChanged;
    OS_GetTime(&filedata->outmoddate);
    if (object->reserved1)
        filedata->filetype = object->reserved1;

    if (object->reserved2) {
        char *newname = reinterpret_cast<char *>(object->reserved2);
        CWFileInfo fi;
        if (OS_MakeSpec(newname, &filedata->srcfss, NULL) || OS_Status(&filedata->srcfss)) {
            fi.fullsearch = 1;
            fi.dependencyType = cwNoDependency;
            fi.isdependentoffile = -1;
            fi.suppressload = 1;
            if (UCBFindAndLoadFile(context, newname, &fi) == cwNoErr) {
                OS_FSSpec_To_OSSpec(&fi.filespec, &filedata->srcfss);
            } else {
                char *fnptr = OS_GetFileNamePtr(newname);
                if (fnptr != newname) {
                    fi.fullsearch = 1;
                    fi.dependencyType = cwNoDependency;
                    fi.isdependentoffile = -1;
                    fi.suppressload = 1;
                    if (UCBFindAndLoadFile(context, fnptr, &fi) == cwNoErr) {
                        OS_FSSpec_To_OSSpec(&fi.filespec, &filedata->srcfss);
                    }
                }
            }
        }
    }

    return cwNoErr;
}

CWResult UCBFreeObjectData(CWPluginContext context, SInt32 whichfile, CWMemHandle objectdata) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBFreeObjectData");

    File *file = Files_GetFile(&gTarg->files, whichfile);
    if (!file)
        return cwErrUnknownFile;

    if (file->objectdata) {
        DisposeHandle(file->objectdata);
        file->objectdata = NULL;
        return cwNoErr;
    } else {
        return cwErrInvalidParameter;
    }
}

CWResult UCBDisplayLines(CWPluginContext context, SInt32 nlines) {
    ShowWorking(12);

    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBDisplayLines");

    if (CheckForUserBreak())
        return cwErrUserCanceled;
    else
        return cwNoErr;
}

CWResult UCBBeginSubCompile(CWPluginContext context, SInt32 whichfile, CWPluginContext *subContext) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBBeginSubCompile");

#line 372
    DO_INTERNAL_ERROR("UCBBeginSubCompile not implemented");
    return cwErrRequestFailed;
}

CWResult UCBEndSubCompile(CWPluginContext subContext) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBEndSubCompile");

#line 384
    DO_INTERNAL_ERROR("UCBEndSubCompile not implemented");
    return cwErrRequestFailed;
}

CWResult UCBGetPrecompiledHeaderSpec(CWPluginContext context, CWFileSpec *pchspec, const char *intarget) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBGetPrecompiledHeaderSpec");

    CWCompilerLinkerContext *c;
    int err;
    OSSpec outfss;
    File *file;
    const CWObjectFlags *cof;
    char target[256];

    if (context->pluginType == CWDROPINCOMPILERTYPE || context->pluginType == CWDROPINLINKERTYPE)
        c = static_cast<CWCompilerLinkerContext *>(context);
    else
        return cwErrInvalidCallback;

    file = Files_GetFile(&gTarg->files, c->whichfile);
#line 420
    OPTION_ASSERT(file != NULL);

    cof = Plugin_CL_GetObjectFlags(file->compiler);
    if (!file->outfilename[0]) {
        if (intarget) {
            if (optsCompiler.canonicalIncludes)
                strcpy(target, intarget);
            else if (OS_CanonPath(intarget, target) != noErr)
                return cwErrInvalidParameter;

            err = OS_MakeSpecWithPath(&file->srcfss.path, target, 0, &outfss);
            if (err) {
                CLReportOSError(CLStr97, err, target);
                return cwErrRequestFailed;
            }

            if (!file->outfileowner || file->outfileowner == CmdLineStageMask_Cg) {
                file->outfileowner = CmdLineStageMask_Cg;
                OS_SpecToStringRelative(&outfss, NULL, file->outfilename, sizeof(file->outfilename));
            }

            if (optsCmdLine.verbose)
                CLReport(CLStr16, "precompiled ", OS_SpecToStringRelative(&outfss, NULL, STSbuf, sizeof(STSbuf)));
        } else {
            OS_MakeSpecWithPath(&gTarg->outputDirectory, file->srcfilename, optsCompiler.relPathInOutputDir == 0, &outfss);
            OS_NameSpecSetExtension(&outfss.name, optsCompiler.pchFileExt[0] ? optsCompiler.pchFileExt : cof->pchFileExt);

            if (!file->outfileowner || file->outfileowner == CmdLineStageMask_Cg) {
                file->outfileowner = CmdLineStageMask_Cg;
                OS_NameSpecToString(&outfss.name, file->outfilename, sizeof(file->outfilename));
            }

            CLReport(CLStr59, OS_SpecToStringRelative(&outfss, NULL, STSbuf, sizeof(STSbuf)));
        }

        OS_OSSpec_To_FSSpec(&outfss, pchspec);
    } else {
        err = OS_MakeSpecWithPath(&gTarg->outputDirectory, file->outfilename, 0, &outfss);
        if (err) {
            CLReportOSError(CLStr97, err, file->outfilename);
            return cwErrRequestFailed;
        }

        OS_OSSpec_To_FSSpec(&outfss, pchspec);

        if (intarget)
            CLReport(CLStr60, OS_SpecToStringRelative(&outfss, NULL, STSbuf, sizeof(STSbuf)), intarget);
    }

    return cwNoErr;
}

CWResult UCBGetResourceFile(CWPluginContext context, CWFileSpec *filespec) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBGetResourceFile");

#line 514
    DO_INTERNAL_ERROR("UCBGetResourceFile not implemented");
    return cwErrRequestFailed;
}

CWResult UCBPutResourceFile(CWPluginContext context, const char *prompt, const char *name, CWFileSpec *filespec) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBPutResourceFile");

#line 529
    DO_INTERNAL_ERROR("UCBPutResourceFile not implemented");
    return cwErrRequestFailed;
}

static int UnitNameToSBMName(OSSpec *spec, File *srcfile) {
    const CWObjectFlags *cof;
    int err;

    cof = Plugin_CL_GetObjectFlags(srcfile->compiler);
    err = OS_NameSpecChangeExtension(
            &spec->name,
            cof->pchFileExt ? cof->pchFileExt : ".sbm",
            cof->pchFileExt ? (cof->pchFileExt[0] == '.') : 0
            );
    return err;
}

CWResult UCBLookUpUnit(CWPluginContext context, const char *name, Boolean isdependency, const void **unitdata, SInt32 *unitdatalength) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBLookUpUnit");

    CWFileInfo includeinfo;
    OSSpec unitspec;
    OSSpec sbmspec;
    time_t unittime;
    UInt32 unitmactime;
    char sbmpath[256];
    int err;
    CWCompilerLinkerContext *c;
    File *srcfile;
    File *sbmfile;

    if (context->pluginType == CWDROPINCOMPILERTYPE || context->pluginType == CWDROPINLINKERTYPE)
        c = static_cast<CWCompilerLinkerContext *>(context);
    else
        return cwErrInvalidCallback;

    srcfile = Files_GetFile(&gTarg->files, c->whichfile);
#line 591
    OPTION_ASSERT(srcfile != NULL);

    *unitdata = NULL;
    *unitdatalength = 0;

    if (optsCompiler.sbmState == OptsCompilerSbmState_1 || optsCompiler.sbmState == OptsCompilerSbmState_3) {
        if (clState.pluginDebug)
            CLPrint("UCBLookUpUnit:  sbmState == sbmRebuild or sbmClean; failing\n");
        return cwErrSBMNotFound;
    }

    includeinfo.fullsearch = 1;
    includeinfo.dependencyType = isdependency ? cwNormalDependency : cwNoDependency;
    includeinfo.isdependentoffile = -1;
    includeinfo.suppressload = 1;
    if (UCBFindAndLoadFile(context, name, &includeinfo) != cwNoErr) {
        if (clState.pluginDebug)
            CLPrint("UCBLookUpUnit:  could not find source '%s'; failing\n", name);
        return cwErrFileNotFound;
    }

    OS_FSSpec_To_OSSpec(&includeinfo.filespec, &unitspec);
    sbmspec = unitspec;
    err = UnitNameToSBMName(&sbmspec, srcfile);
    if (err) {
        if (clState.pluginDebug)
            CLPrint("UCBLookUpUnit:  could not make precompiled unit spec for '%s' (%s)\n", name, OS_GetErrText(err));
        return cwErrRequestFailed;
    }

    if (optsCompiler.sbmPath[0]) {
        sbmspec.path = clState.sbmPathSpec;
        OS_SpecToString(&sbmspec, sbmpath, sizeof(sbmpath));
        if (clState.pluginDebug)
            CLPrint("UCBLookUpUnit:  Only looking at '%s'\n", sbmpath);
    } else {
        OS_NameSpecToString(&sbmspec.name, sbmpath, sizeof(sbmpath));
        if (clState.pluginDebug)
            CLPrint("UCBLookUpUnit:  searching paths for '%s'\n", sbmpath);
    }

    includeinfo.fullsearch = 1;
    includeinfo.dependencyType = isdependency ? cwNormalDependency : cwNoDependency;
    includeinfo.isdependentoffile = -1;
    includeinfo.suppressload = 0;
    if (UCBFindAndLoadFile(context, sbmpath, &includeinfo) != cwNoErr || !includeinfo.filedata) {
        if (clState.pluginDebug)
            CLPrint("UCBLookUpUnit:  could not find or load precompiled unit file '%s'; failing\n", sbmpath);
        return cwErrFileNotFound;
    }

    OS_FSSpec_To_OSSpec(&includeinfo.filespec, &sbmspec);
    if (includeinfo.filedatatype != cwFileTypePrecompiledHeader) {
        CLPrint("UCBLookUpUnit:  file '%s' does not appear to be precompiled\n", OS_SpecToString(&sbmspec, STSbuf, sizeof(STSbuf)));
        UCBReleaseFileText(context, includeinfo.filedata);
        return cwErrRequestFailed;
    }

    OS_GetFileTime(&unitspec, NULL, &unittime);
    OS_TimeToMac(unittime, &unitmactime);
    if (unitmactime != *reinterpret_cast<const UInt32 *>(includeinfo.filedata)) {
        if (clState.pluginDebug)
            CLPrint(
                    "UCBLookUpUnit:  file '%s' does not have internal timestamp that matches source unit's timestamp (0x%8x != 0x%8x)\n",
                    OS_SpecToString(&sbmspec, STSbuf, sizeof(STSbuf)),
                    unitmactime,
                    *reinterpret_cast<const UInt32 *>(includeinfo.filedata));
        UCBReleaseFileText(context, includeinfo.filedata);
        return cwErrRequestFailed;
    }

    sbmfile = Files_FindFile(&gTarg->pchs, &sbmspec);
    if (!sbmfile) {
        sbmfile = File_New();
        sbmfile->srcfss = unitspec;
        OS_SpecToString(&sbmfile->srcfss, sbmfile->srcfilename, sizeof(sbmfile->srcfilename));
        sbmfile->outfss = sbmspec;
        OS_SpecToString(&sbmfile->outfss, sbmfile->outfilename, sizeof(sbmfile->outfilename));
        sbmfile->compiler = srcfile->compiler;
        sbmfile->outfileowner = CmdLineStageMask_Cg;
        sbmfile->writeToDisk = srcfile->writeToDisk;
        sbmfile->dropinflags = srcfile->dropinflags;
        sbmfile->objectflags = srcfile->objectflags;
        sbmfile->mappingflags = srcfile->mappingflags;
        Deps_Initialize(&sbmfile->deps, &gTarg->incls);
        if (!Files_AddFile(&gTarg->pchs, sbmfile))
            return cwErrRequestFailed;
    }

    if (clState.pluginDebug)
        CLPrint("UCBLookUpUnit:  success for '%s'\n", name);

    if (optsCmdLine.verbose)
        CLReport(CLStr62, "unit symbol table", OS_SpecToStringRelative(&sbmspec, NULL, STSbuf, sizeof(STSbuf)));

    *unitdata = includeinfo.filedata;
    *unitdatalength = includeinfo.filedatalength;
    return cwNoErr;
}

CWResult UCBSBMfiles(CWPluginContext context, short libref) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBSBMfiles");
    return cwNoErr;
}

CWResult UCBStoreUnit(CWPluginContext context, const char *inunitname, CWMemHandle unitdata, CWDependencyTag dependencytag) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBStoreUnit");

    char unitname[256];
    OSSpec sbmspec;
    int err;
    Handle h;
    OSHandle unithand;
    OSFileHandle fhand;
    CWCompilerLinkerContext *c;
    File *srcfile;

    if (optsCompiler.canonicalIncludes) {
        strcpy(unitname, inunitname);
    } else if (OS_CanonPath(inunitname, unitname)) {
        return cwErrInvalidParameter;
    }

    if (optsCompiler.sbmState == OptsCompilerSbmState_0 || optsCompiler.sbmState == OptsCompilerSbmState_1) {
        if (context->pluginType == CWDROPINCOMPILERTYPE || context->pluginType == CWDROPINLINKERTYPE)
            c = static_cast<CWCompilerLinkerContext *>(context);
        else
            return cwErrInvalidCallback;

        srcfile = Files_GetFile(&gTarg->files, c->whichfile);
#line 791
        OPTION_ASSERT(srcfile != NULL);

        if (optsCompiler.sbmPath[0]) {
            err = OS_MakeSpecWithPath(&clState.sbmPathSpec, unitname, 1, &sbmspec);
            if (err) {
                if (clState.pluginDebug)
                    CLPrint("UCBStoreUnit:  '%s' is a bad unit name (%s)\n", unitname, OS_GetErrText(err));
                return cwErrInvalidParameter;
            }
        } else {
            err = OS_MakeFileSpec(unitname, &sbmspec);
            if (err) {
                if (clState.pluginDebug)
                    CLPrint("UCBStoreUnit:  '%s' is a bad filename (%s)\n", unitname, OS_GetErrText(err));
                return cwErrInvalidParameter;
            }
        }

        err = UnitNameToSBMName(&sbmspec, srcfile);
        if (err) {
            if (clState.pluginDebug)
                CLPrint("UCBStoreUnit:  could not make precompiled unit form of '%s' (%s)\n", unitname, OS_GetErrText(err));
            return cwErrInvalidParameter;
        }

        if (optsCmdLine.verbose)
            CLReport(CLStr61, "unit symbol table", OS_SpecToStringRelative(&sbmspec, NULL, STSbuf, sizeof(STSbuf)));

        UCBSecretDetachHandle(context, unitdata, &h);
        OS_DestroyMacHandle(h, &unithand);
        err = OS_NewFileHandle(&sbmspec, &unithand, 1, &fhand);
        if (err || (err = OS_FreeFileHandle(&fhand))) {
            CLReportOSError(CLStr18, err, "precompiled unit", OS_SpecToStringRelative(&sbmspec, NULL, STSbuf, sizeof(STSbuf)));
            return cwErrRequestFailed;
        }
    }

    return cwNoErr;
}

CWResult UCBReleaseUnit(CWPluginContext context, void *unitdata) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBReleaseUnit");

    if (!unitdata)
        return cwErrRequestFailed;
    return UCBReleaseFileText(context, static_cast<const char *>(unitdata));
}

CWResult UCBUnitNameToFileName(CWPluginContext context, const char *unitname, char *filename) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBUnitNameToFileName");

    strcpy(filename, unitname);
    if (!OS_EqualPath(filename + strlen(filename) - 2, ".p"))
        strcat(filename, ".p");
    return cwNoErr;
}

CWResult UCBOSAlert(CWPluginContext context, const char *message, OSErr errorcode) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBOSAlert");
    if (CheckForUserBreak())
        return cwErrUserCanceled;

    char errormessage[256];
    GetSysErrText(errorcode, errormessage);
    CLStyledMessageDispatch(
            static_cast<shellContextType *>(context->shellContext)->plugin,
            NULL,
            errorcode,
            CLStyledMessageDispatch_Type4,
            "%\n(%)\n",
            message ? message : "",
            errormessage
    );
    return cwNoErr;
}

CWResult UCBOSErrorMessage(CWPluginContext context, const char *message, OSErr errorcode) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBOSErrorMessage");
    if (!errorcode)
        return cwNoErr;
    if (CheckForUserBreak())
        return cwErrUserCanceled;

    char errormessage[256];
    GetSysErrText(errorcode, errormessage);
    CLStyledMessageDispatch(
            static_cast<shellContextType *>(context->shellContext)->plugin,
            NULL,
            errorcode,
            CLStyledMessageDispatch_Type4,
            "%\n%\n",
            message ? message : "",
            errormessage
            );
    return cwNoErr;
}

CWResult UCBGetModifiedFiles(CWPluginContext context, SInt32 *modifiedFileCount, const SInt32 **modifiedFiles) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBGetModifiedFiles");

    *modifiedFileCount = 0;
#line 949
    DO_INTERNAL_ERROR("CWGetModifiedFiles not implemented!\n");
    return cwNoErr;
}

CWResult UCBGetSuggestedObjectFileSpec(CWPluginContext context, SInt32 whichfile, CWFileSpec *fileSpec) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBGetSuggestedObjectFileSpec");

    File *file;
    if (!(file = Files_GetFile(&gTarg->files, whichfile)))
        return cwErrUnknownFile;

    if (!GetOutputFile(file, CmdLineStageMask_Cg))
        return cwErrRequestFailed;

    OS_OSSpec_To_FSSpec(&file->outfss, fileSpec);
    return cwNoErr;
}

CWResult UCBGetStoredObjectFileSpec(CWPluginContext context, SInt32 whichfile, CWFileSpec *fileSpec) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBGetStoredObjectFileSpec");

    File *file;
    if (!(file = Files_GetFile(&gTarg->files, whichfile)))
        return cwErrUnknownFile;
    if (file->outfileowner != CmdLineStageMask_Cg) {
#line 993
        DO_INTERNAL_ERROR("Lost stored object file spec for '%s'\n", file->srcfilename);
        return cwErrRequestFailed;
    } else {
        OS_OSSpec_To_FSSpec(&file->outfss, fileSpec);
        return cwNoErr;
    }
}

CWResult UCBGetFrameworkCount(CWPluginContext context, SInt32 *frameworkCount) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBGetFrameworkCount");

    *frameworkCount = Frameworks_GetCount();
    return cwNoErr;
}

CWResult UCBGetFrameworkInfo(CWPluginContext context, SInt32 whichFramework, CWFrameworkInfo *frameworkInfo) {
    if (optsCmdLine.verbose > 3)
        CLPrint("Callback: %s\n", "UCBGetFrameworkCount");

    Paths_FWInfo *info;
    if ((info = Frameworks_GetInfo(whichFramework))) {
        OS_OSSpec_To_FSSpec(&info->fileSpec, &frameworkInfo->fileSpec);
        strncpy(frameworkInfo->version, info->version.s, sizeof(frameworkInfo->version));
        return cwNoErr;
    }

    return cwErrFileNotFound;
}

CWCompilerLinkerCallbacks sCompilerLinkerCallbacks = {
        UCBCachePrecompiledHeader,
        UCBLoadObjectData,
        UCBStoreObjectData,
        UCBFreeObjectData,
        UCBDisplayLines,
        UCBBeginSubCompile,
        UCBEndSubCompile,
        UCBGetPrecompiledHeaderSpec,
        UCBGetResourceFile,
        UCBPutResourceFile,
        UCBLookUpUnit,
        UCBSBMfiles,
        UCBStoreUnit,
        UCBReleaseUnit,
        UCBUnitNameToFileName,
        UCBOSErrorMessage,
        UCBOSAlert,
        UCBGetModifiedFiles,
        UCBGetSuggestedObjectFileSpec,
        UCBGetStoredObjectFileSpec,
        NULL,
        UCBGetFrameworkCount,
        UCBGetFrameworkInfo
};

CWCompilerLinkerContext::CWCompilerLinkerContext()
        :
        CWPluginPrivateContext(clState.plugintype, sizeof(CWCompilerLinkerContext)) {
    targetinfo = static_cast<CWTargetInfo *>(xmalloc("context", sizeof(CWTargetInfo)));
    memset(targetinfo, 0, sizeof(CWTargetInfo));

    if (gTarg) {
        targetinfo->targetCPU = gTarg->cpu;
        targetinfo->targetOS = gTarg->os;
    } else {
        targetinfo->targetOS = targetOSAny;
        targetinfo->targetCPU = targetCPUAny;
    }

    whichfile = 0;
    memset(&sourcefile, 0, sizeof(sourcefile));
    sourcetext = NULL;
    sourcetextsize = 0;

    preprocess = 0;
    autoprecompile = 0;
    precompile = 0;
    cachingPCH = 0;
    debuginfo = 0;
    fileID = 0;
    memset(&browseoptions, 0, sizeof(browseoptions));
    reserved = NULL;
    sequenceID = 0;
    parentPB = NULL;
    targetStorage = NULL;
    texthandle = NULL;
    memset(&targetinfo_V7, 0, sizeof(targetinfo_V7));

    callbacks = &sCompilerLinkerCallbacks;
}

CWCompilerLinkerContext::~CWCompilerLinkerContext() {
    xfree(targetinfo);
}