codetools: implemented parsing unsigned shhort

git-svn-id: trunk@14383 -
This commit is contained in:
mattias 2008-03-03 11:35:08 +00:00
parent 97a2a2f9e8
commit b82d0ebf3f

View File

@ -159,6 +159,8 @@ type
function AtomIsIdentifier: boolean;
function AtomIsStringConstant: boolean;
function GetAtom: string;
function LastAtomIs(const s: shortstring): boolean;
function GetLastAtom: string;
procedure Replace(FromPos, ToPos: integer; const NewSrc: string);
@ -549,6 +551,7 @@ procedure TCCodeParserTool.ReadVariable;
var
IsFunction: Boolean;
NeedEnd: Boolean;
LastIsName: Boolean;
begin
DebugLn(['TCCodeParserTool.ReadVariable ']);
CreateChildNode(ccnVariable);
@ -573,27 +576,26 @@ begin
end;
CreateChildNode(ccnVariableName);
// possible:
// prefixes: signed, unsigned
// prefixes and/or names long, short
// int, short int, short signed int
// char, signed char, unsigned char
// singed short, unsigned short, short
// long, long long, signed long, signed long long, unsigned long, unsigned long long
LastIsName:=false;
repeat
if AtomIs('short') then
ReadNextAtom
else if AtomIs('signed') then
ReadNextAtom
else if AtomIs('unsigned') then
ReadNextAtom
else if AtomIs('long') then begin
// check if 'long long'
if AtomIs('signed') or AtomIs('unsigned') then begin
LastIsName:=false;
ReadNextAtom;
end else if AtomIs('short') or AtomIs('long') then begin
LastIsName:=true;
ReadNextAtom;
if not (AtomIs('long') or AtomIs('unsigned')) then begin
UndoReadNextAtom;
break;
end;
end else
break;
until false;
until false;
if LastIsName then
UndoReadNextAtom;
// read name
ReadNextAtom;
@ -872,7 +874,7 @@ end;
procedure TCCodeParserTool.ReadNextAtom;
begin
DebugLn(['TCCodeParserTool.ReadNextAtom START ',AtomStart,'-',SrcPos,' ',Src[SrcPos]]);
//DebugLn(['TCCodeParserTool.ReadNextAtom START ',AtomStart,'-',SrcPos,' ',Src[SrcPos]]);
LastSrcPos:=SrcPos;
LastAtomStart:=AtomStart;
repeat
@ -991,6 +993,25 @@ begin
Result:=(AtomStart<SrcLen) and (Src[AtomStart]='"');
end;
function TCCodeParserTool.LastAtomIs(const s: shortstring): boolean;
var
len: Integer;
i: Integer;
begin
if LastAtomStart<=LastSrcPos then exit(false);
len:=length(s);
if (len<>LastSrcPos-LastAtomStart) then exit(false);
if LastSrcPos>SrcLen then exit(false);
for i:=1 to len do
if Src[LastAtomStart+i-1]<>s[i] then exit(false);
Result:=true;
end;
function TCCodeParserTool.GetLastAtom: string;
begin
Result:=copy(Src,LastAtomStart,LastSrcPos-LastAtomStart);
end;
function TCCodeParserTool.GetAtom: string;
begin
Result:=copy(Src,AtomStart,SrcPos-AtomStart);