| File: | src/forg.c |
| Warning: | line 160, column 3 Value stored to 'text' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | #include "axlobs.h" |
| 2 | #include "forg.h" |
| 3 | #include "spesym.h" |
| 4 | #include "store.h" |
| 5 | #include "comsg.h" |
| 6 | #include "strops.h" |
| 7 | #include "util.h" |
| 8 | |
| 9 | /***************************************************************************** |
| 10 | * |
| 11 | * :: Foreign origins |
| 12 | * |
| 13 | ****************************************************************************/ |
| 14 | |
| 15 | localstatic ForeignOrigin forgAlloc (FoamProtoTag, String); |
| 16 | |
| 17 | static ForeignOrigin stdOrig[FOAM_PROTO_LIMIT - FOAM_PROTO_START]; |
| 18 | |
| 19 | localstatic ForeignOrigin |
| 20 | forgAlloc(FoamProtoTag ptag, String file) |
| 21 | { |
| 22 | ForeignOrigin forg = (ForeignOrigin) stoAlloc(OB_Other0, sizeof(*forg)); |
| 23 | |
| 24 | forg->protocol = ptag; |
| 25 | forg->file = file ? strCopy(file) : NULL((void*)0); |
| 26 | |
| 27 | return forg; |
| 28 | } |
| 29 | |
| 30 | ForeignOrigin |
| 31 | forgNew(FoamProtoTag ptag, String file) |
| 32 | { |
| 33 | static Bool stdOrigAreInit = false((int) 0); |
| 34 | static ForeignOrigin oldOrig = NULL((void*)0); |
| 35 | |
| 36 | if (!stdOrigAreInit) { |
| 37 | Length i; |
| 38 | for (i = 0; i < FOAM_PROTO_LIMIT - FOAM_PROTO_START; i += 1) |
| 39 | stdOrig[i] = forgAlloc((FoamProtoTag)(i) + FOAM_PROTO_START, NULL((void*)0)); |
| 40 | stdOrigAreInit = true1; |
| 41 | } |
| 42 | |
| 43 | if (file == NULL((void*)0)) |
| 44 | return stdOrig[ptag - FOAM_PROTO_START]; |
| 45 | |
| 46 | if (oldOrig && ptag==oldOrig->protocol && strEqual(file,oldOrig->file)) |
| 47 | return oldOrig; |
| 48 | |
| 49 | return oldOrig = forgAlloc(ptag, file); |
| 50 | } |
| 51 | |
| 52 | ForeignOrigin |
| 53 | forgFrAbSyn(AbSyn origin) |
| 54 | { |
| 55 | Symbol psym; |
| 56 | FoamProtoTag ptag; |
| 57 | String file = NULL((void*)0); |
| 58 | |
| 59 | if (!origin) |
| 60 | return forgNew(FOAM_Proto_Other, file); |
| 61 | |
| 62 | if (abHasTag(origin, AB_Apply)((origin)->abHdr.tag == (AB_Apply))) { |
| 63 | AbSyn *argv = abApplyArgv(origin)((origin)->abApply.argv); |
| 64 | if (abApplyArgc(origin)(((origin)->abHdr.argc)-1)==1 && abHasTag(argv[0],AB_LitString)((argv[0])->abHdr.tag == (AB_LitString))) |
| 65 | file = argv[0]->abLitString.str; |
| 66 | |
| 67 | origin = origin->abApply.op; |
| 68 | } |
| 69 | |
| 70 | psym = abHasTag(origin, AB_Id)((origin)->abHdr.tag == (AB_Id)) ? origin->abId.sym : NULL((void*)0); |
| 71 | |
| 72 | if (!psym || psym == ssymForeign) |
| 73 | ptag = FOAM_Proto_Other; |
| 74 | |
| 75 | else if (psym == ssymFortran) |
| 76 | ptag = FOAM_Proto_Fortran; |
| 77 | |
| 78 | else if (psym == ssymC) |
| 79 | ptag = FOAM_Proto_C; |
| 80 | |
| 81 | else if (psym == ssymLisp) |
| 82 | ptag = FOAM_Proto_Lisp; |
| 83 | |
| 84 | else if (psym == ssymJava) |
| 85 | ptag = FOAM_Proto_Java; |
| 86 | |
| 87 | else if (psym == ssymBuiltin) |
| 88 | ptag = FOAM_Proto_Other; |
| 89 | |
| 90 | else { |
| 91 | comsgWarning(origin, ALDOR_W_ScoNotProtocol131); |
| 92 | ptag = FOAM_Proto_Other; |
| 93 | } |
| 94 | |
| 95 | return forgNew(ptag, file); |
| 96 | } |
| 97 | |
| 98 | Bool |
| 99 | forgEqual(ForeignOrigin f1, ForeignOrigin f2) |
| 100 | { |
| 101 | if (f1->protocol != f2->protocol) |
| 102 | return false((int) 0); |
| 103 | |
| 104 | if (f1->file == NULL((void*)0) && f2->file == NULL((void*)0)) |
| 105 | return true1; |
| 106 | if (f1->file != NULL((void*)0) && f2->file != NULL((void*)0)) |
| 107 | return strEqual(f1->file, f2->file); |
| 108 | return false((int) 0); |
| 109 | } |
| 110 | |
| 111 | void |
| 112 | forgFree(ForeignOrigin forg) |
| 113 | { |
| 114 | /* Not possible to free these as there is a |
| 115 | * pre-initialised cache, and some last-value caching |
| 116 | */ |
| 117 | } |
| 118 | |
| 119 | AInt |
| 120 | forgHash(ForeignOrigin forg) |
| 121 | { |
| 122 | if (forg->file == NULL((void*)0)) { |
| 123 | return forg->protocol; |
| 124 | } |
| 125 | return hashCombine(forg->protocol, strHash(forg->file))((((forg->protocol) ^ ((forg->protocol) << 8)) + ( (strHash(forg->file)) + 200041)) & 0x3FFFFFFF); |
| 126 | } |
| 127 | |
| 128 | ForeignOrigin |
| 129 | forgFrBuffer(Buffer buf) |
| 130 | { |
| 131 | FoamProtoTag tag = (FoamProtoTag) bufGetHInt(buf); |
| 132 | String file = NULL((void*)0); |
| 133 | Bool flg; |
| 134 | flg = bufGetByte(buf); |
| 135 | if (flg) { |
| 136 | file = bufRdString(buf); |
| 137 | } |
| 138 | |
| 139 | return forgNew(tag, file); |
| 140 | } |
| 141 | |
| 142 | void |
| 143 | forgToBuffer(Buffer buf, ForeignOrigin forg) |
| 144 | { |
| 145 | bufPutHInt(buf, forg->protocol); |
| 146 | bufPutByte(buf, forg->file != NULL((void*)0)); |
| 147 | if (forg->file != NULL((void*)0)) { |
| 148 | bufWrString(buf, forg->file); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void |
| 153 | forgBufferSkip(Buffer buf) |
| 154 | { |
| 155 | String text; |
| 156 | Bool flg; |
| 157 | bufGetHInt(buf); |
| 158 | flg = bufGetByte(buf); |
| 159 | if (flg) { |
| 160 | text = bufRdString(buf); |
Value stored to 'text' is never read | |
| 161 | } |
| 162 | } |