Correctly implement negative array indices, other bugfixes
- check for negative string lengths - handle negative values for emitInc/emitDec - bugfix for parseInteger with leading minus - fix set literals containing variables as elements
This commit is contained in:
parent
bb602043d2
commit
6d08db2933
2 changed files with 24 additions and 7 deletions
|
|
@ -2456,10 +2456,7 @@ begin
|
|||
begin
|
||||
digits := curToken.tokenText;
|
||||
if matchTokenOrNot(MinusToken) then
|
||||
begin
|
||||
readNextToken;
|
||||
digits := digits + curToken.tokenText;
|
||||
end;
|
||||
parseInteger := integerFromString(digits);
|
||||
end;
|
||||
readNextToken;
|
||||
|
|
@ -2812,6 +2809,8 @@ begin
|
|||
|
||||
if checkToken(CommaToken) then
|
||||
begin
|
||||
(* TODO: handle comma syntax for indexing a char
|
||||
from an array of strings *)
|
||||
if elType.baseType <> ArrayType then
|
||||
errorExit2('invalid array subscript for', name)
|
||||
end;
|
||||
|
|
@ -3231,10 +3230,22 @@ begin
|
|||
readNextToken;
|
||||
end;
|
||||
|
||||
(* Handle an array range part. Very similar to parseInteger
|
||||
but additionally handles Boolean, Enum and Char types which
|
||||
can be used for array indices *)
|
||||
procedure getRangePart(var value:integer; var typeReturn: TypeSpec);
|
||||
var cnst: ConstRef;
|
||||
negate:boolean;
|
||||
digits: string[12];
|
||||
begin
|
||||
setBaseType(typeReturn, NoType);
|
||||
negate := false;
|
||||
|
||||
if checkToken(MinusToken) then
|
||||
begin
|
||||
negate := true;
|
||||
readNextToken;
|
||||
end;
|
||||
|
||||
if checkToken(IdentToken) then
|
||||
begin
|
||||
|
|
@ -3268,7 +3279,11 @@ begin
|
|||
else
|
||||
begin
|
||||
setBaseType(typeReturn, IntegerType);
|
||||
value := parseInteger;
|
||||
digits := curToken.tokenText;
|
||||
if negate then
|
||||
insert('-', digits, 1);
|
||||
value := integerFromString(digits);
|
||||
readNextToken;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
@ -3433,9 +3448,9 @@ begin
|
|||
if savedType.baseType = NoType then
|
||||
savedType := elementType;
|
||||
emitLoadConstantInt(cnst^.intValue);
|
||||
readNextToken;
|
||||
end;
|
||||
emitAddToSet;
|
||||
readNextToken;
|
||||
end
|
||||
else if checkToken(NumberToken) then
|
||||
begin
|
||||
|
|
@ -3999,6 +4014,8 @@ begin
|
|||
begin
|
||||
readNextToken;
|
||||
length := parseInteger;
|
||||
if length < 1 then
|
||||
errorExit2('invalid string length', '');
|
||||
matchToken(RBracketToken);
|
||||
end;
|
||||
typSpec.size := getStringMemSize(length);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue