📄 expr.c
字号:
error("Cannot test unsigned for < 0");
else
testlteq0(JumpOutLabel, TRUE, stpt->type);
}
else {
gpush(stpt->type);
InX = 1;
EvalRight(heir7, stpt, &state2);
if (stpt->type == UCCHAR || stpt->type == UCINT)
gule(stpt->type);
else
gle(stpt->type);
}
}
else
if (match(">=")) {
blanks();
if (ch() == '0' && !(nch() == 'x' || nch() == 'X')) {
match("0");
if (stpt->type == UCCHAR || stpt->type == UCINT)
error("This is ALWAYS true for unsigned");
else
testgteq0(JumpOutLabel, TRUE, stpt->type);
}
else {
gpush(stpt->type);
InX = 1;
EvalRight(heir7, stpt, &state2);
if (stpt->type == UCCHAR || stpt->type == UCINT)
guge(stpt->type);
else
gge(stpt->type);
}
}
else
if ((sstreq("<")) && !sstreq("<<")) {
inbyte();
blanks();
if (ch() == '0' && !(nch() == 'x' || nch() == 'X')) {
match("0");
if (stpt->type == UCCHAR || stpt->type == UCINT)
error("Cannot test unsigned for < 0");
else
testlt0(JumpOutLabel, TRUE, stpt->type);
}
else {
gpush(stpt->type);
InX = 1;
EvalRight(heir7, stpt, &state2);
if (stpt->type == UCCHAR || stpt->type == UCINT)
gult(stpt->type);
else
glt(stpt->type);
}
}
else
if ((sstreq(">")) && !sstreq(">>")) {
inbyte();
blanks();
if (ch() == '0' && !(nch() == 'x' || nch() == 'X')) {
match("0");
if (stpt->type == UCCHAR || stpt->type == UCINT)
testjump(JumpOutLabel, FALSE, stpt->type);
else
testgt0(JumpOutLabel, TRUE, stpt->type);
}
else {
gpush(stpt->type);
InX = 1;
EvalRight(heir7, stpt, &state2);
if (stpt->type == UCCHAR || stpt->type == UCINT)
gugt(stpt->type);
else
ggt(stpt->type);
}
}
else {
// JumpPending = 1;
return (0);
}
blanks();
}
}
static int heir7(STATE *stpt) {
int k;
STATE state2;
k = heir8(stpt);
state2.cast = state2.pointing = 0;
blanks();
if (!sstreq(">>") && !sstreq("<<") || sstreq(">>=") || sstreq("<<="))
return (k);
if (k)
rvalue(stpt);
while (1) {
if (sstreq(">>") && !sstreq(">>=")) {
inbyte();
inbyte();
gpush(stpt->type);
Indexing = TRUE;
EvalRight(heir8, stpt, &state2);
Indexing = FALSE;
gasr(stpt->type);
}
else
if (sstreq("<<") && !sstreq("<<=")) {
inbyte();
inbyte();
gpush(stpt->type);
Indexing = TRUE;
EvalRight(heir8, stpt, &state2);
Indexing = FALSE;
gasl(stpt->type);
}
else
return (0);
blanks();
}
}
static int heir8(STATE *stpt) {
int k;
STATE state2;
k = heir9(stpt);
state2.cast = state2.pointing = 0;
blanks();
if ((ch() != '+') && (ch() != '-') || nch() == '=')
return (k);
if (k)
rvalue(stpt);
while (1) {
if (match("+")) {
if (stpt->ident == POINTER)
gpush(CINT);
else
gpush(stpt->type);
EvalRight(heir9, stpt, &state2);
if (stpt->ident == POINTER)
gadd(-1);
else
gadd(stpt->type);
}
else
if (match("-")) {
if (stpt->ident == POINTER && !stpt->pointing)
gpush(CINT);
else
gpush(stpt->type);
// InX = 1;
EvalRight(heir9, stpt, &state2);
if (stpt->ident == POINTER && !stpt->pointing)
gsub(-1);
else
gsub(stpt->type);
}
else {
Loaded = 1;
return (0);
}
stpt = &state2;
osymptr = state2.ptr;
}
}
static int heir9(STATE *stpt) {
int k;
STATE state2;
k = heir10(stpt);
state2.cast = state2.pointing = 0;
blanks();
if (((ch() != '*') && (ch() != '/') && (ch() != '%')) || (nch() == '='))
return (k);
if (k)
rvalue(stpt);
while (1) {
if (match("*")) {
gpush(stpt->type);
EvalRight(heir10, stpt, &state2);
if (stpt->type == UCCHAR || stpt->type == UCINT)
umult(stpt->type);
else
gmult(stpt->type);
}
else
if (match("/")) {
gpush(stpt->type);
InX = 1;
EvalRight(heir10, stpt, &state2);
if (stpt->type == UCCHAR || stpt->type == UCINT)
udiv(stpt->type);
else
gdiv(stpt->type);
}
else
if (match("%")) {
gpush(stpt->type);
EvalRight(heir10, stpt, &state2);
if (stpt->type == UCCHAR || stpt->type == UCINT)
umod(stpt->type);
else
gmod(stpt->type);
}
else
return (0);
stpt = &state2;
osymptr = stpt->ptr;
InX = 0;
}
}
int heir10(STATE *stpt) {
int k, i, ptr, offset, flag;
char sname[NAMESIZE];
if (match("gintoff")) {
gintoff();
return (0);
}
else
if (match("ginton")) {
ginton();
return (0);
}
else
if (testmatch(";"))
return(0);
else
if (match("++")) {
if ((k = heir10(stpt)) == 0) {
needlval();
return (0);
}
if (ch() != ';' && stpt->type)
gpush(CINT);
rvalue(stpt);
ginc(stpt);
store(stpt);
return (0);
}
else
if (match("--")) {
if ((k = heir10(stpt)) == 0) {
needlval();
return (0);
}
if (ch() != ';' && stpt->type)
gpush(CINT);
rvalue(stpt);
gdec(stpt);
store(stpt);
return (0);
}
else
if (match("-")) {
NegFlag = 1;
k = heir10(stpt);
if (k)
rvalue(stpt);
if (NegFlag)
gneg(stpt->type);
return (0);
}
else
if (match("~")) {
k = heir10(stpt);
if (k)
rvalue(stpt);
gcom(stpt->type);
return (0);
}
else
if (match("!")) {
k = heir10(stpt);
if (k)
rvalue(stpt);
glneg(stpt->type);
return (0);
}
else
if (ch() =='*' && nch() != '=') {
inbyte();
PointerFlag = 1;
k = heir10(stpt);
if (!(stpt->ident == FUNCPTR || stpt->ident == POINTER || stpt->ident == FUNCPTRARR))
error("Variable is not a pointer");
if (!rhs)
RHSisPntr = 1;
if (k) {
flag = 0;
if (symtab[stpt->ptr].reg & CONSTANT) {
// another "special case"!!!
flag = 1;
symtab[stpt->ptr].reg &= ~CONSTANT;
}
if (!stpt->cast && !Loaded)
rvalue(stpt);
if (flag)
symtab[stpt->ptr].reg |= CONSTANT;
// if (stpt->ident == FUNCPTR)
// gpush(CINT);
}
PointerFlag = 0;
stpt->pointing = 1; // the pointer is pointing
if ((rhs || ch() == ')') && stpt->storage == REGISTER)
stpt->storage = AUTO;
return (1);
}
else
if (ch() == '&' && nch() != '&' && nch() != '=') {
// address of operator
inbyte();
stpt->cast = POINTER; // force as pointer
k = heir10(stpt);
if (k == 0) {
error("illegal address");
return (0);
}
if (stpt->storage == PUBLIC && stkptr > 0) {
doimmed(stpt, 0, 0);
stkptr--;
}
stpt->cast = 0;
FuncArgType = POINTER; // flag as pointer (should use POINTER)
return (0);
}
else {
k = heir11(stpt);
if (match(".") && symname(sname)) {
if ((offset = GetStructItem(stpt, sname, &i)) < 0)
error("Structure member does not exist");
// if (StructureOffset == 2)
// gaslint();
// else
// if (StructureOffset == 4) {
// gaslint();
// gaslint();
// }
// else
StructureOffset = symtab[stpt->ptr].PerEntry;
// Should look at using "rhs" here:
if (ItemWasZero || !StructIsIndexed)
InX = 1;
doimmed(stpt, sname, offset);
if (!ItemWasZero && StructIsIndexed)
doStructOff(StructureOffset);
if (stpt->storage != AUTO) {
InX = 0;
stkptr--;
}
stpt->ident = symtab[stpt->ptr].entry[i].ident;
stpt->type = symtab[stpt->ptr].entry[i].type;
// stpt->storage = symtab[stpt->ptr].entry[i].storage;
stpt->storage = AUTO;
// if (offset > 0 && Emitting) {
// gpush(CINT);
// doimmed(offset);
// ol("add\tr26,r30");
// ol("adc\tr27,r31");
// prefix();
// onum(offset);
// nl();
// gadd(-1);
// ot("ldix\t");
// onum(offset);
// nl();
// ol("add\tr26,r30");
// ol("adc\tr27,r31");
// }
// else
stpt->offset = offset;
if (match("[")) {
ArrayFlag = 1;
if (symtab[stpt->ptr].entry[i].ident != ARRAY)
error("Cannot subscript");
StructureOffset = 0;
CINTpushPending = TRUE;
k = doIndexes(stpt);
if (k) {
GetStructItem(stpt, sname, &i);
if (symtab[stpt->ptr].entry[i].type == CINT)
gaslint();
else
if (symtab[stpt->ptr].entry[i].type == CLONG) {
gaslint();
gaslint();
}
gadd(-1);
Indexing = 0;
stpt->pointing = 1;
stpt->storage = AUTO;
}
ArrayFlag = 0;
}
if (rhs && stpt->ident == POINTER) {
ol("ld\tr27,z+");
ol("ld\tr26,z+");
InX = 1;
}
}
// else // commented 14/9/99
if (match("++")) {
if (k == 0) {
needlval();
return (0);
}
if (stpt->storage == AUTO && stpt->storage != REGISTER) {
gpush(CINT);
}
if (stpt->type == STRUCTINST)
InX = 1;
rvalue(stpt);
ginc(stpt);
store(stpt);
gdec(stpt);
// DecPending = 1;
if (!CallFunction && !rhs && stpt->storage == REGISTER && stpt->ident == POINTER)
gpush(CINT);
return (0);
}
else
if (match("--")) {
if (k == 0) {
needlval();
return (0);
}
if ((stpt->storage == AUTO) && stpt->storage != REGISTER) {
gpush(CINT);
}
rvalue(stpt);
gdec(stpt);
store(stpt);
ginc(stpt);
// IncPending = 1;
if (!CallFunction && !rhs && stpt->storage == REGISTER && stpt->ident == POINTER)
gpush(CINT);
return (0);
}
else
if (match("->")) {
ptr = symtab[stpt->ptr].pntrpntr;
if (symname(sname)) {
PointerFlag = 1;
rvalue(stpt);
stpt->ptr = ptr;
offset = GetStructItem(stpt, sname, &i);
stpt->ident = symtab[stpt->ptr].entry[i].ident;
stpt->type = symtab[stpt->ptr].entry[i].type;
stpt->storage = AUTO;
if (offset > 0 && Emitting) {
if (InX)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -