Commit f68a9855 authored by Olly Betts's avatar Olly Betts
Browse files

Fix code formatting oddities

parent 496d1882
......@@ -104,7 +104,9 @@ static void wlitarray(struct generator * g, symbol * p) { /* write literal arra
static void wlitref(struct generator * g, symbol * p) { /* write ref to literal array */
if (SIZE(p) == 0) write_char(g, '0'); else {
if (SIZE(p) == 0) {
write_char(g, '0');
} else {
struct str * s = g->outbuf;
g->outbuf = g->declarations;
write_string(g, "static const symbol s_"); write_int(g, g->literalstring_count); write_string(g, "[] = ");
......@@ -252,8 +254,7 @@ static void write_failure(struct generator * g, struct node * p) { /* f
}
write_char(g, ' ');
}
switch (g->failure_label)
{
switch (g->failure_label) {
case x_return:
write_string(g, "return 0;");
break;
......@@ -1314,8 +1315,7 @@ static void generate(struct generator * g, struct node * p) {
int a0 = g->failure_label;
int a1 = g->failure_keep_count;
switch (p->type)
{
switch (p->type) {
case c_define: generate_define(g, p); break;
case c_bra: generate_bra(g, p); break;
case c_and: generate_and(g, p); break;
......@@ -1433,8 +1433,7 @@ static void generate_among_table(struct generator * g, struct among * x) {
g->I[0] = x->number;
{
int i;
for (i = 0; i < x->literalstring_count; i++)
{
for (i = 0; i < x->literalstring_count; i++) {
g->I[1] = i;
g->I[2] = v->size;
g->L[0] = v->b;
......@@ -1458,8 +1457,11 @@ static void generate_among_table(struct generator * g, struct among * x) {
g->S[0] = i < x->literalstring_count - 1 ? "," : "";
w(g, "/*~J1 */ { ~I2, ");
if (v->size == 0) w(g, "0,");
else w(g, "s_~I0_~I1,");
if (v->size == 0) {
w(g, "0,");
} else {
w(g, "s_~I0_~I1,");
}
w(g, " ~I3, ~I4, ");
if (v->function == 0) {
write_char(g, '0');
......
......@@ -163,8 +163,7 @@ static void write_failure(struct generator * g) {
write_newline(g);
}
write_margin(g);
switch (g->failure_label)
{
switch (g->failure_label) {
case x_return:
write_string(g, "return false;");
break;
......@@ -1030,8 +1029,7 @@ static void generate(struct generator * g, struct node * p) {
int a0 = g->failure_label;
struct str * a1 = str_copy(g->failure_str);
switch (p->type)
{
switch (p->type) {
case c_define: generate_define(g, p); break;
case c_bra: generate_bra(g, p); break;
case c_and: generate_and(g, p); break;
......
......@@ -172,8 +172,7 @@ static void write_failure(struct generator * g) {
write_str(g, g->failure_str);
write_newline(g);
}
switch (g->failure_label)
{
switch (g->failure_label) {
case x_return:
w(g, "~Mreturn false~N");
g->unreachable = true;
......@@ -1030,8 +1029,7 @@ static void generate(struct generator * g, struct node * p) {
a0 = g->failure_label;
a1 = str_copy(g->failure_str);
switch (p->type)
{
switch (p->type) {
case c_define: generate_define(g, p); break;
case c_bra: generate_bra(g, p); break;
case c_and: generate_and(g, p); break;
......@@ -1126,16 +1124,14 @@ static void generate_among_table(struct generator * g, struct among * x) {
w(g, "~Mvar A_~I0 = []*snowballRuntime.Among{~N~+");
{
int i;
for (i = 0; i < x->literalstring_count; i++)
{
for (i = 0; i < x->literalstring_count; i++) {
g->I[0] = v->i;
g->I[1] = v->result;
g->L[0] = v->b;
g->S[0] = ",";
w(g, "~M&snowballRuntime.Among{Str:~L0, A:~I0, B:~I1, ");
if (v->function != 0)
{
if (v->function != 0) {
w(g, "F:");
write_varname(g, v->function);
} else {
......
......@@ -167,8 +167,7 @@ static void write_failure(struct generator * g) {
write_newline(g);
}
write_margin(g);
switch (g->failure_label)
{
switch (g->failure_label) {
case x_return:
write_string(g, "return false;");
g->unreachable = true;
......@@ -997,8 +996,7 @@ static void generate(struct generator * g, struct node * p) {
a0 = g->failure_label;
a1 = str_copy(g->failure_str);
switch (p->type)
{
switch (p->type) {
case c_define: generate_define(g, p); break;
case c_bra: generate_bra(g, p); break;
case c_and: generate_and(g, p); break;
......
......@@ -163,8 +163,7 @@ static void write_failure(struct generator * g) {
write_newline(g);
}
write_margin(g);
switch (g->failure_label)
{
switch (g->failure_label) {
case x_return:
write_string(g, "return false;");
g->unreachable = true;
......@@ -1041,8 +1040,7 @@ static void generate(struct generator * g, struct node * p) {
a0 = g->failure_label;
a1 = str_copy(g->failure_str);
switch (p->type)
{
switch (p->type) {
case c_define: generate_define(g, p); break;
case c_bra: generate_bra(g, p); break;
case c_and: generate_and(g, p); break;
......@@ -1144,8 +1142,7 @@ static void generate_among_table(struct generator * g, struct among * x) {
w(g, "~M/** @const */ var a_~I0 = [~N~+");
{
int i;
for (i = 0; i < x->literalstring_count; i++)
{
for (i = 0; i < x->literalstring_count; i++) {
g->I[0] = v->i;
g->I[1] = v->result;
g->L[0] = v->b;
......
......@@ -195,8 +195,7 @@ static void write_failure(struct generator * g) {
write_newline(g);
}
write_margin(g);
switch (g->failure_label)
{
switch (g->failure_label) {
case x_return:
write_string(g, "Begin Result := False; Exit; End;");
break;
......@@ -1052,8 +1051,7 @@ static void generate(struct generator * g, struct node * p) {
a0 = g->failure_label;
a1 = str_copy(g->failure_str);
switch (p->type)
{
switch (p->type) {
case c_define: generate_define(g, p); break;
case c_bra: generate_bra(g, p); break;
case c_and: generate_and(g, p); break;
......@@ -1214,8 +1212,7 @@ static void generate_among_table(struct generator * g, struct among * x) {
w(g, "~MSetLength(a_~I0, ~I1);~N~+");
for (i = 0; i < x->literalstring_count; i++, v++)
{
for (i = 0; i < x->literalstring_count; i++, v++) {
g->I[1] = i;
/* Write among's string. */
......
......@@ -169,8 +169,7 @@ static void write_failure(struct generator * g) {
write_str(g, g->failure_str);
write_newline(g);
}
switch (g->failure_label)
{
switch (g->failure_label) {
case x_return:
w(g, "~Mreturn False~N");
g->unreachable = true;
......@@ -1042,8 +1041,7 @@ static void generate(struct generator * g, struct node * p) {
a0 = g->failure_label;
a1 = str_copy(g->failure_str);
switch (p->type)
{
switch (p->type) {
case c_define: generate_define(g, p); break;
case c_bra: generate_bra(g, p); break;
case c_and: generate_and(g, p); break;
......@@ -1144,16 +1142,14 @@ static void generate_among_table(struct generator * g, struct among * x) {
w(g, "~Ma_~I0 = [~N~+");
{
int i;
for (i = 0; i < x->literalstring_count; i++)
{
for (i = 0; i < x->literalstring_count; i++) {
g->I[0] = v->i;
g->I[1] = v->result;
g->L[0] = v->b;
g->S[0] = i < x->literalstring_count - 1 ? "," : "";
w(g, "~MAmong(~L0, ~I0, ~I1");
if (v->function != 0)
{
if (v->function != 0) {
w(g, ", \"");
if (v->function->type == t_routine) {
/* Need to use mangled version of private name here. */
......@@ -1242,8 +1238,7 @@ static void generate_methods(struct generator * g) {
static void generate_label_classes(struct generator * g)
{
int i;
for (i = 0; i <= g->max_label; i++)
{
for (i = 0; i <= g->max_label; i++) {
g->I[0] = i;
w(g, "~N~Nclass lab~I0(BaseException): pass~N");
}
......
......@@ -171,8 +171,7 @@ static void write_failure(struct generator * g) {
write_str(g, g->failure_str);
write_newline(g);
}
switch (g->failure_label)
{
switch (g->failure_label) {
case x_return:
w(g, "~Mreturn false;~N");
g->unreachable = true;
......@@ -1030,8 +1029,7 @@ static void generate(struct generator * g, struct node * p) {
a0 = g->failure_label;
a1 = str_copy(g->failure_str);
switch (p->type)
{
switch (p->type) {
case c_define: generate_define(g, p); break;
case c_bra: generate_bra(g, p); break;
case c_and: generate_and(g, p); break;
......@@ -1135,16 +1133,14 @@ static void generate_among_table(struct generator * g, struct among * x) {
w(g, "~Mstatic A_~I0: &'static [Among<Context>; ~I1] = &[~N~+");
{
int i;
for (i = 0; i < x->literalstring_count; i++)
{
for (i = 0; i < x->literalstring_count; i++) {
g->I[0] = v->i;
g->I[1] = v->result;
g->L[0] = v->b;
g->S[0] = ",";
w(g, "~MAmong(~L0, ~I0, ~I1, ");
if (v->function != 0)
{
if (v->function != 0) {
w(g, "Some(&");
write_varname(g, v->function);
w(g, ")");
......
......@@ -362,110 +362,114 @@ extern int read_token(struct tokeniser * t) {
int code = next_token(t);
switch (code) {
case c_comment1: /* slash-slash comment */
while (t->c < SIZE(p) && p[t->c] != '\n') t->c++;
continue;
while (t->c < SIZE(p) && p[t->c] != '\n') t->c++;
continue;
case c_comment2: /* slash-star comment */
while (true) {
if (t->c >= SIZE(p)) {
error1(t, "/* comment not terminated");
t->token = -1;
return -1;
}
if (p[t->c] == '\n') t->line_number++;
if (eq_s(t, "*/")) break;
t->c++;
}
continue;
case c_stringescapes:
{
int ch1 = next_real_char(t);
int ch2 = next_real_char(t);
if (ch2 < 0)
{ error2(t, "stringescapes"); continue; }
if (ch1 == '\'')
{ error1(t, "first stringescape cannot be '"); continue; }
t->m_start = ch1;
t->m_end = ch2;
}
continue;
case c_stringdef:
{
int base = 0;
read_chars(t);
code = read_token(t);
if (code == c_hex) { base = 16; code = read_token(t); } else
if (code == c_decimal) { base = 10; code = read_token(t); }
if (code != c_literalstring)
{ error1(t, "string omitted after stringdef"); continue; }
if (base > 0) convert_numeric_string(t, t->b, base);
{ NEW(m_pair, q);
q->next = t->m_pairs;
q->name = copy_b(t->b2);
q->value = copy_b(t->b);
t->m_pairs = q;
if (t->uplusmode != UPLUS_DEFINED &&
(SIZE(t->b2) >= 3 && t->b2[0] == 'U' && t->b2[1] == '+')) {
if (t->uplusmode == UPLUS_UNICODE) {
error1(t, "U+xxxx already used with implicit meaning");
} else {
t->uplusmode = UPLUS_DEFINED;
}
}
}
}
continue;
while (true) {
if (t->c >= SIZE(p)) {
error1(t, "/* comment not terminated");
t->token = -1;
return -1;
}
if (p[t->c] == '\n') t->line_number++;
if (eq_s(t, "*/")) break;
t->c++;
}
continue;
case c_stringescapes: {
int ch1 = next_real_char(t);
int ch2 = next_real_char(t);
if (ch2 < 0) {
error2(t, "stringescapes");
continue;
}
if (ch1 == '\'') {
error1(t, "first stringescape cannot be '");
continue;
}
t->m_start = ch1;
t->m_end = ch2;
continue;
}
case c_stringdef: {
int base = 0;
read_chars(t);
code = read_token(t);
if (code == c_hex) { base = 16; code = read_token(t); } else
if (code == c_decimal) { base = 10; code = read_token(t); }
if (code != c_literalstring) {
error1(t, "string omitted after stringdef");
continue;
}
if (base > 0) convert_numeric_string(t, t->b, base);
{ NEW(m_pair, q);
q->next = t->m_pairs;
q->name = copy_b(t->b2);
q->value = copy_b(t->b);
t->m_pairs = q;
if (t->uplusmode != UPLUS_DEFINED &&
(SIZE(t->b2) >= 3 && t->b2[0] == 'U' && t->b2[1] == '+')) {
if (t->uplusmode == UPLUS_UNICODE) {
error1(t, "U+xxxx already used with implicit meaning");
} else {
t->uplusmode = UPLUS_DEFINED;
}
}
}
continue;
}
case c_get:
code = read_token(t);
if (code != c_literalstring) {
error1(t, "string omitted after get"); continue;
}
t->get_depth++;
if (t->get_depth > 10) {
fprintf(stderr, "get directives go 10 deep. Looping?\n");
exit(1);
}
{
NEW(input, q);
char * file = b_to_s(t->b);
symbol * u = get_input(file);
if (u == 0) {
struct include * r;
for (r = t->includes; r; r = r->next) {
symbol * b = copy_b(r->b);
b = add_to_b(b, SIZE(t->b), t->b);
free(file);
file = b_to_s(b);
u = get_input(file);
lose_b(b);
if (u != 0) break;
}
}
if (u == 0) {
error(t, "Can't get '", SIZE(t->b), t->b, "'");
exit(1);
}
memmove(q, t, sizeof(struct input));
t->next = q;
t->p = u;
t->c = 0;
t->file = file;
t->file_needs_freeing = true;
t->line_number = 1;
}
p = t->p;
continue;
code = read_token(t);
if (code != c_literalstring) {
error1(t, "string omitted after get"); continue;
}
t->get_depth++;
if (t->get_depth > 10) {
fprintf(stderr, "get directives go 10 deep. Looping?\n");
exit(1);
}
{
NEW(input, q);
char * file = b_to_s(t->b);
symbol * u = get_input(file);
if (u == 0) {
struct include * r;
for (r = t->includes; r; r = r->next) {
symbol * b = copy_b(r->b);
b = add_to_b(b, SIZE(t->b), t->b);
free(file);
file = b_to_s(b);
u = get_input(file);
lose_b(b);
if (u != 0) break;
}
}
if (u == 0) {
error(t, "Can't get '", SIZE(t->b), t->b, "'");
exit(1);
}
memmove(q, t, sizeof(struct input));
t->next = q;
t->p = u;
t->c = 0;
t->file = file;
t->file_needs_freeing = true;
t->line_number = 1;
}
p = t->p;
continue;
case -1:
if (t->next) {
lose_b(p);
{
struct input * q = t->next;
memmove(t, q, sizeof(struct input)); p = t->p;
FREE(q);
}
t->get_depth--;
continue;
}
/* fall through */
if (t->next) {
lose_b(p);
{
struct input * q = t->next;
memmove(t, q, sizeof(struct input)); p = t->p;
FREE(q);
}
t->get_depth--;
continue;
}
/* fall through */
default:
t->previous_token = t->token;
t->token = code;
......
......@@ -253,8 +253,13 @@ extern int find_among(struct SN_env * z, const struct among * v, int v_size) {
common++;
}
}
if (diff < 0) { j = k; common_j = common; }
else { i = k; common_i = common; }
if (diff < 0) {
j = k;
common_j = common;
} else {
i = k;
common_i = common;
}
if (j - i <= 1) {
if (i > 0) break; /* v->s has been inspected */
if (j == i) break; /* only one item in v */
......@@ -383,9 +388,8 @@ extern int replace_s(struct SN_env * z, int c_bra, int c_ket, int s_size, const
z->l += adjustment;
if (z->c >= c_ket)
z->c += adjustment;
else
if (z->c > c_bra)
z->c = c_bra;
else if (z->c > c_bra)
z->c = c_bra;
}
if (s_size) memmove(z->p + c_bra, s, s_size * sizeof(symbol));
if (adjptr != NULL)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment