removed old version of !if/else/!ifdef/!ifndef algo.

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@188 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2020-05-24 19:52:10 +00:00
parent 486febcef4
commit d407faab1c
3 changed files with 22 additions and 100 deletions

View File

@ -201,52 +201,6 @@ void flow_do_while(struct do_while *loop)
}
// helper functions for "!if", "!ifdef" and "!ifndef"
// parse or skip a block. returns with GotByte as '}'.
// TODO - remove when ELSE IF is finished
static void skip_or_parse_block(boolean parse)
{
if (parse) {
Parse_until_eob_or_eof();
// if block isn't correctly terminated, complain and exit
if (GotByte != CHAR_EOB)
Throw_serious_error(exception_no_right_brace);
} else {
Input_skip_or_store_block(FALSE);
}
}
// parse {block} [else {block}]
// TODO - remove when ELSE IF is finished
void flow_parse_block_else_block(boolean parse_first)
{
// Parse first block.
skip_or_parse_block(parse_first);
// now GotByte = '}'. Check for "else" part.
// If end of statement, return immediately.
NEXTANDSKIPSPACE();
if (GotByte == CHAR_EOS)
return;
// read keyword and check whether really "else"
if (Input_read_and_lower_keyword()) {
if (strcmp(GlobalDynaBuf->buffer, "else")) {
Throw_error(exception_syntax);
} else {
SKIPSPACE();
if (GotByte != CHAR_SOB)
Throw_serious_error(exception_no_left_brace);
skip_or_parse_block(!parse_first);
// now GotByte = '}'
GetByte();
}
}
Input_ensure_EOS();
}
// parse a whole source code file
void flow_parse_and_close_file(FILE *fd, const char *filename)
{

View File

@ -57,8 +57,6 @@ extern void flow_store_while_condition(struct condition *condition);
extern void flow_do_while(struct do_while *loop);
// parse a whole source code file
extern void flow_parse_and_close_file(FILE *fd, const char *filename);
// parse {block} [else {block}]
extern void flow_parse_block_else_block(boolean parse_first);
#endif

View File

@ -587,7 +587,25 @@ static enum eos po_pseudopc(void)
// get new value
ALU_defined_int(&new_pc); // FIXME - allow for undefined! (complaining about non-addresses would be logical, but annoying)
// TODO - accept ', name = "section name"'
/* TODO - add this. check if code can be shared with "*="!
// check for modifiers
while (Input_accept_comma()) {
// parse modifier. if no keyword given, give up
if (Input_read_and_lower_keyword() == 0)
return SKIP_REMAINDER;
if (strcmp(GlobalDynaBuf->buffer, "limit") == 0) {
skip '='
read memory limit
} else if (strcmp(GlobalDynaBuf->buffer, "name") == 0) {
skip '='
read segment name (quoted string!)
} else {
Throw_error("Unknown !pseudopc segment modifier.");
return SKIP_REMAINDER;
}
}
*/
// remember old state in buffer, set new state
pseudopc_start(&buffer, &new_pc);
// if there's a block, parse that and then restore old value!
@ -974,69 +992,21 @@ static enum eos ifelse(enum ifmode mode)
// conditional assembly ("!if"). has to be re-entrant.
static enum eos po_if(void) // now GotByte = illegal char
{
struct number cond_result;
if (config.test_new_features)
return ifelse(IFMODE_IF);
ALU_defined_int(&cond_result);
if (GotByte != CHAR_SOB)
Throw_serious_error(exception_no_left_brace);
flow_parse_block_else_block(!!cond_result.val.intval);
return ENSURE_EOS;
}
// conditional assembly ("!ifdef" and "!ifndef"). has to be re-entrant.
// TODO - remove when new ifelse function is finished
static enum eos ifdef_ifndef(boolean invert) // now GotByte = illegal char
{
struct rwnode *node;
struct symbol *symbol;
scope_t scope;
int defined = FALSE;
if (Input_read_scope_and_keyword(&scope) == 0) // skips spaces before
return SKIP_REMAINDER;
Tree_hard_scan(&node, symbols_forest, scope, FALSE);
if (node) {
symbol = (struct symbol *) node->body;
// in first pass, count usage
if (FIRST_PASS)
symbol->usage++;
if (symbol->result.u.number.flags & NUMBER_IS_DEFINED)
defined = TRUE;
}
SKIPSPACE();
// if "ifndef", invert condition
if (invert)
defined = !defined;
if (GotByte != CHAR_SOB)
return defined ? PARSE_REMAINDER : SKIP_REMAINDER;
flow_parse_block_else_block(defined);
return ENSURE_EOS;
return ifelse(IFMODE_IF);
}
// conditional assembly ("!ifdef"). has to be re-entrant.
static enum eos po_ifdef(void) // now GotByte = illegal char
{
if (config.test_new_features)
return ifelse(IFMODE_IFDEF);
return ifdef_ifndef(FALSE);
return ifelse(IFMODE_IFDEF);
}
// conditional assembly ("!ifndef"). has to be re-entrant.
static enum eos po_ifndef(void) // now GotByte = illegal char
{
if (config.test_new_features)
return ifelse(IFMODE_IFNDEF);
return ifdef_ifndef(TRUE);
return ifelse(IFMODE_IFNDEF);
}