You've already forked lazarus-ccr
* Improved constant parsing: handle constant value as one text block
* Replace << and >> for shl and shr in non-string constants git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2344 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -35,7 +35,8 @@ unit idlGenPascal;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, idlParser;
|
||||
Classes, SysUtils, strutils,
|
||||
idlParser;
|
||||
|
||||
procedure GeneratePascalSource(const AnIdlList: TIDLList; const PascalCode: tstrings;TypeConvList, CTypesList: TStrings; AlwaysAddPrefixToParam: boolean);
|
||||
|
||||
@ -71,10 +72,18 @@ end;
|
||||
|
||||
function CValueToPascalValue(AValue: string) : string;
|
||||
begin
|
||||
AValue := trim(AValue);
|
||||
if copy(AValue,1,2)='0x' then
|
||||
result := '$'+copy(AValue,3,16)
|
||||
else
|
||||
begin
|
||||
if (pos('''',AValue)<0) and (pos('"',AValue)<0) then
|
||||
// the constant does not contain any strings
|
||||
begin
|
||||
AValue := StringsReplace(AValue,['<<','>>'],['shl','shr'],[rfReplaceAll]);
|
||||
end;
|
||||
result := AValue;
|
||||
end
|
||||
end;
|
||||
|
||||
function IdentifierNameToPascalName(AName: string) : string;
|
||||
|
@ -227,17 +227,39 @@ var
|
||||
else if PriorState = psInterfaceBlockFuncName then
|
||||
CurrentIDLMember.MemberName:=AWord
|
||||
else if PriorState = psInterfaceBlockFuncParamName then
|
||||
CurrentIDLMemberParam.ParamName:=AWord
|
||||
else if PriorState = psConstValue then
|
||||
begin
|
||||
if CurrentIDLMember.ConstValue<>'' then CurrentIDLMember.ConstValue := CurrentIDLMember.ConstValue + ' ';
|
||||
CurrentIDLMember.ConstValue:=CurrentIDLMember.ConstValue + AWord;
|
||||
end;
|
||||
CurrentIDLMemberParam.ParamName:=AWord;
|
||||
ParseState := ASetParseState;
|
||||
result := True;
|
||||
end;
|
||||
end;
|
||||
|
||||
function CheckStartConst: boolean;
|
||||
begin
|
||||
result := CheckChar(idlConstAssign,psConstValue);
|
||||
if Result then
|
||||
begin
|
||||
pWordStart:=pCurrent;
|
||||
ParseState := psConstValue;
|
||||
inc(pcurrent);
|
||||
end;
|
||||
end;
|
||||
|
||||
function CheckEndConst: boolean;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
result := CheckChar(idlMemberEnd,psInterfaceBlock);
|
||||
if result then
|
||||
begin
|
||||
i := pCurrent-pWordStart-1;
|
||||
SetLength(AWord,i);
|
||||
move(pWordStart^,AWord[1],i);
|
||||
CurrentIDLMember.ConstValue:=AWord;
|
||||
ParseState := psInterfaceBlock;
|
||||
inc(pcurrent);
|
||||
end;
|
||||
end;
|
||||
|
||||
function CheckInterfaceStart: boolean;
|
||||
begin
|
||||
result := CheckChar(idlInterface, psInterface);
|
||||
@ -428,7 +450,7 @@ begin
|
||||
if not (CheckStartWord(psWord, psInterfaceBlockFuncName) or
|
||||
CheckChar(idlStartFuncParams,psInterfaceBlockFuncParams) or
|
||||
CheckChar(idlMemberEnd,psInterfaceBlock) or
|
||||
CheckChar(idlConstAssign,psConstValue) or
|
||||
CheckStartConst or
|
||||
CheckChar(idlStartMultiLineComment,psMultiLineComment,ParseState)) then
|
||||
inc(pCurrent)
|
||||
end;
|
||||
@ -468,9 +490,9 @@ begin
|
||||
end;
|
||||
psConstValue:
|
||||
begin
|
||||
if not (CheckStartWord(psWord, psConstValue) or
|
||||
CheckChar(idlStartMultiLineComment,psMultiLineComment,ParseState) or
|
||||
CheckChar(idlMemberEnd,psInterfaceBlock)) then
|
||||
if not (CheckChar(idlStartMultiLineComment,psMultiLineComment,ParseState) or
|
||||
CheckChar(idlStartSingleLineComment,psSingleLineComment,ParseState) or
|
||||
CheckEndConst) then
|
||||
inc(pCurrent)
|
||||
end;
|
||||
psWord:
|
||||
|
Reference in New Issue
Block a user