⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stmt.c

📁 一款拥有一定历史的C语言编译器
💻 C
📖 第 1 页 / 共 2 页
字号:
	}    }}#endif /* SYNTAX_CORRECT */static STMT *switchstmt P0 (void){    STMT   *snp = mk_stmt (st_switch);    STMT   *local_last_case = last_case;    TYP    *local_last_switch_type = last_switch_type;#ifndef SYNTAX_CORRECT    break_lvl++;    case_lvl++;#endif /* SYNTAX_CORRECT */    getsym ();    last_case = snp;    snp->s1 = NIL_STMT;    needpunc (tk_openpa);    snp->exp = integral_expression ();#ifndef SYNTAX_CORRECT    sequence_point ();    check_unconditional (snp->exp, "switch");#endif /* SYNTAX_CORRECT */    last_switch_type = snp->exp->etp;    needpunc (tk_closepa);#ifndef SYNTAX_CORRECT    need_label = TRUE;#endif /* SYNTAX_CORRECT */    snp->v1.s = statement ();#ifndef SYNTAX_CORRECT    need_label = FALSE;		/* currently too difficult to work out if true */    check_cases (snp->s1);#ifdef FACIST    {	STMT   *cur;	for (cur = snp->s1; cur != NIL_STMT; cur = cur->s1) {	    if (cur->stype == st_default) {		break;	    }	}	if (cur == NIL_STMT) {	    message (WARN_DEFAULT);	}    }#endif /* FACIST */    break_lvl--;    case_lvl--;#endif /* SYNTAX_CORRECT */    last_case = local_last_case;    last_switch_type = local_last_switch_type;    return snp;}static STMT *retstmt P0 (void){    STMT   *snp;    snp = mk_stmt (st_return);    getsym ();    snp->exp = expression ();#ifndef SYNTAX_CORRECT    sequence_point ();#endif /* SYNTAX_CORRECT */    if (snp->exp != NIL_EXPR) {#ifndef SYNTAX_CORRECT	if (is_void (ret_type)) {	    message (ERR_VOIDFUNC);	} else if (is_void (snp->exp->etp)) {	    message (ERR_VOIDRETURN);	} else {	    if (snp->exp->nodetype == en_autocon) {		message (WARN_LOCAL);	    }	    check_qualifiers (ret_type, snp->exp->etp);#endif /* SYNTAX_CORRECT */	    snp->exp = implicit_castop (snp->exp, ret_type);#ifndef SYNTAX_CORRECT	}    } else if (!is_void (ret_type)) {	if (lang_option >= LANG_C99) {	    message (ERR_VALRETURN);	} else {	    message (WARN_VALRETURN);	}#endif /* SYNTAX_CORRECT */    }    needpunc (tk_semicolon);#ifndef SYNTAX_CORRECT    return_found = TRUE;    need_label = TRUE;#endif /* SYNTAX_CORRECT */    return snp;}static STMT *breakstmt P0 (void){    STMT   *snp;#ifndef SYNTAX_CORRECT    if (break_lvl == 0) {	message (ERR_BREAK);    }#endif /* SYNTAX_CORRECT */    snp = mk_stmt (st_break);    getsym ();    needpunc (tk_semicolon);#ifndef SYNTAX_CORRECT    need_label = TRUE;#endif /* SYNTAX_CORRECT */    return snp;}static STMT *contstmt P0 (void){    STMT   *snp;#ifndef SYNTAX_CORRECT    if (cont_lvl == 0) {	message (ERR_CONT);    }#endif /* SYNTAX_CORRECT */    snp = mk_stmt (st_continue);    getsym ();    needpunc (tk_semicolon);#ifndef SYNTAX_CORRECT    need_label = TRUE;#endif /* SYNTAX_CORRECT */    return snp;}/* * exprstmt is called whenever a statement does not begin with a keyword. the * statement should be an expression. */static STMT *exprstmt P0 (void){    STMT   *snp;    if (lastst == tk_semicolon) {	snp = NIL_STMT;    } else {	snp = mk_stmt (st_expr);	snp->exp = expression ();#ifndef SYNTAX_CORRECT	if (snp->exp == NIL_EXPR) {	    /* brute force fix to detect loop */	    if (errorloop) {		message (ERR_EXPREXPECT);	    } else {		errorloop = TRUE;		getsym ();	    }	} else {	    check_discard (snp->exp);	}#endif /* SYNTAX_CORRECT */    }#ifndef SYNTAX_CORRECT    sequence_point ();#endif /* SYNTAX_CORRECT */    needpunc (tk_semicolon);    return snp;}/* * compound processes a block of statements and forms a linked list of the * statements within the block. */static STMT *compound P0 (void){    STMT   *stmthead, *stmttail, *snp;    lc_auto = declaration_list (sc_auto, lc_auto);    snp = mk_stmt (st_compound);    if (init_node == NIL_EXPR) {	stmthead = NIL_STMT;    } else {	stmthead = stmttail = mk_stmt (st_expr);	stmthead->exp = init_node;	stmthead->next = NIL_STMT;    }    init_node = NIL_EXPR;    while (lastst != tk_end) {	if (stmthead == NIL_STMT) {	    stmthead = stmttail = statement ();	} else {	    stmttail->next = statement ();  /*lint !e644*/  /* variable may not have been initialized */	    if (stmttail->next != NIL_STMT) {		stmttail = stmttail->next;	    }	}    }    snp->s1 = stmthead;    return snp;}/* * labelstmt processes a label that appears before a statement as a separate * statement. */static STMT *labelstmt P0 (void){    STMT   *snp;    snp = mk_stmt (st_label);    snp->v2.l = lab_define (lastsym);    getsym ();    needpunc (tk_colon);    snp->v1.s = statement ();    return snp;}/* * gotostmt processes the goto statement */static STMT *gotostmt P0 (void){    STMT   *snp;    snp = mk_stmt (st_goto);    getsym ();    if (lastst == tk_id) {	snp->v2.l = lab_search (lastsym);	getsym ();		/* get past label name */#ifndef SYNTAX_CORRECT    } else {	message (ERR_IDEXPECT);#endif /* SYNTAX_CORRECT */    }    needpunc (tk_semicolon);#ifndef SYNTAX_CORRECT    need_label = TRUE;#endif /* SYNTAX_CORRECT */    return snp;}#ifdef ASMstatic STMT *asmstmt P0 (void){    STMT   *snp;    snp = mk_stmt (st_asm);    getsym ();    needpunc (tk_openpa);    snp->exp = asm_expression ();    needpunc (tk_closepa);    return snp;}#endif /* ASM */#ifdef TRACE/* * tracestmt adds calls to a run-time tracing/debugging routine. */static STMT *tracestmt P0 (void){    STMT   *snp;    snp = mk_stmt (st_compound);    snp->s1 = mk_stmt (st_expr);    snp->s1->exp = traceexpr ();    return snp;}#endif /* TRACE *//* * statement figures out which of the statement processors should be called * and transfers control to the proper routine. */static STMT *statement P0 (void){    STMT   *snp;#ifdef TRACE    STMT   *tsnp;    if (trace_option) {	tsnp = tracestmt ();    }#endif /* TRACE */#ifndef SYNTAX_CORRECT    switch (lastst) {    default:	if (need_label) {	    message (WARN_NOTREACHED);	}	/*lint -fallthrough */    case kw_case:    case kw_default:	need_label = FALSE;	/*lint -fallthrough */    case tk_begin:    case tk_id:	break;    }#endif /* SYNTAX_CORRECT */    switch (lastst) {#ifdef ASM    case kw_asm:	snp = asmstmt ();	break;#endif /* ASM */    case tk_begin:	needpunc (tk_begin);	beginblock ();	snp = compound ();	endblock ();	needpunc (tk_end);	break;    case kw_if:	snp = ifstmt ();	break;    case kw_while:	snp = whilestmt ();	break;    case kw_for:	if (lang_option >= LANG_C99) {	    beginblock ();	    snp = forstmt ();	    endblock ();	} else {	    snp = forstmt ();	}	break;    case kw_return:	snp = retstmt ();	break;    case kw_break:	snp = breakstmt ();	break;    case kw_goto:	snp = gotostmt ();	break;    case kw_continue:	snp = contstmt ();	break;    case kw_do:	snp = dostmt ();	break;    case kw_switch:	snp = switchstmt ();	break;    case kw_case:    case kw_default:	snp = casestmt ();	break;    case tk_id:	if (is_label (lastst)) {#ifndef SYNTAX_CORRECT	    need_label = FALSE;#endif /* SYNTAX_CORRECT */	    snp = labelstmt ();	    break;	}	/* else fall through to process expression */
	/*lint -fallthrough*/    default:#ifndef SYNTAX_CORRECT	if (need_label) {	    message (WARN_NOTREACHED);	}	need_label = FALSE;#endif /* SYNTAX_CORRECT */	if (lang_option >= LANG_C99) {	    lc_auto = declaration_list (sc_auto, lc_auto);	}	snp = exprstmt ();	break;    }#ifdef TRACE    if (trace_option) {	tsnp->s1->next = snp;	return tsnp;    }#endif /* TRACE */    return snp;}/* * funcbody starts with the current symbol being the begin for the local * block or the first symbol of the parameter declaration */void funcbody P2 (SYM *, sp, const BLOCK *, block){    int     old_global;#ifdef CPU_DEFINED    STMT   *stmt;    SIZE    poffset, return_block;    LINE    line = act_line;    SYM    *sp1;

#ifdef DEBUGOPT    const CHAR *linetxt = mk_string (act_linetxt);#else    const CHAR *linetxt = (const CHAR *) NULL;
    assert (block != NULL);
#endif /* DEBUGOPT */#endif /* CPU_DEFINED */    STARTTIME (ltime);#ifdef VERBOSE    if (verbose_option) {	eprintf ("%s%s", nameof (sp), newline);    }#endif /* VERBOSE */    uses_structassign = FALSE;    lc_auto_max = lc_auto = 0L;#ifndef SYNTAX_CORRECT    need_label = FALSE;    return_found = FALSE;#endif /* SYNTAX_CORRECT */    is_leaf_function = TRUE;    init_node = NIL_EXPR;    old_global = global_flag;
    global_flag = 0;

    ret_type = returned_type (typeof (sp));#ifdef CPU_DEFINED    return_block = tp_pointer->size;	/* return address */    return_block += tp_pointer->size;	/* saved frame pointer */    if (is_structure_type (ret_type)) {	return_block += tp_pointer->size;    }    poffset = return_block;
    if (block) {	for (sp1 = symbolsof (block); sp1; sp1 = nextsym (sp1)) {	    BOOL    promote = promoteparam_option || !is_ansi (typeof (sp));	    poffset = allocate_storage (sp1, poffset, sc_parms, promote);	    addoptinfo (sp1, sc_parms);	}
    }#endif /* CPU_DEFINED */    needpunc (tk_begin);    beginfuncblock (block);#ifdef CPU_DEFINED    stmt = compound ();
#else    VOIDCAST compound ();#endif /* CPU_DEFINED */    check_labels ();#ifndef SYNTAX_CORRECT    if (!is_void (ret_type) && !return_found) {	message (WARN_IMPLICITRET);    }#endif /* SYNTAX_CORRECT */    DOTIME (parse_time, ltime);#ifdef ICODE    if (icode_option) {	iprintf ("%s:\n", nameof (sp));	genicode (stmt, 0);    }#endif /* ICODE */#ifdef CPU_DEFINED#ifdef DOINLINE
    if (is_inline (sp) && (inline_statement_cost (stmt) < inline_option)) {
	sp->value.stmt = copystmttree (stmt);
    } else
#endif /* DOINLINE */
    {
	sp->value.stmt = NIL_STMT;
	if (code_option) {	    CSE    *cse = globalopt (stmt);
	    DOTIME (opt_time, ltime);	    genfunc (sp, stmt, cse, line, linetxt);	    DOTIME (gen_time, ltime);	}
    }#endif /* CPU_DEFINED */    endfuncblock ();    needpunc (tk_end);
    rel_autolst ();
    rel_reglst ();    rel_local ();		/* release local symbols */    global_flag = old_global;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -