Support non-printables in string literals and tidy case alignment and constant literals.

This commit is contained in:
David Brown 2016-08-12 20:41:58 +01:00
parent fe03130fe1
commit 58556457bc
32 changed files with 1125 additions and 1148 deletions

View file

@ -22,6 +22,7 @@ export void OPC_BegBlk (void);
export void OPC_BegStat (void);
static void OPC_CProcDefs (OPT_Object obj, INTEGER vis);
export void OPC_Case (LONGINT caseVal, INTEGER form);
static void OPC_CharacterLiteral (LONGINT c);
export void OPC_Cmp (INTEGER rel);
export void OPC_CompleteIdent (OPT_Object obj);
export void OPC_Constant (OPT_Const con, INTEGER form);
@ -75,6 +76,7 @@ static void OPC_RegCmds (OPT_Object obj);
export void OPC_SetInclude (BOOLEAN exclude);
static void OPC_Stars (OPT_Struct typ, BOOLEAN *openClause);
static void OPC_Str1 (CHAR *s, LONGINT s__len, LONGINT x);
static void OPC_StringLiteral (CHAR *s, LONGINT s__len, LONGINT l);
export void OPC_TDescDecl (OPT_Struct typ);
export void OPC_TypeDefs (OPT_Object obj, INTEGER vis);
export void OPC_TypeOf (OPT_Object ap);
@ -815,11 +817,12 @@ void OPC_TDescDecl (OPT_Struct typ)
OPC_Andent(typ);
OPC_Str1((CHAR*)", #", (LONGINT)4, typ->n + 1);
OPC_Str1((CHAR*)", #) = {__TDFLDS(", (LONGINT)18, OPC_NofPtrs(typ));
OPM_Write('\"');
OPM_Write('"');
if (typ->strobj != NIL) {
OPM_WriteStringVar((void*)typ->strobj->name, ((LONGINT)(256)));
}
OPC_Str1((CHAR*)"\", #), {", (LONGINT)9, typ->size);
OPM_Write('"');
OPC_Str1((CHAR*)", #), {", (LONGINT)8, typ->size);
nofptrs = 0;
OPC_PutPtrOffsets(typ, ((LONGINT)(0)), &nofptrs);
OPC_Str1((CHAR*)"#}}", (LONGINT)4, -((nofptrs + 1) * (LONGINT)OPM_LIntSize));
@ -1170,10 +1173,10 @@ static void OPC_Include (CHAR *name, LONGINT name__len)
{
__DUP(name, name__len, CHAR);
OPM_WriteString((CHAR*)"#include ", (LONGINT)10);
OPM_Write('\"');
OPM_Write('"');
OPM_WriteStringVar((void*)name, name__len);
OPM_WriteString((CHAR*)".h", (LONGINT)3);
OPM_Write('\"');
OPM_Write('"');
OPM_WriteLn();
__DEL(name);
}
@ -1855,26 +1858,56 @@ void OPC_Cmp (INTEGER rel)
}
}
static void OPC_CharacterLiteral (LONGINT c)
{
if (c < 32 || c > 126) {
OPM_WriteString((CHAR*)"0x", (LONGINT)3);
OPM_WriteHex(c);
} else {
OPM_Write('\'');
if ((c == 92 || c == 39) || c == 63) {
OPM_Write('\\');
}
OPM_Write((CHAR)c);
OPM_Write('\'');
}
}
static void OPC_StringLiteral (CHAR *s, LONGINT s__len, LONGINT l)
{
LONGINT i;
INTEGER c;
__DUP(s, s__len, CHAR);
OPM_Write('"');
i = 0;
while (i < l) {
c = (int)s[__X(i, s__len)];
if (c < 32 || c > 126) {
OPM_Write('\\');
OPM_Write((CHAR)(48 + __ASHR(c, 6)));
c = __MASK(c, -64);
OPM_Write((CHAR)(48 + __ASHR(c, 3)));
c = __MASK(c, -8);
OPM_Write((CHAR)(48 + c));
} else {
if ((c == 92 || c == 34) || c == 63) {
OPM_Write('\\');
}
OPM_Write((CHAR)c);
}
i += 1;
}
OPM_Write('"');
__DEL(s);
}
void OPC_Case (LONGINT caseVal, INTEGER form)
{
CHAR ch;
OPM_WriteString((CHAR*)"case ", (LONGINT)6);
switch (form) {
case 3:
ch = (CHAR)caseVal;
if ((ch >= ' ' && ch <= '~')) {
OPM_Write('\'');
if (((ch == '\\' || ch == '\?') || ch == '\'') || ch == '\"') {
OPM_Write('\\');
OPM_Write(ch);
} else {
OPM_Write(ch);
}
OPM_Write('\'');
} else {
OPM_WriteString((CHAR*)"0x", (LONGINT)3);
OPM_WriteHex(caseVal);
}
OPC_CharacterLiteral(caseVal);
break;
case 4: case 5: case 6:
OPM_WriteInt(caseVal);
@ -1932,8 +1965,7 @@ void OPC_Len (OPT_Object obj, OPT_Struct array, LONGINT dim)
void OPC_Constant (OPT_Const con, INTEGER form)
{
INTEGER i, len;
CHAR ch;
INTEGER i;
SET s;
LONGINT hex;
BOOLEAN skipLeading;
@ -1945,18 +1977,7 @@ void OPC_Constant (OPT_Const con, INTEGER form)
OPM_WriteInt(con->intval);
break;
case 3:
ch = (CHAR)con->intval;
if ((ch >= ' ' && ch <= '~')) {
OPM_Write('\'');
if (((ch == '\\' || ch == '\?') || ch == '\'') || ch == '\"') {
OPM_Write('\\');
}
OPM_Write(ch);
OPM_Write('\'');
} else {
OPM_WriteString((CHAR*)"0x", (LONGINT)3);
OPM_WriteHex(con->intval);
}
OPC_CharacterLiteral(con->intval);
break;
case 4: case 5: case 6:
OPM_WriteInt(con->intval);
@ -1991,18 +2012,7 @@ void OPC_Constant (OPT_Const con, INTEGER form)
}
break;
case 10:
OPM_Write('\"');
len = (int)con->intval2 - 1;
i = 0;
while (i < len) {
ch = (*con->ext)[__X(i, ((LONGINT)(256)))];
if (((ch == '\\' || ch == '\?') || ch == '\'') || ch == '\"') {
OPM_Write('\\');
}
OPM_Write(ch);
i += 1;
}
OPM_Write('\"');
OPC_StringLiteral(*con->ext, ((LONGINT)(256)), con->intval2 - 1);
break;
case 11:
OPM_WriteString((CHAR*)"NIL", (LONGINT)4);
@ -2015,74 +2025,74 @@ void OPC_Constant (OPT_Const con, INTEGER form)
}
}
static struct InitKeywords__47 {
static struct InitKeywords__48 {
SHORTINT *n;
struct InitKeywords__47 *lnk;
} *InitKeywords__47_s;
struct InitKeywords__48 *lnk;
} *InitKeywords__48_s;
static void Enter__48 (CHAR *s, LONGINT s__len);
static void Enter__49 (CHAR *s, LONGINT s__len);
static void Enter__48 (CHAR *s, LONGINT s__len)
static void Enter__49 (CHAR *s, LONGINT s__len)
{
INTEGER h;
__DUP(s, s__len, CHAR);
h = OPC_PerfectHash((void*)s, s__len);
OPC_hashtab[__X(h, ((LONGINT)(105)))] = *InitKeywords__47_s->n;
__COPY(s, OPC_keytab[__X(*InitKeywords__47_s->n, ((LONGINT)(36)))], ((LONGINT)(9)));
*InitKeywords__47_s->n += 1;
OPC_hashtab[__X(h, ((LONGINT)(105)))] = *InitKeywords__48_s->n;
__COPY(s, OPC_keytab[__X(*InitKeywords__48_s->n, ((LONGINT)(36)))], ((LONGINT)(9)));
*InitKeywords__48_s->n += 1;
__DEL(s);
}
static void OPC_InitKeywords (void)
{
SHORTINT n, i;
struct InitKeywords__47 _s;
struct InitKeywords__48 _s;
_s.n = &n;
_s.lnk = InitKeywords__47_s;
InitKeywords__47_s = &_s;
_s.lnk = InitKeywords__48_s;
InitKeywords__48_s = &_s;
n = 0;
i = 0;
while (i <= 104) {
OPC_hashtab[__X(i, ((LONGINT)(105)))] = -1;
i += 1;
}
Enter__48((CHAR*)"asm", (LONGINT)4);
Enter__48((CHAR*)"auto", (LONGINT)5);
Enter__48((CHAR*)"break", (LONGINT)6);
Enter__48((CHAR*)"case", (LONGINT)5);
Enter__48((CHAR*)"char", (LONGINT)5);
Enter__48((CHAR*)"const", (LONGINT)6);
Enter__48((CHAR*)"continue", (LONGINT)9);
Enter__48((CHAR*)"default", (LONGINT)8);
Enter__48((CHAR*)"do", (LONGINT)3);
Enter__48((CHAR*)"double", (LONGINT)7);
Enter__48((CHAR*)"else", (LONGINT)5);
Enter__48((CHAR*)"enum", (LONGINT)5);
Enter__48((CHAR*)"extern", (LONGINT)7);
Enter__48((CHAR*)"export", (LONGINT)7);
Enter__48((CHAR*)"float", (LONGINT)6);
Enter__48((CHAR*)"for", (LONGINT)4);
Enter__48((CHAR*)"fortran", (LONGINT)8);
Enter__48((CHAR*)"goto", (LONGINT)5);
Enter__48((CHAR*)"if", (LONGINT)3);
Enter__48((CHAR*)"import", (LONGINT)7);
Enter__48((CHAR*)"int", (LONGINT)4);
Enter__48((CHAR*)"long", (LONGINT)5);
Enter__48((CHAR*)"register", (LONGINT)9);
Enter__48((CHAR*)"return", (LONGINT)7);
Enter__48((CHAR*)"short", (LONGINT)6);
Enter__48((CHAR*)"signed", (LONGINT)7);
Enter__48((CHAR*)"sizeof", (LONGINT)7);
Enter__48((CHAR*)"static", (LONGINT)7);
Enter__48((CHAR*)"struct", (LONGINT)7);
Enter__48((CHAR*)"switch", (LONGINT)7);
Enter__48((CHAR*)"typedef", (LONGINT)8);
Enter__48((CHAR*)"union", (LONGINT)6);
Enter__48((CHAR*)"unsigned", (LONGINT)9);
Enter__48((CHAR*)"void", (LONGINT)5);
Enter__48((CHAR*)"volatile", (LONGINT)9);
Enter__48((CHAR*)"while", (LONGINT)6);
InitKeywords__47_s = _s.lnk;
Enter__49((CHAR*)"asm", (LONGINT)4);
Enter__49((CHAR*)"auto", (LONGINT)5);
Enter__49((CHAR*)"break", (LONGINT)6);
Enter__49((CHAR*)"case", (LONGINT)5);
Enter__49((CHAR*)"char", (LONGINT)5);
Enter__49((CHAR*)"const", (LONGINT)6);
Enter__49((CHAR*)"continue", (LONGINT)9);
Enter__49((CHAR*)"default", (LONGINT)8);
Enter__49((CHAR*)"do", (LONGINT)3);
Enter__49((CHAR*)"double", (LONGINT)7);
Enter__49((CHAR*)"else", (LONGINT)5);
Enter__49((CHAR*)"enum", (LONGINT)5);
Enter__49((CHAR*)"extern", (LONGINT)7);
Enter__49((CHAR*)"export", (LONGINT)7);
Enter__49((CHAR*)"float", (LONGINT)6);
Enter__49((CHAR*)"for", (LONGINT)4);
Enter__49((CHAR*)"fortran", (LONGINT)8);
Enter__49((CHAR*)"goto", (LONGINT)5);
Enter__49((CHAR*)"if", (LONGINT)3);
Enter__49((CHAR*)"import", (LONGINT)7);
Enter__49((CHAR*)"int", (LONGINT)4);
Enter__49((CHAR*)"long", (LONGINT)5);
Enter__49((CHAR*)"register", (LONGINT)9);
Enter__49((CHAR*)"return", (LONGINT)7);
Enter__49((CHAR*)"short", (LONGINT)6);
Enter__49((CHAR*)"signed", (LONGINT)7);
Enter__49((CHAR*)"sizeof", (LONGINT)7);
Enter__49((CHAR*)"static", (LONGINT)7);
Enter__49((CHAR*)"struct", (LONGINT)7);
Enter__49((CHAR*)"switch", (LONGINT)7);
Enter__49((CHAR*)"typedef", (LONGINT)8);
Enter__49((CHAR*)"union", (LONGINT)6);
Enter__49((CHAR*)"unsigned", (LONGINT)9);
Enter__49((CHAR*)"void", (LONGINT)5);
Enter__49((CHAR*)"volatile", (LONGINT)9);
Enter__49((CHAR*)"while", (LONGINT)6);
InitKeywords__48_s = _s.lnk;
}

View file

@ -228,17 +228,17 @@ BOOLEAN OPM_OpenPar (void)
OPM_LogWLn();
OPM_LogWStr((CHAR*)" x - turn off array indices check", (LONGINT)35);
OPM_LogWLn();
OPM_LogWStr((CHAR*)" a - don\'t check ASSERTs at runtime, use this option in tested production code", (LONGINT)80);
OPM_LogWStr((CHAR*)" a - don't check ASSERTs at runtime, use this option in tested production code", (LONGINT)80);
OPM_LogWLn();
OPM_LogWStr((CHAR*)" p - turn off automatic pointer initialization", (LONGINT)48);
OPM_LogWLn();
OPM_LogWStr((CHAR*)" t - don\'t check type guards (use in rare cases such as low-level modules where every cycle counts)", (LONGINT)101);
OPM_LogWStr((CHAR*)" t - don't check type guards (use in rare cases such as low-level modules where every cycle counts)", (LONGINT)101);
OPM_LogWLn();
OPM_LogWStr((CHAR*)" S - don\'t call external assembler/compiler, only generate C code", (LONGINT)67);
OPM_LogWStr((CHAR*)" S - don't call external assembler/compiler, only generate C code", (LONGINT)67);
OPM_LogWLn();
OPM_LogWStr((CHAR*)" c - don\'t call linker", (LONGINT)24);
OPM_LogWStr((CHAR*)" c - don't call linker", (LONGINT)24);
OPM_LogWLn();
OPM_LogWStr((CHAR*)" f - don\'t use color output", (LONGINT)29);
OPM_LogWStr((CHAR*)" f - don't use color output", (LONGINT)29);
OPM_LogWLn();
OPM_LogWStr((CHAR*)" F - force writing new symbol file in current directory", (LONGINT)57);
OPM_LogWLn();

View file

@ -325,7 +325,7 @@ void OPS_Get (SHORTINT *sym)
}
}
switch (OPS_ch) {
case '\"': case '\'':
case '"': case '\'':
OPS_Str(&s);
break;
case '#':

View file

@ -787,9 +787,9 @@ void Texts_Scan (Texts_Scanner *S, LONGINT *S__typ)
(*S).s[__X(i, ((LONGINT)(64)))] = 0x00;
(*S).len = i;
(*S).class = 1;
} else if (ch == '\"') {
} else if (ch == '"') {
Texts_Read((void*)&*S, S__typ, &ch);
while ((((ch != '\"' && ch >= ' ')) && i != 63)) {
while ((((ch != '"' && ch >= ' ')) && i != 63)) {
(*S).s[__X(i, ((LONGINT)(64)))] = ch;
i += 1;
Texts_Read((void*)&*S, S__typ, &ch);

View file

@ -25,7 +25,7 @@ export void *errors__init(void)
errors_errors[6][0] = 0x00;
errors_errors[7][0] = 0x00;
errors_errors[8][0] = 0x00;
__MOVE("\'=\' expected", errors_errors[9], 13);
__MOVE("'=' expected", errors_errors[9], 13);
errors_errors[10][0] = 0x00;
errors_errors[11][0] = 0x00;
__MOVE("type definition starts with incorrect symbol", errors_errors[12], 45);
@ -34,28 +34,28 @@ export void *errors__init(void)
__MOVE("declaration followed by incorrect symbol", errors_errors[15], 41);
__MOVE("MODULE expected", errors_errors[16], 16);
errors_errors[17][0] = 0x00;
__MOVE("\'.\' missing", errors_errors[18], 12);
__MOVE("\',\' missing", errors_errors[19], 12);
__MOVE("\':\' missing", errors_errors[20], 12);
__MOVE("'.' missing", errors_errors[18], 12);
__MOVE("',' missing", errors_errors[19], 12);
__MOVE("':' missing", errors_errors[20], 12);
errors_errors[21][0] = 0x00;
__MOVE("\')\' missing", errors_errors[22], 12);
__MOVE("\']\' missing", errors_errors[23], 12);
__MOVE("\'}\' missing", errors_errors[24], 12);
__MOVE("')' missing", errors_errors[22], 12);
__MOVE("']' missing", errors_errors[23], 12);
__MOVE("'}' missing", errors_errors[24], 12);
__MOVE("OF missing", errors_errors[25], 11);
__MOVE("THEN missing", errors_errors[26], 13);
__MOVE("DO missing", errors_errors[27], 11);
__MOVE("TO missing", errors_errors[28], 11);
errors_errors[29][0] = 0x00;
__MOVE("\'(\' missing", errors_errors[30], 12);
__MOVE("'(' missing", errors_errors[30], 12);
errors_errors[31][0] = 0x00;
errors_errors[32][0] = 0x00;
errors_errors[33][0] = 0x00;
__MOVE("\':=\' missing", errors_errors[34], 13);
__MOVE("\',\' or OF expected", errors_errors[35], 19);
__MOVE("':=' missing", errors_errors[34], 13);
__MOVE("',' or OF expected", errors_errors[35], 19);
errors_errors[36][0] = 0x00;
errors_errors[37][0] = 0x00;
__MOVE("identifier expected", errors_errors[38], 20);
__MOVE("\';\' missing", errors_errors[39], 12);
__MOVE("';' missing", errors_errors[39], 12);
errors_errors[40][0] = 0x00;
__MOVE("END missing", errors_errors[41], 12);
errors_errors[42][0] = 0x00;
@ -131,10 +131,10 @@ export void *errors__init(void)
__MOVE("operand is not a variable", errors_errors[112], 26);
__MOVE("incompatible assignment", errors_errors[113], 24);
__MOVE("string too long to be assigned", errors_errors[114], 31);
__MOVE("parameter doesn\'t match", errors_errors[115], 24);
__MOVE("number of parameters doesn\'t match", errors_errors[116], 35);
__MOVE("result type doesn\'t match", errors_errors[117], 26);
__MOVE("export mark doesn\'t match with forward declaration", errors_errors[118], 51);
__MOVE("parameter doesn't match", errors_errors[115], 24);
__MOVE("number of parameters doesn't match", errors_errors[116], 35);
__MOVE("result type doesn't match", errors_errors[117], 26);
__MOVE("export mark doesn't match with forward declaration", errors_errors[118], 51);
__MOVE("redefinition textually precedes procedure bound to base type", errors_errors[119], 61);
__MOVE("type of expression following IF, WHILE, UNTIL or ASSERT is not BOOLEAN", errors_errors[120], 71);
__MOVE("called object is not a procedure (or is an interrupt procedure)", errors_errors[121], 64);

View file

@ -252,7 +252,7 @@ export void *vt100__init(void)
__REGCMD("RCP", vt100_RCP);
__REGCMD("SCP", vt100_SCP);
/* BEGIN */
__COPY("", vt100_CSI, ((LONGINT)(5)));
__COPY("\033", vt100_CSI, ((LONGINT)(5)));
Strings_Append((CHAR*)"[", (LONGINT)2, (void*)vt100_CSI, ((LONGINT)(5)));
__ENDMOD;
}