Implement the _Alignof operator (from C11).
In ORCA/C, the alignment of all object types is 1.
This commit is contained in:
parent
9036a98e1c
commit
3121a465f1
|
@ -576,6 +576,7 @@ label 1,2,3;
|
||||||
var
|
var
|
||||||
done,done2: boolean; {for loop termination}
|
done,done2: boolean; {for loop termination}
|
||||||
doingSizeof: boolean; {used to test for a sizeof operator}
|
doingSizeof: boolean; {used to test for a sizeof operator}
|
||||||
|
doingAlignof: boolean; {used to test for an _Alignof operator}
|
||||||
expectingTerm: boolean; {should the next token be a term?}
|
expectingTerm: boolean; {should the next token be a term?}
|
||||||
opStack: tokenPtr; {operation stack}
|
opStack: tokenPtr; {operation stack}
|
||||||
parenCount: integer; {# of open parenthesis}
|
parenCount: integer; {# of open parenthesis}
|
||||||
|
@ -1228,6 +1229,7 @@ var
|
||||||
opplusplus, {postfix ++}
|
opplusplus, {postfix ++}
|
||||||
opminusminus, {postfix --}
|
opminusminus, {postfix --}
|
||||||
sizeofsy, {sizeof}
|
sizeofsy, {sizeof}
|
||||||
|
_Alignofsy, {_Alignof (erroneous uses)}
|
||||||
castoper, {(type)}
|
castoper, {(type)}
|
||||||
typedef, {(type-name)}
|
typedef, {(type-name)}
|
||||||
tildech, {~}
|
tildech, {~}
|
||||||
|
@ -1254,6 +1256,15 @@ var
|
||||||
end; {else}
|
end; {else}
|
||||||
op^.left := nil;
|
op^.left := nil;
|
||||||
end {if sizeofsy}
|
end {if sizeofsy}
|
||||||
|
|
||||||
|
else if op^.token.kind = _Alignofsy then begin
|
||||||
|
{error case: operand of _Alignof is not a parenthesized type-name}
|
||||||
|
Error(36);
|
||||||
|
op^.token.kind := ulongConst;
|
||||||
|
op^.token.class := longConstant;
|
||||||
|
op^.token.lval := 1;
|
||||||
|
dispose(op^.left);
|
||||||
|
end {else if _Alignofsy}
|
||||||
|
|
||||||
else if op^.token.kind = castoper then begin
|
else if op^.token.kind = castoper then begin
|
||||||
class := op^.left^.token.class;
|
class := op^.left^.token.class;
|
||||||
|
@ -1486,7 +1497,7 @@ var
|
||||||
if token.kind = constsy then
|
if token.kind = constsy then
|
||||||
tp^.isConstant := true
|
tp^.isConstant := true
|
||||||
else {if token.kind = volatilesy then}
|
else {if token.kind = volatilesy then}
|
||||||
if not doingSizeof then
|
if not (doingSizeof or doingAlignof) then
|
||||||
volatile := true;
|
volatile := true;
|
||||||
NextToken;
|
NextToken;
|
||||||
end; {while}
|
end; {while}
|
||||||
|
@ -1659,11 +1670,14 @@ if token.kind in startExpression then begin
|
||||||
doublesy,compsy,extendedsy,voidsy,enumsy,structsy,unionsy,
|
doublesy,compsy,extendedsy,voidsy,enumsy,structsy,unionsy,
|
||||||
typedef,constsy,volatilesy,signedsy] then begin
|
typedef,constsy,volatilesy,signedsy] then begin
|
||||||
doingSizeof := false;
|
doingSizeof := false;
|
||||||
|
doingAlignof := false;
|
||||||
if opStack <> nil then
|
if opStack <> nil then
|
||||||
if opStack^.token.kind = sizeofsy then
|
if opStack^.token.kind = sizeofsy then
|
||||||
doingSizeof := true;
|
doingSizeof := true
|
||||||
|
else if opStack^.token.kind = _Alignofsy then
|
||||||
|
doingAlignof := true;
|
||||||
TypeName;
|
TypeName;
|
||||||
if doingSizeof then begin
|
if doingSizeof or doingAlignof then begin
|
||||||
|
|
||||||
{handle a sizeof operator}
|
{handle a sizeof operator}
|
||||||
op := opStack;
|
op := opStack;
|
||||||
|
@ -1676,10 +1690,13 @@ if token.kind in startExpression then begin
|
||||||
sp^.right := nil;
|
sp^.right := nil;
|
||||||
sp^.token.kind := ulongconst;
|
sp^.token.kind := ulongconst;
|
||||||
sp^.token.class := longConstant;
|
sp^.token.class := longConstant;
|
||||||
sp^.token.lval := typeSpec^.size;
|
if doingSizeof then
|
||||||
|
sp^.token.lval := typeSpec^.size
|
||||||
|
else {if doingAlignof then}
|
||||||
|
sp^.token.lval := 1;
|
||||||
with typeSpec^ do
|
with typeSpec^ do
|
||||||
if (size = 0) or ((kind = arrayType) and (elements = 0)) then
|
if (size = 0) or ((kind = arrayType) and (elements = 0)) then
|
||||||
Error(49);
|
Error(133);
|
||||||
sp^.next := stack;
|
sp^.next := stack;
|
||||||
stack := sp;
|
stack := sp;
|
||||||
expectingTerm := false;
|
expectingTerm := false;
|
||||||
|
@ -1743,7 +1760,7 @@ if token.kind in startExpression then begin
|
||||||
errorFound := true;
|
errorFound := true;
|
||||||
end; {if}
|
end; {if}
|
||||||
if token.kind in {make sure we get what we want}
|
if token.kind in {make sure we get what we want}
|
||||||
[plusplusop,minusminusop,sizeofsy,tildech,excch,
|
[plusplusop,minusminusop,sizeofsy,_Alignofsy,tildech,excch,
|
||||||
uasterisk,uminus,uand] then begin
|
uasterisk,uminus,uand] then begin
|
||||||
if not expectingTerm then begin
|
if not expectingTerm then begin
|
||||||
Error(38);
|
Error(38);
|
||||||
|
@ -3999,7 +4016,7 @@ startTerm := [ident,intconst,uintconst,longconst,ulongconst,doubleconst,
|
||||||
stringconst];
|
stringconst];
|
||||||
startExpression:= startTerm +
|
startExpression:= startTerm +
|
||||||
[lparench,asteriskch,andch,plusch,minusch,excch,tildech,sizeofsy,
|
[lparench,asteriskch,andch,plusch,minusch,excch,tildech,sizeofsy,
|
||||||
plusplusop,minusminusop,typedef];
|
plusplusop,minusminusop,typedef,_Alignofsy];
|
||||||
end; {InitExpression}
|
end; {InitExpression}
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -647,6 +647,7 @@ if list or (numErr <> 0) then begin
|
||||||
130: msg := @'lint: invalid shift count';
|
130: msg := @'lint: invalid shift count';
|
||||||
131: msg := @'numeric constant is too long';
|
131: msg := @'numeric constant is too long';
|
||||||
132: msg := @'static assertion failed';
|
132: msg := @'static assertion failed';
|
||||||
|
133: msg := @'incomplete or function types may not be used here';
|
||||||
otherwise: Error(57);
|
otherwise: Error(57);
|
||||||
end; {case}
|
end; {case}
|
||||||
writeln(msg^);
|
writeln(msg^);
|
||||||
|
|
|
@ -359,7 +359,7 @@ icp start in comming priority for expression
|
||||||
dc i1'200' doubleconst
|
dc i1'200' doubleconst
|
||||||
dc i1'200' stringconst
|
dc i1'200' stringconst
|
||||||
dc i1'200' _Alignassy
|
dc i1'200' _Alignassy
|
||||||
dc i1'200' _Alignofsy
|
dc i1'16' _Alignofsy
|
||||||
dc i1'200' _Atomicsy
|
dc i1'200' _Atomicsy
|
||||||
dc i1'200' _Boolsy
|
dc i1'200' _Boolsy
|
||||||
dc i1'200' _Complexsy
|
dc i1'200' _Complexsy
|
||||||
|
@ -524,7 +524,7 @@ isp start in stack priority for expression
|
||||||
dc i1'0' doubleconst
|
dc i1'0' doubleconst
|
||||||
dc i1'0' stringconst
|
dc i1'0' stringconst
|
||||||
dc i1'0' _Alignassy
|
dc i1'0' _Alignassy
|
||||||
dc i1'0' _Alignofsy
|
dc i1'16' _Alignofsy
|
||||||
dc i1'0' _Atomicsy
|
dc i1'0' _Atomicsy
|
||||||
dc i1'0' _Boolsy
|
dc i1'0' _Boolsy
|
||||||
dc i1'0' _Complexsy
|
dc i1'0' _Complexsy
|
||||||
|
|
Loading…
Reference in New Issue