Bug Summary

File:src/java/javacode.c
Warning:line 1306, column 2
Value stored to 'aClss' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name javacode.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/kfp/aldor/aldor/aldor/src -fcoverage-compilation-dir=/home/kfp/aldor/aldor/aldor/src -resource-dir /usr/local/lib/clang/18 -D PACKAGE_NAME="aldor" -D PACKAGE_TARNAME="aldor" -D PACKAGE_VERSION="1.4.0" -D PACKAGE_STRING="aldor 1.4.0" -D PACKAGE_BUGREPORT="aldor@xinutec.org" -D PACKAGE_URL="" -D PACKAGE="aldor" -D VERSION="1.4.0" -D YYTEXT_POINTER=1 -D HAVE_STDIO_H=1 -D HAVE_STDLIB_H=1 -D HAVE_STRING_H=1 -D HAVE_INTTYPES_H=1 -D HAVE_STDINT_H=1 -D HAVE_STRINGS_H=1 -D HAVE_SYS_STAT_H=1 -D HAVE_SYS_TYPES_H=1 -D HAVE_UNISTD_H=1 -D STDC_HEADERS=1 -D HAVE_LIBREADLINE=1 -D HAVE_READLINE_READLINE_H=1 -D HAVE_READLINE_HISTORY=1 -D HAVE_READLINE_HISTORY_H=1 -D USE_GLOOP_SHELL=1 -D GENERATOR_COROUTINES=0 -D HAVE_DLFCN_H=1 -D LT_OBJDIR=".libs/" -I . -D VCSVERSION="2c53e759f1e00e345f8b172e7139debda72fda13" -internal-isystem /usr/local/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-empty-body -Wno-enum-compare -Wno-missing-field-initializers -Wno-unused -Wno-unused-parameter -Wno-error=format -Wno-error=type-limits -Wno-error=strict-aliasing -Wno-sign-compare -Wno-error=shift-negative-value -Wno-error=clobbered -std=c99 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2026-01-15-223856-845667-1 -x c java/javacode.c
1#include "javacode.h"
2#include "javaobj.h"
3#include "sexpr.h"
4#include "util.h"
5
6enum jc_clss_enum {
7 JCO_CLSS_START,
8 JCO_CLSS_String = JCO_CLSS_START,
9 JCO_CLSS_Character,
10 JCO_CLSS_Integer,
11 JCO_CLSS_Float,
12 JCO_CLSS_Double,
13 JCO_CLSS_Keyword,
14 JCO_CLSS_Id,
15 JCO_CLSS_CommaSeq,
16 JCO_CLSS_SpaceSeq,
17 JCO_CLSS_NLSeq,
18 JCO_CLSS_Seq,
19 JCO_CLSS_Parens,
20 JCO_CLSS_Braces,
21 JCO_CLSS_SqBrackets,
22 JCO_CLSS_ABrackets,
23 JCO_CLSS_ImportedId,
24 JCO_CLSS_ImportedStatic,
25 JCO_CLSS_Annotation,
26 JCO_CLSS_Class,
27 JCO_CLSS_JavaDoc,
28 JCO_CLSS_Comment,
29 JCO_CLSS_Method,
30 JCO_CLSS_Declaration,
31 JCO_CLSS_Statement,
32 JCO_CLSS_File,
33
34 JCO_CLSS_If,
35 JCO_CLSS_While,
36 JCO_CLSS_Switch,
37 JCO_CLSS_Case,
38 JCO_CLSS_Block,
39 JCO_CLSS_Try,
40 JCO_CLSS_Catch,
41 JCO_CLSS_Finally,
42
43 JCO_CLSS_ArrRef,
44 JCO_CLSS_MemRef,
45 JCO_CLSS_Cast,
46
47 JCO_CLSS_Apply,
48 JCO_CLSS_Construct,
49
50 JCO_CLSS_Not,
51 JCO_CLSS_LogAnd,
52 JCO_CLSS_LogOr,
53 JCO_CLSS_And,
54 JCO_CLSS_Or,
55 JCO_CLSS_XOr,
56 JCO_CLSS_Equals,
57 JCO_CLSS_NEquals,
58 JCO_CLSS_Assign,
59 JCO_CLSS_Plus,
60 JCO_CLSS_Minus,
61 JCO_CLSS_Times,
62 JCO_CLSS_Divide,
63 JCO_CLSS_Modulo,
64 JCO_CLSS_LT,
65 JCO_CLSS_LE,
66 JCO_CLSS_GT,
67 JCO_CLSS_GE,
68 JCO_CLSS_Negate,
69 JCO_CLSS_ShiftUp,
70 JCO_CLSS_ShiftDn,
71
72 JCO_CLSS_Conditional,
73 JCO_CLSSS_END
74};
75
76enum JavaKeywordTag {
77JK_Abstract,
78JK_Assert,
79JK_Boolean,
80JK_Break,
81JK_Byte,
82JK_Case,
83JK_Catch,
84JK_Char,
85JK_Class,
86JK_Const,
87JK_Continue,
88JK_Default,
89JK_Do,
90JK_Double,
91JK_Else,
92JK_Enum,
93JK_Extends,
94JK_Final,
95JK_Finally,
96JK_Float,
97JK_For,
98JK_Goto,
99JK_If,
100JK_Implements,
101JK_Import,
102JK_Instanceof,
103JK_Int,
104JK_Interface,
105JK_Long,
106JK_Native,
107JK_New,
108JK_Package,
109JK_Private,
110JK_Protected,
111JK_Public,
112JK_Return,
113JK_Short,
114JK_Static,
115JK_Strictfp,
116JK_Super,
117JK_Switch,
118JK_Synchronized,
119JK_This,
120JK_Throw,
121JK_Throws,
122JK_Transient,
123JK_Try,
124JK_Void,
125JK_Volatile,
126JK_While,
127JK_False,
128JK_Null,
129JK_True,
130JK_END
131};
132
133
134typedef struct javaKeyword {
135 int id;
136 String text;
137} *JavaKeyword;
138
139struct javaKeyword jkKeywords[] = {
140 { JK_Abstract, "abstract" },
141 { JK_Assert, "assert" },
142 { JK_Boolean, "boolean" },
143 { JK_Break, "break" },
144 { JK_Byte, "byte" },
145 { JK_Case, "case" },
146 { JK_Catch, "catch" },
147 { JK_Char, "char" },
148 { JK_Class, "class" },
149 { JK_Const, "const" },
150 { JK_Continue, "continue" },
151 { JK_Default, "default" },
152 { JK_Do, "do" },
153 { JK_Double, "double" },
154 { JK_Else, "else" },
155 { JK_Enum, "enum" },
156 { JK_Extends, "extends" },
157 { JK_Final, "final" },
158 { JK_Finally, "finally" },
159 { JK_Float, "float" },
160 { JK_For, "for" },
161 { JK_Goto, "goto" },
162 { JK_If, "if" },
163 { JK_Implements, "implements" },
164 { JK_Import, "import" },
165 { JK_Instanceof, "instanceof" },
166 { JK_Int, "int" },
167 { JK_Interface, "interface" },
168 { JK_Long, "long" },
169 { JK_Native, "native" },
170 { JK_New, "new" },
171 { JK_Package, "package" },
172 { JK_Private, "private" },
173 { JK_Protected, "protected" },
174 { JK_Public, "public" },
175 { JK_Return, "return" },
176 { JK_Short, "short" },
177 { JK_Static, "static" },
178 { JK_Strictfp, "strictfp" },
179 { JK_Super, "super" },
180 { JK_Switch, "switch" },
181 { JK_Synchronized, "synchronized" },
182 { JK_This, "this" },
183 { JK_Throw, "throw" },
184 { JK_Throws, "throws" },
185 { JK_Transient, "transient" },
186 { JK_Try, "try" },
187 { JK_Void, "void" },
188 { JK_Volatile, "volatile" },
189 { JK_While, "while" },
190 { JK_False, "false" },
191 { JK_Null, "null" },
192 { JK_True, "true" },
193};
194
195typedef Enum(jc_clss_enum)enum jc_clss_enum JcClassId;
196
197localstatic JWriteFn jcAnnotationPrint;
198localstatic JWriteFn jcApplyPrint;
199localstatic JWriteFn jcARefPrint;
200localstatic JWriteFn jcBinOpPrint;
201localstatic JWriteFn jcBlockHdrPrint;
202localstatic JWriteFn jcBlockKeywordPrint;
203localstatic JWriteFn jcBlockPrint;
204localstatic JWriteFn jcCasePrint;
205localstatic JWriteFn jcCastPrint;
206localstatic JWriteFn jcClassPrint;
207localstatic JWriteFn jcCommentPrint;
208localstatic JWriteFn jcCondPrint;
209localstatic JWriteFn jcConstructPrint;
210localstatic JWriteFn jcDeclarationPrint;
211localstatic JWriteFn jcIdPrint;
212localstatic JWriteFn jcImportPrint;
213localstatic JWriteFn jcIntegerPrint;
214localstatic JWriteFn jcJavaDocPrint;
215localstatic JWriteFn jcKeywordPrint;
216localstatic JWriteFn jcMethodPrint;
217localstatic JWriteFn jcParenPrint;
218localstatic JWriteFn jcSequencePrint;
219localstatic JWriteFn jcStatementPrint;
220localstatic JWriteFn jcFilePrint;
221localstatic JWriteFn jcStringPrint;
222localstatic JWriteFn jcUnaryOpPrint;
223
224localstatic JSExprFn jcCommentSExpr;
225localstatic JSExprFn jcIdSExpr;
226localstatic JSExprFn jcImportSExpr;
227localstatic JSExprFn jcIntegerSExpr;
228localstatic JSExprFn jcKeywordSExpr;
229localstatic JSExprFn jcStringSExpr;
230
231localstatic JavaCodeList jc0CreateModifiers(int modifiers);
232localstatic void jc0PrintWithParens(JavaCodePContext ctxt, JavaCodeClass oclss, JavaCode arg);
233localstatic Bool jc0NeedsParens(JavaCodeClass c1, JavaCodeClass c2);
234localstatic String jc0EscapeString(String s, Bool terminal);
235localstatic Bool jcBlockHdrIndent(JavaCode code);
236localstatic JavaCode jcBinaryOp(JavaCodeClass c, JavaCode lhs, JavaCode rhs);
237
238/*
239Operator Description Associativity
24015. () Parentheses (grouping) left-to-right
24114. ++ -- Unary postincrement/postdecrement right-to-left
24213 ++ -- Unary preincrement/predecrement right-to-left
243 + - Unary plus/minus
244 ! ~ Unary logical negation/bitwise complement
245 (type) Unary cast (change type)
24612. * / % Multiplication/division/modulus left-to-right
24711. + - Addition/subtraction left-to-right
24810. << >> Bitwise shift left, Bitwise shift right left-to-right
2499. < <= Relational less than/less than or equal to left-to-right
250 > >= Relational greater than/greater than or equal to
251 instanceof Type comparison
2528 == != Relational is equal to/is not equal to left-to-right
2537 & Bitwise AND left-to-right
2546 ^ Bitwise exclusive OR left-to-right
2555. | Bitwise inclusive OR left-to-right
2564. && Logical AND left-to-right
2573. || Logical OR left-to-right
2582. ?: Ternary conditional right-to-left
2591. = Assignment right-to-left
260 += -= Addition/subtraction assignment
261 *= /= Multiplication/division assignment
262 %= &= Modulus/bitwise AND assignment
263 ^= |= Bitwise exclusive/inclusive OR assignment
264 <<= >>= Bitwise shift left/right assignment
265
266*/
267static struct jclss jcClss[] = {
268 { JCO_CLSS_String, jcStringPrint, jcStringSExpr, "string", "\""},
269 { JCO_CLSS_Character, jcStringPrint, jcStringSExpr, "char", "'"},
270 { JCO_CLSS_Integer, jcIntegerPrint, jcIntegerSExpr, "integer"},
271 { JCO_CLSS_Float, jcIntegerPrint, jcIntegerSExpr, "float"},
272 { JCO_CLSS_Double, jcIntegerPrint, jcIntegerSExpr, "double"},
273 { JCO_CLSS_Keyword, jcKeywordPrint, jcKeywordSExpr, "keyword"},
274 { JCO_CLSS_Id, jcIdPrint, jcIdSExpr, "id"},
275
276 { JCO_CLSS_CommaSeq, jcSequencePrint,jcNodeSExpr, "commaseq", ", "},
277 { JCO_CLSS_SpaceSeq, jcSequencePrint,jcNodeSExpr, "spaceseq", " "},
278 { JCO_CLSS_NLSeq, jcSequencePrint,jcNodeSExpr, "nlseq", "\n"},
279 { JCO_CLSS_Seq, jcSequencePrint,jcNodeSExpr, "seq", ""},
280 { JCO_CLSS_Parens, jcParenPrint, jcNodeSExpr, "paren", "()", 15, JCO_NONE },
281 { JCO_CLSS_Braces, jcParenPrint, jcNodeSExpr, "braces", "{}", 15, JCO_NONE },
282 { JCO_CLSS_SqBrackets, jcParenPrint, jcNodeSExpr, "sqbracket", "[]", 15, JCO_NONE },
283 { JCO_CLSS_ABrackets, jcParenPrint, jcNodeSExpr, "angle", "<>" },
284 { JCO_CLSS_ImportedId, jcImportPrint, jcImportSExpr,"importid", 0},
285 { JCO_CLSS_ImportedStatic,
286 jcImportPrint, jcImportSExpr, "static-importid", 0},
287 { JCO_CLSS_Annotation, jcAnnotationPrint, jcNodeSExpr, "annotation", 0},
288 { JCO_CLSS_Class, jcClassPrint, jcNodeSExpr, "class", 0},
289 { JCO_CLSS_JavaDoc, jcJavaDocPrint, jcCommentSExpr, "javadoc", 0},
290 { JCO_CLSS_Comment, jcCommentPrint, jcCommentSExpr, "comment", 0},
291 { JCO_CLSS_Method, jcMethodPrint, jcNodeSExpr, "method", 0},
292 { JCO_CLSS_Declaration,jcDeclarationPrint, jcNodeSExpr,"declaration", 0},
293 { JCO_CLSS_Statement, jcStatementPrint, jcNodeSExpr, "statement", 0},
294 { JCO_CLSS_File, jcFilePrint, jcNodeSExpr, "file", 0},
295
296 { JCO_CLSS_If, jcBlockHdrPrint, jcNodeSExpr, "if", "if"},
297 { JCO_CLSS_While, jcBlockHdrPrint, jcNodeSExpr, "while", "while"},
298 { JCO_CLSS_Switch, jcBlockHdrPrint, jcNodeSExpr, "switch", "switch"},
299 { JCO_CLSS_Case, jcCasePrint, jcNodeSExpr, "case", "case"},
300 { JCO_CLSS_Block, jcBlockPrint, jcNodeSExpr, "block"},
301 { JCO_CLSS_Try, jcBlockKeywordPrint, jcNodeSExpr, "try", "try"},
302 { JCO_CLSS_Catch, jcBlockHdrPrint, jcNodeSExpr, "catch", "catch"},
303 { JCO_CLSS_Finally, jcBlockKeywordPrint, jcNodeSExpr, "finally", "finally"},
304
305 { JCO_CLSS_ArrRef, jcARefPrint, jcNodeSExpr, "arrayref", 0, 20, JCO_NONE},
306 { JCO_CLSS_MemRef, jcBinOpPrint, jcNodeSExpr, "memref", ".", 20, JCO_NONE},
307 { JCO_CLSS_Cast, jcCastPrint, jcNodeSExpr, "cast", " ", 16, JCO_NONE },
308
309 { JCO_CLSS_Apply, jcApplyPrint, jcNodeSExpr, "apply", 0, 20, JCO_NONE},
310 { JCO_CLSS_Construct, jcConstructPrint, jcNodeSExpr, "new", 0, 20, JCO_NONE},
311
312 { JCO_CLSS_Not, jcUnaryOpPrint,jcNodeSExpr, "not", "!", 13,JCO_LR },
313 { JCO_CLSS_LogAnd, jcBinOpPrint, jcNodeSExpr, "and", " && ", 4, JCO_LR },
314 { JCO_CLSS_LogOr, jcBinOpPrint, jcNodeSExpr, "or", " || ", 4, JCO_LR },
315 { JCO_CLSS_And, jcBinOpPrint, jcNodeSExpr, "and", " & ", 7, JCO_LR },
316 { JCO_CLSS_Or, jcBinOpPrint, jcNodeSExpr, "or", " | ", 7, JCO_LR },
317 { JCO_CLSS_XOr, jcBinOpPrint, jcNodeSExpr, "xor", " ^ ", 7, JCO_LR },
318 { JCO_CLSS_Equals, jcBinOpPrint, jcNodeSExpr, "equal", " == ", 8, JCO_LR },
319 { JCO_CLSS_NEquals, jcBinOpPrint, jcNodeSExpr, "nequal", " != ", 8, JCO_LR },
320 { JCO_CLSS_Assign, jcBinOpPrint, jcNodeSExpr, "assign", " = ", 1, JCO_RL },
321 { JCO_CLSS_Plus, jcBinOpPrint, jcNodeSExpr, "plus", " + ", 11,JCO_LR },
322 { JCO_CLSS_Minus, jcBinOpPrint, jcNodeSExpr, "minus", " - ", 11,JCO_LR },
323 { JCO_CLSS_Times, jcBinOpPrint, jcNodeSExpr, "times", "*", 12,JCO_LR },
324 { JCO_CLSS_Divide, jcBinOpPrint, jcNodeSExpr, "divide", "/", 12,JCO_LR },
325 { JCO_CLSS_Modulo, jcBinOpPrint, jcNodeSExpr, "modulo", "%", 12,JCO_LR },
326 { JCO_CLSS_LT, jcBinOpPrint, jcNodeSExpr, "lt", " < ", 9, JCO_LR },
327 { JCO_CLSS_LE, jcBinOpPrint, jcNodeSExpr, "le", " <= ", 9, JCO_LR },
328 { JCO_CLSS_GT, jcBinOpPrint, jcNodeSExpr, "gt", " > ", 9, JCO_LR },
329 { JCO_CLSS_GE, jcBinOpPrint, jcNodeSExpr, "ge", " >= ", 9, JCO_LR },
330 { JCO_CLSS_Negate, jcUnaryOpPrint,jcNodeSExpr, "negate", "-", 13,JCO_LR },
331 { JCO_CLSS_ShiftUp, jcBinOpPrint, jcNodeSExpr, "shiftup", "<<", 10,JCO_LR },
332 { JCO_CLSS_ShiftDn, jcBinOpPrint, jcNodeSExpr, "shiftdn", ">>", 10,JCO_LR },
333
334 { JCO_CLSS_Conditional,jcCondPrint,jcNodeSExpr, "cond", 0, 2, JCO_RL },
335};
336
337void
338jcInit()
339{
340 int i;
341 for (i=0; i<JK_END; i++) {
342 if (jkKeywords[i].id != i)
343 bug("Java is a mess");
344 }
345}
346
347
348
349localstatic JavaCodeClass jc0ClassObj(JcClassId);
350
351JavaCode
352jcClass(int modifiers, String comment,
353 JavaCodeList annotations,
354 JavaCode id, JavaCode superclass,
355 JavaCodeList extendList, JavaCodeList body)
356{
357 JavaCodeList jcmods = jc0CreateModifiers(modifiers);
358
359 JavaCode clss = jcoNew(jc0ClassObj(JCO_CLSS_Class),
360 6,
361 jcNLSeq(annotations),
362 jcSpaceSeq(jcmods),
363 id, superclass,
364 extendList == listNil(JavaCode)((JavaCodeList) 0) ? NULL((void*)0) : jcCommaSeq(extendList),
365 jcNLSeq(body));
366 if (comment == NULL((void*)0))
367 return clss;
368
369 return jcDocumented(comment, clss);
370}
371
372void
373jcClassPrint(JavaCodePContext ctxt, JavaCode clss)
374{
375 JavaCode annotations = jcoArgv(clss)[0];
376 JavaCode modifiers = jcoArgv(clss)[1];
377 JavaCode id = jcoArgv(clss)[2];
378 JavaCode superclass = jcoArgv(clss)[3];
379 JavaCode implList = jcoArgv(clss)[4];
380 JavaCode body = jcoArgv(clss)[5];
381
382 jcoWrite(ctxt, annotations);
383 jcoPContextWrite(ctxt, "\n");
384 if (modifiers != NULL((void*)0) && jcoArgc(modifiers) > 0) {
385 jcoWrite(ctxt, modifiers);
386 jcoPContextWrite(ctxt, " ");
387 }
388 jcoPContextWrite(ctxt, "class ");
389 jcoWrite(ctxt, id);
390 if (superclass != NULL((void*)0)) {
391 jcoPContextWrite(ctxt, " extends ");
392 jcoWrite(ctxt, superclass);
393 }
394 if (implList != NULL((void*)0)) {
395 jcoPContextWrite(ctxt, " implements ");
396 jcoWrite(ctxt, implList);
397 }
398 jcoPContextWrite(ctxt, " {");
399 jcoPContextNewlineIndent(ctxt);
400 jcoWrite(ctxt, body);
401 jcoPContextNewlineUnindent(ctxt);
402 jcoPContextWrite(ctxt, "}");
403}
404
405/*
406 * :: Methods (actually, could be 'member' instead)
407 */
408JavaCode
409jcMethod(int modifiers, String comment,
410 JavaCode retnType,
411 JavaCode id, JavaCodeList genArgs,
412 JavaCodeList args,
413 JavaCodeList exns, JavaCode body)
414{
415 JavaCode meth = jcoNew(jc0ClassObj(JCO_CLSS_Method),
416 2,
417 jcDeclaration(modifiers, retnType,
418 id, listNil(JavaCode)((JavaCodeList) 0),
419 jcParens(jcCommaSeq(args)), exns),
420 body);
421 return meth;
422}
423
424JavaCode
425jcConstructor(int modifiers, String comment,
426 JavaCode id, JavaCodeList genArgs,
427 JavaCodeList args,
428 JavaCodeList exns, JavaCode body)
429{
430 JavaCode meth = jcoNew(jc0ClassObj(JCO_CLSS_Method),
431 2,
432 jcDeclaration(modifiers, jcSpaceSeqV(0),
433 id, listNil(JavaCode)((JavaCodeList) 0),
434 jcParens(jcCommaSeq(args)), exns),
435 body);
436 return meth;
437}
438
439localstatic void
440jcMethodPrint(JavaCodePContext ctxt, JavaCode code)
441{
442 JavaCode decl = jcoArgv(code)[0];
443 JavaCode body = jcoArgv(code)[1];
444
445 jcoWrite(ctxt, decl);
446 jcoPContextWrite(ctxt, " {");
447 jcoPContextNewlineIndent(ctxt);
448 jcoWrite(ctxt, body);
449 jcoPContextNewlineUnindent(ctxt);
450 jcoPContextWrite(ctxt, "}");
451 jcoPContextNewline(ctxt);
452}
453
454
455/*
456 * :: Declarations
457 */
458
459JavaCode
460jcDeclaration(int modifiers,
461 JavaCode retnType,
462 JavaCode id, JavaCodeList genArgs,
463 JavaCode args,
464 JavaCodeList exns)
465{
466 JavaCodeList l = listNil(JavaCode)((JavaCodeList) 0);
467 JavaCodeList jcmods = jc0CreateModifiers(modifiers);
468
469 l = listCons(JavaCode)(JavaCode_listPointer->Cons)(jcSpaceSeq(jcmods), l);
470 l = listCons(JavaCode)(JavaCode_listPointer->Cons)(retnType, l);
471 l = listCons(JavaCode)(JavaCode_listPointer->Cons)(id, l);
472 if (args != NULL((void*)0)) {
473 l = listCons(JavaCode)(JavaCode_listPointer->Cons)(args, l);
474 l = listCons(JavaCode)(JavaCode_listPointer->Cons)(jcCommaSeq(exns), l);
475 }
476 l = listNReverse(JavaCode)(JavaCode_listPointer->NReverse)(l);
477 return jcoNewFrList(jc0ClassObj(JCO_CLSS_Declaration), l);
478}
479
480JavaCode
481jcMemberDecl(int modifiers, JavaCode type, JavaCode id)
482{
483 return jcDeclaration(modifiers, type, id, 0, 0, 0);
484}
485
486JavaCode
487jcParamDecl(int modifiers, JavaCode type, JavaCode id)
488{
489 return jcDeclaration(modifiers, type, id, 0, 0, 0);
490}
491
492JavaCode
493jcLocalDecl(int modifiers, JavaCode type, JavaCode id)
494{
495 return jcDeclaration(modifiers, type, id, 0, 0, 0);
496}
497
498JavaCode
499jcInitialisation(int modifiers, JavaCode type, JavaCode id, JavaCode value)
500{
501 return jcParamDecl(modifiers, type, jcAssign(id, value));
502}
503
504
505localstatic void
506jcDeclarationPrint(JavaCodePContext ctxt, JavaCode code)
507{
508 JavaCode mods = jcoArgv(code)[0];
509 JavaCode retn = jcoArgv(code)[1];
510 JavaCode name = jcoArgv(code)[2];
511
512 if (!jcoIsEmpty(mods)) {
513 jcoWrite(ctxt, mods);
514 jcoPContextWrite(ctxt, " ");
515 }
516 if (!jcoIsEmpty(retn)) {
517 jcoWrite(ctxt, retn);
518 jcoPContextWrite(ctxt, " ");
519 }
520 jcoWrite(ctxt, name);
521 if (jcoArgc(code) > 3) {
522 JavaCode args = jcoArgv(code)[3];
523 JavaCode exns = jcoArgv(code)[4];
524 jcoWrite(ctxt, args);
525 if (jcoArgc(exns) > 0) {
526 jcoPContextWrite(ctxt, " throws ");
527 jcoWrite(ctxt, exns);
528 }
529
530 }
531
532}
533
534/*
535 * :: Annotations
536 */
537
538JavaCode
539jcAnnotation(JavaCode annotationClass, JavaCodeList arguments)
540{
541 return jcoNew(jc0ClassObj(JCO_CLSS_Annotation),
542 2, annotationClass,
543 jcParens(jcCommaSeq(arguments)));
544}
545
546localstatic void
547jcAnnotationPrint(JavaCodePContext ctxt, JavaCode code)
548{
549 jcoPContextWrite(ctxt, "@");
550 jcoWrite(ctxt, jcoArgv(code)[0]);
551 jcoWrite(ctxt, jcoArgv(code)[1]);
552}
553
554/*
555 * :: Function application
556 */
557
558JavaCode
559jcApply(JavaCode c, JavaCodeList args)
560{
561 return jcoNew(jc0ClassObj(JCO_CLSS_Apply), 2, c, jcParens(jcCommaSeq(args)));
562}
563
564JavaCode
565jcApplyV(JavaCode c, int n, ...)
566{
567 va_list argp;
568 JavaCode jc;
569 va_start(argp, n)__builtin_va_start(argp, n);
570 jc = jcApplyP(c, n, argp);
571 va_end(argp)__builtin_va_end(argp);
572 return jc;
573}
574
575JavaCode
576jcApplyP(JavaCode c, int n, va_list argp)
577{
578 return jcoNew(jc0ClassObj(JCO_CLSS_Apply),
579 2, c, jcParens(jcCommaSeqP(n, argp)));
580}
581
582JavaCode
583jcApplyMethod(JavaCode c, JavaCode id, JavaCodeList args)
584{
585 return jcApply(jcMemRef(c, id), args);
586}
587
588JavaCode
589jcApplyMethodV(JavaCode c, JavaCode id, int n, ...)
590{
591 va_list argp;
592 JavaCode jc;
593
594 va_start(argp, n)__builtin_va_start(argp, n);
595
596 jc = jcApplyP(jcMemRef(c, id), n, argp);
597 va_end(argp)__builtin_va_end(argp);
598 return jc;
599}
600
601localstatic void
602jcApplyPrint(JavaCodePContext ctxt, JavaCode code)
603{
604 jcoWrite(ctxt, jcoArgv(code)[0]);
605 jcoWrite(ctxt, jcoArgv(code)[1]);
606}
607
608JavaCode
609jcGenericMethodName(JavaCode methodName, JavaCodeList genArgs)
610{
611 return jcSeqV(2, jcABrackets(jcCommaSeq(genArgs)));
612}
613
614JavaCode
615jcGenericMethodNameV(JavaCode methodName, int n, ...)
616{
617 JavaCode jc;
618 va_list argp;
619 va_start(argp, n)__builtin_va_start(argp, n);
620 jc = jcSeqV(2, jcABrackets(jcCommaSeqP(n, argp)), methodName);
621 va_end(argp)__builtin_va_end(argp);
622 return jc;
623}
624
625
626/*
627 * :: Parens
628 */
629JavaCode
630jcParens(JavaCode args)
631{
632 JavaCode jco = jcoNew(jc0ClassObj(JCO_CLSS_Parens), 1, args);
633 return jco;
634}
635
636JavaCode
637jcBraces(JavaCode args)
638{
639 JavaCode jco = jcoNew(jc0ClassObj(JCO_CLSS_Braces), 1, args);
640 return jco;
641}
642
643JavaCode
644jcSqBrackets(JavaCode args)
645{
646 JavaCode jco = jcoNew(jc0ClassObj(JCO_CLSS_SqBrackets), 1, args);
647 return jco;
648}
649
650JavaCode
651jcABrackets(JavaCode args)
652{
653 JavaCode jco = jcoNew(jc0ClassObj(JCO_CLSS_ABrackets), 1, args);
654 return jco;
655}
656
657localstatic void
658jcParenPrint(JavaCodePContext ctxt, JavaCode code)
659{
660 char s[2] = " ";
661 String txt = jcoClass(code)(((code)->hdr).clss)->txt;
662 s[0]=txt[0];
663 jcoPContextWrite(ctxt, s);
664 jcoWrite(ctxt, jcoArgv(code)[0]);
665 s[0]=txt[1];
666 jcoPContextWrite(ctxt, s);
667}
668
669
670/*
671 * :: Comments
672 */
673JavaCode
674jcDocumented(String comment, JavaCode code)
675{
676 JavaCode doc = jcoNewLiteral(jc0ClassObj(JCO_CLSS_JavaDoc), comment);
677 return jcNLSeqV(2, doc, code);
678}
679
680JavaCode
681jcCommented(String comment, JavaCode code)
682{
683 return jcSpaceSeqV(2, jcComment(comment), code);
684}
685
686JavaCode
687jcComment(String comment)
688{
689 JavaCode jc = jcoNewLiteral(jc0ClassObj(JCO_CLSS_Comment), comment);
690 return jc;
691}
692
693localstatic void
694jcJavaDocPrint(JavaCodePContext ctxt, JavaCode code)
695{
696 String s = strReplace(jcoLiteral(code), "\n", "\n * ");
697 jcoPContextWrite(ctxt, "/**\n * ");
698 jcoPContextWrite(ctxt, s);
699 jcoPContextWrite(ctxt, "\n */");
700 strFree(s);
701}
702
703
704localstatic void
705jcCommentPrint(JavaCodePContext ctxt, JavaCode code)
706{
707 String s = strReplace(jcoLiteral(code), "\n", "\n *");
708 jcoPContextWrite(ctxt, "/* ");
709 jcoPContextWrite(ctxt, s);
710 jcoPContextWrite(ctxt, "*/");
711 strFree(s);
712}
713
714localstatic SExpr
715jcCommentSExpr(JavaCode code)
716{
717 SExpr h = sxiFrSymbol(symIntern(jcoClass(code)->name)symProbe((((code)->hdr).clss)->name, 1 | 2));
718 String s = jc0EscapeString(jcoLiteral(code), false((int) 0));
719 SExpr sx = sxiFrString(s);
720 strFree(s);
721 return sxiList(2, h, sx);
722}
723
724/*
725 * :: Imports
726 */
727
728JavaCode
729jcImportedIdFrString(String str)
730{
731 String p = strLastIndexOf(str, '.');
732 if (p == NULL((void*)0)) {
733 return jcId(strCopy(str));
734 }
735 else {
736 String pkg = strnCopy(str, p - str);
737 String id = strCopy(p+1);
738 return jcImportedId(pkg, id);
739 }
740}
741
742JavaCode
743jcImportedId(String pkg, String name)
744{
745 return jcoNewImport(jc0ClassObj(JCO_CLSS_ImportedId), pkg, listNil(String)((StringList) 0), name, false((int) 0));
746}
747
748
749String
750jcImportedIdName(JavaCode id)
751{
752 return jcoImportId(id);
753}
754
755String
756jcImportedIdPkg(JavaCode id)
757{
758 return jcoImportPkg(id);
759}
760
761
762JavaCode
763jcImportedStaticId(String pkg, String clss, String name)
764{
765 assert(strLastIndexOf(clss, '.') == NULL)do { if (!(strLastIndexOf(clss, '.') == ((void*)0))) _do_assert
(("strLastIndexOf(clss, '.') == NULL"),"java/javacode.c",765)
; } while (0)
;
766 assert(strLastIndexOf(name, '.') == NULL)do { if (!(strLastIndexOf(name, '.') == ((void*)0))) _do_assert
(("strLastIndexOf(name, '.') == NULL"),"java/javacode.c",766)
; } while (0)
;
767
768 return jcoNewImport(jc0ClassObj(JCO_CLSS_ImportedStatic), pkg,
769 listSingleton(String)(String_listPointer->Singleton)(clss), name, false((int) 0));
770}
771
772JavaCode
773jcImportedStaticIdFrString(String str)
774{
775 String p = strLastIndexOf(str, '.');
776 String id = strCopy(p+1);
777 String pkgClss = strnCopy(str, p - str);
778 String dclss = strLastIndexOf(pkgClss, '.');
779 String clss = strCopy(dclss+1);
780 String pkg = strnCopy(pkgClss, dclss - pkgClss);
781
782 return jcImportedStaticId(pkg, clss, id);
783}
784
785String
786jcImportedStaticIdClass(JavaCode importedId)
787{
788 return car(jcoImportPath(importedId))((jcoImportPath(importedId))->first);
789}
790
791String
792jcImportedStaticIdPkg(JavaCode importedId)
793{
794 return jcoImportPkg(importedId);
795}
796
797String
798jcImportedStaticIdName(JavaCode importedId)
799{
800 return jcImportedIdName(importedId);
801}
802
803localstatic void
804jcImportPrint(JavaCodePContext ctxt, JavaCode code)
805{
806 if (jcoImportIsImported(code))
807 jcoPContextWrite(ctxt, jcoImportId(code));
808 else {
809 if (strlen(jcoImportPkg(code)) != 0) {
810 jcoPContextWrite(ctxt, jcoImportPkg(code));
811 jcoPContextWrite(ctxt, ".");
812 }
813 jcoPContextWrite(ctxt, jcoImportId(code));
814 }
815}
816
817localstatic SExpr
818jcImportSExpr(JavaCode code)
819{
820 SExpr sym = sxiFrSymbol(symIntern(jcoClass(code)->name)symProbe((((code)->hdr).clss)->name, 1 | 2));
821 if (jcoImportPkg(code) == NULL((void*)0)) {
822 return sxiList(2, sym, sxiFrString(jcoImportId(code)));
823 }
824 return sxiList(3, sym,
825 sxiFrString(jcoImportPkg(code)),
826 sxiFrString(jcoImportId(code)));
827}
828
829
830/*
831 * :: String literals
832 */
833
834
835JavaCode
836jcLiteralString(String s)
837{
838 return jcoNewLiteral(jc0ClassObj(JCO_CLSS_String),
839 jc0EscapeString(s, false((int) 0)));
840}
841
842JavaCode
843jcLiteralStringWithTerminalChar(String s)
844{
845 return jcoNewLiteral(jc0ClassObj(JCO_CLSS_String),
846 jc0EscapeString(s, true1));
847}
848
849JavaCode
850jcLiteralChar(String s)
851{
852 String t;
853 if (s[0] == '\0')
854 t = strCopy("\\0");
855 else if (s[0] == '\'')
856 t = strCopy("\\'");
857 else if (s[0] == '"')
858 t = strCopy("\\\"");
859 else if (s[0] == '\n')
860 t = strCopy("\\n");
861 else if (s[0] == '\t')
862 t = strCopy("\\t");
863 else if (s[0] == '\\')
864 t = strCopy("\\\\");
865 else if (s[0] == -1)
866 t = strCopy("\\1");
867 else
868 t = strCopy(s);
869
870 return jcoNewLiteral(jc0ClassObj(JCO_CLSS_Character), t);
871}
872
873localstatic void
874jcStringPrint(JavaCodePContext ctxt, JavaCode code)
875{
876 JavaCodeClass thisClss = jcoClass(code)(((code)->hdr).clss);
877 jcoPContextWrite(ctxt, thisClss->txt);
878 jcoPContextWrite(ctxt, jcoLiteral(code));
879 jcoPContextWrite(ctxt, thisClss->txt);
880}
881
882localstatic SExpr
883jcStringSExpr(JavaCode code)
884{
885 String s = jcoLiteral(code);
886 SExpr sx;
887 s = jc0EscapeString(s, false((int) 0));
888 sx = sxiFrString(s);
889 strFree(s);
890 return sx;
891}
892
893/*
894 * :: Numeric literals
895 */
896
897
898JavaCode
899jcLiteralInteger(AInt i)
900{
901 String s = strPrintf("%d", i);
902 return jcoNewLiteral(jc0ClassObj(JCO_CLSS_Integer), s);
903}
904
905JavaCode
906jcLiteralIntegerFrString(String s)
907{
908 return jcoNewLiteral(jc0ClassObj(JCO_CLSS_Integer), s);
909}
910
911JavaCode
912jcLiteralFloatFrString(String s)
913{
914 return jcoNewLiteral(jc0ClassObj(JCO_CLSS_Float), s);
915}
916
917void
918jcIntegerPrint(JavaCodePContext ctxt, JavaCode code)
919{
920 jcoPContextWrite(ctxt, jcoLiteral(code));
921}
922
923localstatic SExpr
924jcIntegerSExpr(JavaCode code)
925{
926 int i = atoi(jcoLiteral(code));
927 return sxiFrInteger(i);
928}
929
930/*
931 * :: Keywords
932 */
933
934
935JavaCode
936jcKeyword(Symbol sym)
937{
938 return jcoNewToken(jc0ClassObj(JCO_CLSS_Keyword), sym);
939}
940
941JavaCode
942jcReturn(JavaCode c)
943{
944 return jcSpaceSeqV(2, jcKeyword(symInternConst("return")symProbe("return", 1)), c);
945}
946
947JavaCode
948jcReturnVoid()
949{
950 return jcKeyword(symInternConst("return")symProbe("return", 1));
951}
952
953
954JavaCode
955jcNull()
956{
957 return jcKeyword(symInternConst("null")symProbe("null", 1));
958}
959
960JavaCode
961jcTrue(String name)
962{
963 return jcKeyword(symInternConst("true")symProbe("true", 1));
964}
965JavaCode
966jcFalse(String name)
967{
968 return jcKeyword(symInternConst("false")symProbe("false", 1));
969}
970
971JavaCode
972jcThis(String name)
973{
974 return jcKeyword(symInternConst("this")symProbe("this", 1));
975}
976
977localstatic SExpr
978jcKeywordSExpr(JavaCode code)
979{
980 return sxiFrSymbol(jcoToken(code));
981}
982
983localstatic void
984jcKeywordPrint(JavaCodePContext ctxt, JavaCode code)
985{
986 jcoPContextWrite(ctxt, symString(jcoToken(code))((jcoToken(code))->str));
987}
988
989/*
990 * :: Ids
991 */
992
993JavaCode
994jcId(String name)
995{
996 return jcoNewLiteral(jc0ClassObj(JCO_CLSS_Id), name);
997}
998
999String
1000jcIdName(JavaCode id)
1001{
1002 return jcoLiteral(id);
1003}
1004
1005localstatic SExpr
1006jcIdSExpr(JavaCode code)
1007{
1008 return sxiFrString(jcoLiteral(code));
1009}
1010
1011void
1012jcIdPrint(JavaCodePContext ctxt, JavaCode code)
1013{
1014 String name = jcoLiteral(code);
1015 jcoPContextWrite(ctxt, name);
1016}
1017
1018
1019/*
1020 * :: Generic id
1021 */
1022JavaCode
1023jcGenericId(JavaCode root, JavaCodeList genArgs)
1024{
1025 return jcSeqV(2, root, jcABrackets(jcCommaSeq(genArgs)));
1026}
1027
1028
1029/*
1030 * :: Constructor Call
1031 */
1032JavaCode
1033jcConstructBase(JavaCode t, JavaCode body)
1034{
1035 return jcoNew(jc0ClassObj(JCO_CLSS_Construct), 2, t, body);
1036}
1037
1038JavaCode
1039jcConstruct(JavaCode t, JavaCodeList args)
1040{
1041 return jcConstructBase(jcApply(t, args), 0);
1042}
1043
1044JavaCode
1045jcConstructSubclass(JavaCode t, JavaCodeList args, JavaCode body)
1046{
1047 return jcConstructBase(jcApply(t, args), body);
1048}
1049
1050JavaCode
1051jcConstructV(JavaCode t, int n, ...)
1052{
1053 JavaCode jc;
1054 va_list argp;
1055
1056 va_start(argp, n)__builtin_va_start(argp, n);
1057 jc = jcConstructBase(jcApplyP(t, n, argp), 0);
1058 va_end(argp)__builtin_va_end(argp);
1059 return jc;
1060}
1061
1062localstatic void
1063jcConstructPrint(JavaCodePContext ctxt, JavaCode t)
1064{
1065 jcoPContextWrite(ctxt, "new ");
1066 jcoWrite(ctxt, jcoArgv(t)[0]);
1067 if (jcoArgv(t)[1] != 0) {
1068 jcoPContextWrite(ctxt, " { ");
1069 jcoPContextNewlineIndent(ctxt);
1070 jcoWrite(ctxt, jcoArgv(t)[1]);
1071 jcoPContextNewlineUnindent(ctxt);
1072 jcoPContextWrite(ctxt, "}");
1073 }
1074}
1075
1076/*
1077 * :: Arrays
1078 */
1079
1080JavaCode
1081jcArrayOf(JavaCode type)
1082{
1083 return jcSpaceSeqV(2, type, jcSqBrackets(jcSpaceSeqV(0)));
1084}
1085
1086JavaCode
1087jcNAry(JavaCode type)
1088{
1089 return jcSpaceSeqV(2, type,
1090 jcKeyword(symInternConst("...")symProbe("...", 1)));
1091}
1092
1093JavaCode
1094jcArrayNew(JavaCode t, JavaCode sz)
1095{
1096 return jcConstructBase(jcArrayRef(t, sz), 0);
1097}
1098
1099JavaCode
1100jcArrayRef(JavaCode arr, JavaCode idx)
1101{
1102 return jcoNew(jc0ClassObj(JCO_CLSS_ArrRef), 2, arr, idx);
1103}
1104
1105void jcARefPrint(JavaCodePContext ctxt, JavaCode code)
1106{
1107 JavaCodeClass thisClss = jcoClass(code)(((code)->hdr).clss);
1108
1109 jc0PrintWithParens(ctxt, thisClss, jcoArgv(code)[0]);
1110 jcoPContextWrite(ctxt, "[");
1111 jcoWrite(ctxt, jcoArgv(code)[1]);
1112 jcoPContextWrite(ctxt, "]");
1113}
1114
1115/*
1116 * :: Binary operations
1117 */
1118
1119JavaCode
1120jcAssign(JavaCode lhs, JavaCode rhs)
1121{
1122 return jcBinaryOp(jc0ClassObj(JCO_CLSS_Assign), lhs, rhs);
1123}
1124
1125JavaCode
1126jcCast(JavaCode lhs, JavaCode rhs)
1127{
1128 return jcBinaryOp(jc0ClassObj(JCO_CLSS_Cast), lhs, rhs);
1129}
1130
1131JavaCode
1132jcMemRef(JavaCode lhs, JavaCode rhs)
1133{
1134 return jcBinaryOp(jc0ClassObj(JCO_CLSS_MemRef), lhs, rhs);
1135}
1136
1137
1138
1139/*
1140 * :: Operations
1141 */
1142typedef JavaCode (*JcOpBuilder)(JavaCodeList l);
1143struct jcOpInfo {
1144 JcOperation op;
1145 JcOpBuilder builder;
1146 JcClassId clsId;
1147};
1148typedef struct jcOpInfo *JcOpInfo;
1149
1150localstatic JavaCode jcOpNot(JavaCodeList l);
1151localstatic JavaCode jcOpNegate(JavaCodeList l);
1152localstatic JavaCode jcOpTimesPlus(JavaCodeList args);
1153
1154localstatic JcOpInfo jc0OpInfo(JcOperation op);
1155
1156
1157struct jcOpInfo JcOpInfoTable[] = {
1158 { JCO_OP_Not, jcOpNot},
1159 { JCO_OP_LogAnd, 0, JCO_CLSS_LogAnd},
1160 { JCO_OP_LogOr, 0, JCO_CLSS_LogOr},
1161 { JCO_OP_And, 0, JCO_CLSS_And},
1162 { JCO_OP_Or, 0, JCO_CLSS_Or},
1163 { JCO_OP_XOr, 0, JCO_CLSS_XOr},
1164 { JCO_OP_Equals, 0, JCO_CLSS_Equals},
1165 { JCO_OP_NEquals, 0, JCO_CLSS_NEquals},
1166 { JCO_OP_Assign, 0, JCO_CLSS_Assign},
1167 { JCO_OP_Plus, 0, JCO_CLSS_Plus},
1168 { JCO_OP_Minus, 0, JCO_CLSS_Minus},
1169 { JCO_OP_Times, 0, JCO_CLSS_Times},
1170 { JCO_OP_Divide, 0, JCO_CLSS_Divide},
1171 { JCO_OP_Modulo, 0, JCO_CLSS_Modulo},
1172 { JCO_OP_LT, 0, JCO_CLSS_LT},
1173 { JCO_OP_LE, 0, JCO_CLSS_LE},
1174 { JCO_OP_GT, 0, JCO_CLSS_GT},
1175 { JCO_OP_GE, 0, JCO_CLSS_GE},
1176 { JCO_OP_Negate, jcOpNegate},
1177 { JCO_OP_TimesPlus, jcOpTimesPlus},
1178 { JCO_OP_ShiftUp, 0, JCO_CLSS_ShiftUp},
1179 { JCO_OP_ShiftDn, 0, JCO_CLSS_ShiftDn},
1180};
1181
1182JavaCode
1183jcOp(JcOperation op, JavaCodeList args)
1184{
1185 JcOpInfo inf = jc0OpInfo(op);
1186 if (inf->builder == 0)
1187 return jcBinaryOp(jc0ClassObj(inf->clsId), car(args)((args)->first), car(cdr(args))((((args)->rest))->first));
1188 else
1189 return inf->builder(args);
1190}
1191
1192JavaCode
1193jcBinOp(JcOperation op, JavaCode e1, JavaCode e2)
1194{
1195 JcOpInfo inf = jc0OpInfo(op);
1196
1197 if (inf->builder == 0)
1198 return jcBinaryOp(jc0ClassObj(inf->clsId), e1, e2);
1199 else
1200 return inf->builder(listList(JavaCode)(JavaCode_listPointer->List)(2, e1, e2));
1201}
1202
1203
1204localstatic JavaCode
1205jcOpNot(JavaCodeList l)
1206{
1207 return jcNot(car(l)((l)->first));
1208}
1209
1210localstatic JavaCode
1211jcOpNegate(JavaCodeList l)
1212{
1213 return jcNegate(car(l)((l)->first));
1214}
1215
1216localstatic JavaCode
1217jcOpTimesPlus(JavaCodeList args)
1218{
1219 JavaCode a1 = car(args)((args)->first);
1220 JavaCode a2 = car(cdr(args))((((args)->rest))->first);
1221 JavaCode a3 = car(cdr(cdr(args)))((((((args)->rest))->rest))->first);
1222
1223 return jcBinaryOp(jc0ClassObj(JCO_CLSS_Plus),
1224 jcBinaryOp(jc0ClassObj(JCO_CLSS_Times), a1, a2),
1225 a3);
1226}
1227
1228
1229localstatic JcOpInfo
1230jc0OpInfo(JcOperation op)
1231{
1232 JcOpInfo inf = &JcOpInfoTable[op];
1233
1234 assert(inf->op == op)do { if (!(inf->op == op)) _do_assert(("inf->op == op")
,"java/javacode.c",1234); } while (0)
;
1235 return inf;
1236}
1237
1238/*
1239 * :: Binary operations
1240 */
1241
1242JavaCode
1243jcBinaryOp(JavaCodeClass c, JavaCode lhs, JavaCode rhs)
1244{
1245 JavaCode r = jcoNew(c, 2, lhs, rhs);
1246 return r;
1247}
1248
1249localstatic void
1250jcBinOpPrint(JavaCodePContext ctxt, JavaCode code)
1251{
1252 JavaCodeClass thisClss = jcoClass(code)(((code)->hdr).clss);
1253 JavaCode lhs = jcoArgv(code)[0];
1254 JavaCode rhs = jcoArgv(code)[1];
1255
1256 jc0PrintWithParens(ctxt, thisClss, lhs);
1257 jcoPContextWrite(ctxt, thisClss->txt);
1258 jc0PrintWithParens(ctxt, thisClss, rhs);
1259}
1260
1261localstatic void
1262jc0PrintWithParens(JavaCodePContext ctxt, JavaCodeClass oClss, JavaCode arg)
1263{
1264 JavaCodeClass aClss = jcoClass(arg)(((arg)->hdr).clss);
1265 if (jc0NeedsParens(oClss, aClss)) {
1266 jcoPContextWrite(ctxt, "(");
1267 jcoWrite(ctxt, arg);
1268 jcoPContextWrite(ctxt, ")");
1269 }
1270 else {
1271 jcoWrite(ctxt, arg);
1272 }
1273}
1274
1275localstatic Bool
1276jc0NeedsParens(JavaCodeClass c1, JavaCodeClass c2)
1277{
1278 if (c2->prec == 0)
1279 return false((int) 0);
1280 return c1->prec > c2->prec;
1281}
1282
1283/*
1284 * :: Unary operations
1285 */
1286
1287JavaCode
1288jcNot(JavaCode arg)
1289{
1290 return jcoNew(jc0ClassObj(JCO_CLSS_Not), 1, arg);
1291}
1292
1293JavaCode
1294jcNegate(JavaCode arg)
1295{
1296 return jcoNew(jc0ClassObj(JCO_CLSS_Negate), 1, arg);
1297}
1298
1299
1300localstatic void
1301jcUnaryOpPrint(JavaCodePContext ctxt, JavaCode code)
1302{
1303 JavaCodeClass thisClss, aClss;
1304 JavaCode arg = jcoArgv(code)[0];
1305 thisClss = jcoClass(code)(((code)->hdr).clss);
1306 aClss = jcoClass(arg)(((arg)->hdr).clss);
Value stored to 'aClss' is never read
1307
1308 jcoPContextWrite(ctxt, thisClss->txt);
1309 jc0PrintWithParens(ctxt, thisClss, arg);
1310
1311}
1312
1313localstatic void
1314jcCastPrint(JavaCodePContext ctxt, JavaCode code)
1315{
1316 JavaCodeClass thisClss, aClss;
1317 JavaCode arg1 = jcoArgv(code)[0];
1318 JavaCode arg2 = jcoArgv(code)[1];
1319
1320 thisClss = jcoClass(code)(((code)->hdr).clss);
1321 aClss = jcoClass(code)(((code)->hdr).clss);
1322
1323 jcoPContextWrite(ctxt, "(");
1324 jcoWrite(ctxt, arg1);
1325 jcoPContextWrite(ctxt, ")");
1326
1327 jc0PrintWithParens(ctxt, thisClss, arg2);
1328}
1329
1330/*
1331 * :: Ternary operators
1332 * Well, there's only ?:.
1333 */
1334
1335JavaCode
1336jcConditional(JavaCode test, JavaCode truePart, JavaCode falsePart)
1337{
1338 return jcoNew(jc0ClassObj(JCO_CLSS_Conditional), 3, test, truePart, falsePart);
1339}
1340
1341localstatic void
1342jcCondPrint(JavaCodePContext ctxt, JavaCode code)
1343{
1344 JavaCodeClass thisClss;
1345 JavaCode arg1 = jcoArgv(code)[0];
1346 JavaCode arg2 = jcoArgv(code)[1];
1347 JavaCode arg3 = jcoArgv(code)[2];
1348
1349 thisClss = jcoClass(code)(((code)->hdr).clss);
1350 jc0PrintWithParens(ctxt, thisClss, arg1);
1351 jcoPContextWrite(ctxt, " ? ");
1352 jc0PrintWithParens(ctxt, thisClss, arg2);
1353 jcoPContextWrite(ctxt, " : ");
1354 jc0PrintWithParens(ctxt, thisClss, arg3);
1355}
1356
1357/*
1358 * :: Statements
1359 */
1360JavaCode
1361jcStatement(JavaCode stmt)
1362{
1363 return jcoNew(jc0ClassObj(JCO_CLSS_Statement), 1, stmt);
1364}
1365
1366localstatic void
1367jcStatementPrint(JavaCodePContext ctxt, JavaCode code)
1368{
1369 jcoWrite(ctxt, jcoArgv(code)[0]);
1370 jcoPContextWrite(ctxt, ";");
1371}
1372
1373/*
1374 * :: Sequences
1375 */
1376
1377JavaCode
1378jcCommaSeq(JavaCodeList lst)
1379{
1380 return jcoNewFrList(jc0ClassObj(JCO_CLSS_CommaSeq), lst);
1381}
1382
1383JavaCode
1384jcCommaSeqP(int n, va_list argp)
1385{
1386 return jcoNewP(jc0ClassObj(JCO_CLSS_CommaSeq), n, argp);
1387}
1388
1389JavaCode
1390jcSeq(JavaCodeList lst)
1391{
1392 return jcoNewFrList(jc0ClassObj(JCO_CLSS_Seq), lst);
1393}
1394
1395JavaCode
1396jcSeqV(int n, ...)
1397{
1398 va_list argp;
1399 JavaCode jc;
1400 va_start(argp, n)__builtin_va_start(argp, n);
1401 jc = jcoNewP(jc0ClassObj(JCO_CLSS_Seq), n, argp);
1402 va_end(argp)__builtin_va_end(argp);
1403 return jc;
1404}
1405
1406JavaCode
1407jcNLSeq(JavaCodeList lst)
1408{
1409 return jcoNewFrList(jc0ClassObj(JCO_CLSS_NLSeq), lst);
1410}
1411
1412JavaCode
1413jcSpaceSeq(JavaCodeList lst)
1414{
1415 return jcoNewFrList(jc0ClassObj(JCO_CLSS_SpaceSeq), lst);
1416}
1417
1418JavaCode
1419jcSpaceSeqV(int n, ...)
1420{
1421 va_list argp;
1422 JavaCode jc;
1423 va_start(argp, n)__builtin_va_start(argp, n);
1424 jc = jcoNewP(jc0ClassObj(JCO_CLSS_SpaceSeq), n, argp);
1425 va_end(argp)__builtin_va_end(argp);
1426 return jc;
1427}
1428
1429JavaCode
1430jcNLSeqV(int n, ...)
1431{
1432 va_list argp;
1433 JavaCode jc;
1434 va_start(argp, n)__builtin_va_start(argp, n);
1435 jc = jcoNewP(jc0ClassObj(JCO_CLSS_NLSeq), n, argp);
1436 va_end(argp)__builtin_va_end(argp);
1437 return jc;
1438}
1439
1440localstatic void
1441jcSequencePrint(JavaCodePContext ctxt, JavaCode code)
1442{
1443 char *theSep = jcoClass(code)(((code)->hdr).clss)->txt;
1444 char *sep = 0;
1445 int i=0;
1446 for (i=0; i<jcoArgc(code); i++) {
1447 if (sep != 0)
1448 jcoPContextWrite(ctxt, sep);
1449 jcoWrite(ctxt, jcoArgv(code)[i]);
1450 sep = theSep;
1451 }
1452}
1453
1454JavaCode
1455jcBlockNoNL(JavaCode body)
1456{
1457 return jcoNew(jc0ClassObj(JCO_CLSS_Braces), 1, body);
1458}
1459
1460JavaCode
1461jcBlock(JavaCode body)
1462{
1463 return jcoNew(jc0ClassObj(JCO_CLSS_Block), 1, body);
1464}
1465
1466localstatic void
1467jcBlockPrint(JavaCodePContext ctxt, JavaCode code)
1468{
1469 jcoPContextWrite(ctxt, "{");
1470 jcoPContextNewlineIndent(ctxt);
1471 jcoWrite(ctxt, jcoArgv(code)[0]);
1472 jcoPContextNewlineUnindent(ctxt);
1473 jcoPContextWrite(ctxt, "}");
1474
1475}
1476
1477JavaCode
1478jcBreak(JavaCode label)
1479{
1480 if (label == 0)
1481 return jcKeyword(symInternConst("break")symProbe("break", 1));
1482 else
1483 return jcSpaceSeqV(2, jcKeyword(symInternConst("break")symProbe("break", 1)), label);
1484}
1485
1486JavaCode
1487jcContinue(JavaCode label)
1488{
1489 if (label == 0)
1490 return jcKeyword(symInternConst("continue")symProbe("continue", 1));
1491 else
1492 return jcSpaceSeqV(2, jcKeyword(symInternConst("continue")symProbe("continue", 1)), label);
1493}
1494
1495JavaCode
1496jcCaseLabel(JavaCode label)
1497{
1498 return jcoNew(jc0ClassObj(JCO_CLSS_Case), 1, label);
1499}
1500
1501localstatic void
1502jcCasePrint(JavaCodePContext ctxt, JavaCode code)
1503{
1504 jcoPContextWrite(ctxt, "case ");
1505 jcoWrite(ctxt, jcoArgv(code)[0]);
1506 jcoPContextWrite(ctxt, ": ");
1507}
1508
1509JavaCode
1510jcTryCatch(JavaCode body, JavaCode catch, JavaCode finally)
1511{
1512 return jcTry(body, listSingleton(JavaCode)(JavaCode_listPointer->Singleton)(catch), finally);
1513}
1514
1515JavaCode
1516jcTry(JavaCode body, JavaCodeList catches, JavaCode finally)
1517{
1518 JavaCodeList lst = listNil(JavaCode)((JavaCodeList) 0);
1519 lst = listCons(JavaCode)(JavaCode_listPointer->Cons)(jcoNew(jc0ClassObj(JCO_CLSS_Try), 1, body), lst);
1520 lst = listNConcat(JavaCode)(JavaCode_listPointer->NConcat)(lst, catches);
1521 if (finally != NULL((void*)0)) {
1522 lst = listNConcat(JavaCode)(JavaCode_listPointer->NConcat)(lst,
1523 listSingleton(JavaCode)(JavaCode_listPointer->Singleton)(jcoNew(jc0ClassObj(JCO_CLSS_Finally),
1524 1, finally)));
1525 }
1526 return jcNLSeq(lst);
1527}
1528
1529JavaCode
1530jcCatch(JavaCode decl, JavaCode body)
1531{
1532 return jcoNew(jc0ClassObj(JCO_CLSS_Catch), 2, decl, body);
1533}
1534
1535/*
1536 * :: Import, Package
1537 */
1538
1539JavaCode
1540jcImport(JavaCode arg)
1541{
1542 return jcSpaceSeqV(2, jcKeyword(symInternConst("import")symProbe("import", 1)), arg);
1543}
1544
1545JavaCode
1546jcPackage(JavaCode arg)
1547{
1548 return jcSpaceSeqV(2, jcKeyword(symInternConst("package")symProbe("package", 1)), arg);
1549}
1550
1551/*
1552 * :: Throw, catch
1553 */
1554
1555JavaCode
1556jcThrow(JavaCode arg)
1557{
1558 return jcSpaceSeqV(2, jcKeyword(symInternConst("throw")symProbe("throw", 1)), arg);
1559}
1560
1561/*
1562 * :: If, Switch, While
1563 */
1564
1565JavaCode
1566jcIf(JavaCode test, JavaCode stmt)
1567{
1568 return jcoNew(jc0ClassObj(JCO_CLSS_If), 2, test, stmt);
1569}
1570
1571JavaCode
1572jcSwitch(JavaCode test, JavaCodeList bodyList)
1573{
1574 JavaCode block = jcBraces(jcNLSeq(bodyList));
1575 return jcoNew(jc0ClassObj(JCO_CLSS_Switch), 2, test, block);
1576}
1577
1578JavaCode
1579jcWhile(JavaCode test, JavaCode stmt)
1580{
1581 return jcoNew(jc0ClassObj(JCO_CLSS_While), 2, test, stmt);
1582}
1583
1584localstatic void
1585jcBlockHdrPrint(JavaCodePContext ctxt, JavaCode code)
1586{
1587 Bool needsIndent;
1588 char *key = (char *) jcoClass(code)(((code)->hdr).clss)->txt;
1589 jcoPContextWrite(ctxt, key);
1590 jcoPContextWrite(ctxt, " (");
1591 jcoWrite(ctxt, jcoArgv(code)[0]);
1592 jcoPContextWrite(ctxt, ") ");
1593
1594 needsIndent = jcBlockHdrIndent(jcoArgv(code)[1]);
1595 if (needsIndent)
1596 jcoPContextNewlineIndent(ctxt);
1597 jcoWrite(ctxt, jcoArgv(code)[1]);
1598 if (needsIndent)
1599 jcoPContextNewlineUnindent(ctxt);
1600
1601}
1602
1603localstatic void
1604jcBlockKeywordPrint(JavaCodePContext ctxt, JavaCode code)
1605{
1606 Bool needsIndent;
1607 char *key = (char *) jcoClass(code)(((code)->hdr).clss)->txt;
1608 jcoPContextWrite(ctxt, key);
1609 jcoPContextWrite(ctxt, " ");
1610
1611 needsIndent = jcBlockHdrIndent(jcoArgv(code)[0]);
1612 if (needsIndent)
1613 jcoPContextNewlineIndent(ctxt);
1614 jcoWrite(ctxt, jcoArgv(code)[0]);
1615 if (needsIndent)
1616 jcoPContextNewlineUnindent(ctxt);
1617
1618}
1619
1620localstatic Bool
1621jcBlockHdrIndent(JavaCode code)
1622{
1623 return jcoClass(code)(((code)->hdr).clss)->id != JCO_CLSS_Braces
1624 && jcoClass(code)(((code)->hdr).clss)->id != JCO_CLSS_Block;
1625}
1626
1627/*
1628 * :: File
1629 */
1630
1631JavaCode
1632jcFile(JavaCode pkg, JavaCode name, JavaCodeList imports, JavaCode body)
1633{
1634 JavaCodeList whole;
1635 JavaCode file;
1636
1637 whole = listNil(JavaCode)((JavaCodeList) 0);
1638 if (pkg != NULL((void*)0)) {
1639 whole = listSingleton(JavaCode)(JavaCode_listPointer->Singleton)(jcStatement(jcPackage(jcoCopy(pkg))));
1640 }
1641 whole = listNConcat(JavaCode)(JavaCode_listPointer->NConcat)(whole, imports);
1642 whole = listNConcat(JavaCode)(JavaCode_listPointer->NConcat)(whole, listSingleton(JavaCode)(JavaCode_listPointer->Singleton)(body));
1643
1644 file = jcoNew(jc0ClassObj(JCO_CLSS_File),
1645 3, name, jcoCopy(pkg), jcNLSeq(whole));
1646
1647 jcoFree(pkg);
1648
1649 return file;
1650}
1651
1652void
1653jcFilePrint(JavaCodePContext ctxt, JavaCode code)
1654{
1655 jcoWrite(ctxt, jcoArgv(code)[2]);
1656}
1657
1658String
1659jcFileClassName(JavaCode file)
1660{
1661 return jcIdName(jcoArgv(file)[0]);
1662}
1663
1664String
1665jcFilePackageName(JavaCode file)
1666{
1667 if (jcoArgv(file)[1] == NULL((void*)0)) {
1668 return "";
1669 }
1670 else {
1671 return jcIdName(jcoArgv(file)[1]);
1672 }
1673}
1674
1675/*
1676 * :: Generic operations
1677 */
1678SExpr
1679jcNodeSExpr(JavaCode code)
1680{
1681 Symbol sym = symIntern(jcoClass(code)->name)symProbe((((code)->hdr).clss)->name, 1 | 2);
1682 SExpr whole = sxiList(1, sxiFrSymbol(sym));
1683 int i=0;
1684
1685 for (i=0; i<jcoArgc(code); i++) {
1686 JavaCode jc = jcoArgv(code)[i];
1687 SExpr sexpr = jc == NULL((void*)0) ? sxNil : jcoSExpr(jc);
1688 whole = sxCons(sexpr, whole);
1689 }
1690 return sxNReverse(whole);
1691}
1692
1693extern void
1694jcNodePrint(JavaCodePContext ctxt, JavaCode code)
1695{
1696 jcoPContextWrite(ctxt, "<<node>>");
1697}
1698
1699
1700void
1701jcListPrint(JavaCodePContext ctxt, JavaCode code)
1702{
1703 char *theSep = (char *) jcoClass(code)(((code)->hdr).clss)->txt;
1704 char *sep = "";
1705 int i;
1706 for (i=0; i<jcoArgc(code); i++) {
1707 jcoPContextWrite(ctxt, sep);
1708 jcoWrite(ctxt, jcoArgv(code)[i]);
1709 sep = theSep;
1710 }
1711}
1712
1713
1714/*
1715 * :: Utils
1716 */
1717localstatic Symbol jc0ModifierSymbol(int idx);
1718
1719localstatic JavaCodeClass
1720jc0ClassObj(JcClassId id)
1721{
1722 JavaCodeClass clss = &jcClss[id];
1723 assert(clss->id == id)do { if (!(clss->id == id)) _do_assert(("clss->id == id"
),"java/javacode.c",1723); } while (0)
;
1724 return clss;
1725}
1726
1727struct jcModifierInfo {
1728 int mask;
1729 String txt;
1730 Symbol sym;
1731};
1732
1733
1734static struct jcModifierInfo jcModifierList[] = {
1735 { JCO_MOD_Public, "public"},
1736 { JCO_MOD_Private, "private"},
1737 { JCO_MOD_Protected, "protected"},
1738 { JCO_MOD_Static, "static"},
1739 { JCO_MOD_Final, "final"},
1740 { JCO_MOD_Transient, "transient"},
1741 { JCO_MOD_Volatile, "volatile"},
1742};
1743
1744localstatic JavaCodeList
1745jc0CreateModifiers(int modifiers)
1746{
1747 JavaCodeList l = listNil(JavaCode)((JavaCodeList) 0);
1748 int i=0, m;
1749 for (m=1; m< JCO_MOD_MAX; m=m<<1) {
1750 if (modifiers & m)
1751 l = listCons(JavaCode)(JavaCode_listPointer->Cons)(jcoNewToken(jc0ClassObj(JCO_CLSS_Keyword),
1752 jc0ModifierSymbol(i)), l);
1753 i++;
1754 }
1755 return listNReverse(JavaCode)(JavaCode_listPointer->NReverse)(l);
1756}
1757
1758localstatic Symbol
1759jc0ModifierSymbol(int idx)
1760{
1761 struct jcModifierInfo *inf = &jcModifierList[idx];
1762 if (inf->sym == NULL((void*)0))
1763 inf->sym = symInternConst(inf->txt)symProbe(inf->txt, 1);
1764 return inf->sym;
1765}
1766
1767
1768localstatic Bool jc0ImportEq(JavaCode c1, JavaCode c2);
1769localstatic void jc0CollectImports(Table tbl, Table nameTbl, JavaCode code);
1770
1771JavaCodeList
1772jcCollectImports(JavaCode code)
1773{
1774 Table tbl = tblNew((TblHashFun) jcoHash, (TblEqFun) jc0ImportEq);
1775 Table nameTbl = tblNew((TblHashFun) strHash, (TblEqFun) strEqual);
1776 TableIterator it;
1777 JavaCodeList resList = listNil(JavaCode)((JavaCodeList) 0);
1778
1779 jc0CollectImports(tbl, nameTbl, code);
1780
1781 for (tblITER(it, tbl)_tblITER(&(it), tbl); tblMORE(it)((it).curr <= (it).last); tblSTEP(it)((((it).link=(it).link->next))==0 ? _tblSTEP(&(it)) : 1
)
) {
1782 JavaCode id = (JavaCode) tblKEY(it)((it).link->key);
1783 JavaCodeList codes = (JavaCodeList) tblELT(it)((it).link->elt);
1784 JavaCodeList tmp;
1785 JavaCode copy = jcImportedId(jcoImportPkg(id), jcoImportId(id));
1786 JavaCodeList usages = (JavaCodeList) tblElt(nameTbl, jcoImportId(id), listNil(JavaCode)((JavaCodeList) 0));
1787 if (cdr(usages)((usages)->rest) != listNil(JavaCode)((JavaCodeList) 0)) {
1788 continue;
1789 }
1790 else {
1791 resList = listCons(JavaCode)(JavaCode_listPointer->Cons)(copy, resList);
1792 tmp = codes;
1793 while (tmp != 0) {
1794 JavaCode imp = car(tmp)((tmp)->first);
1795 jcoImportSetImported(imp, true1);
1796 tmp = cdr(tmp)((tmp)->rest);
1797 }
1798 listFree(JavaCode)(JavaCode_listPointer->Free)(codes);
1799 }
1800 }
1801 return resList;
1802}
1803
1804localstatic Bool
1805jc0ImportEq(JavaCode c1, JavaCode c2)
1806{
1807 assert(jcoIsImport(c1) && jcoIsImport(c2))do { if (!(((((c1)->hdr).tag) == JCO_IMPORT) && ((
((c2)->hdr).tag) == JCO_IMPORT))) _do_assert(("jcoIsImport(c1) && jcoIsImport(c2)"
),"java/javacode.c",1807); } while (0)
;
1808
1809 if (strcmp(jcoImportPkg(c1), jcoImportPkg(c2)) != 0)
1810 return false((int) 0);
1811 if (strcmp(jcoImportId(c1), jcoImportId(c2)) != 0)
1812 return false((int) 0);
1813
1814 return true1;
1815}
1816
1817
1818localstatic void
1819jc0CollectImports(Table tbl, Table nameTbl, JavaCode code)
1820{
1821 if (code == 0)
1822 return;
1823 if (jcoIsImport(code)((((code)->hdr).tag) == JCO_IMPORT)) {
1824 JavaCodeList l = (JavaCodeList) tblElt(tbl, code, listNil(JavaCode)((JavaCodeList) 0));
1825 JavaCode key = code;
1826 l = listCons(JavaCode)(JavaCode_listPointer->Cons)(code, l);
1827 tblSetElt(tbl, key, l);
1828
1829 String name = jcoImportId(code);
1830 JavaCodeList ids = (JavaCodeList) tblElt(nameTbl, name, listNil(JavaCode)((JavaCodeList) 0));
1831 if (!listMember(JavaCode)(JavaCode_listPointer->Member)(ids, code, jc0ImportEq)) {
1832 tblSetElt(nameTbl, name, (TblElt) listCons(JavaCode)(JavaCode_listPointer->Cons)(code, ids));
1833 }
1834 }
1835 if (jcoIsNode(code)((((code)->hdr).tag) == JCO_JAVA)) {
1836 int i=0;
1837 for (i=0; i<jcoArgc(code); i++) {
1838 jc0CollectImports(tbl, nameTbl, jcoArgv(code)[i]);
1839 }
1840 }
1841}
1842
1843/*
1844 * Returns a newly allocated string with properly escaped characters.
1845 */
1846localstatic String
1847jc0EscapeString(String s, Bool addTerminalChar)
1848{
1849 Buffer buf;
1850 buf = bufNew();
1851 while (*s != 0) {
1852 switch (*s) {
1853 case '\\':
1854 bufPuts(buf, "\\\\");
1855 break;
1856 case '\n':
1857 bufPuts(buf, "\\\n");
1858 break;
1859 case '\"':
1860 bufPuts(buf, "\\\"");
1861 break;
1862 default:
1863 bufPutc(buf, *s);
1864 break;
1865 }
1866 s++;
1867 }
1868 if (addTerminalChar) {
1869 bufPutc(buf, '\\');
1870 bufPutc(buf, '0');
1871 }
1872
1873 return bufLiberate(buf);
1874}
1875
1876/*
1877 * :: Names and so on
1878 */
1879
1880localstatic Bool jcIsId(String word);
1881
1882Bool
1883jcIsLegalClassName(String word)
1884{
1885 int i;
1886 if (!jcIsId(word))
1887 return false((int) 0);
1888
1889 for (i=0; i<JK_END; i++) {
1890 if (strcmp(word, jkKeywords[i].text) == 0)
1891 return false((int) 0);
1892 }
1893 return true1;
1894}
1895
1896localstatic Bool
1897jcIsId(String word)
1898{
1899 char *p = word;
1900 if (word[0] == '\0')
1901 return false((int) 0);
1902 if (!(word[0] == '_' || isalpha(word[0])((*__ctype_b_loc ())[(int) ((word[0]))] & (unsigned short
int) _ISalpha)
))
1903 return false((int) 0);
1904 while (*p != '\0') {
1905 if (!(*p == '_' || isalnum(*p)((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int)
_ISalnum)
))
1906 return false((int) 0);
1907 p++;
1908 }
1909
1910 return true1;
1911}