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
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, idlParser;
|
Classes, SysUtils, strutils,
|
||||||
|
idlParser;
|
||||||
|
|
||||||
procedure GeneratePascalSource(const AnIdlList: TIDLList; const PascalCode: tstrings;TypeConvList, CTypesList: TStrings; AlwaysAddPrefixToParam: boolean);
|
procedure GeneratePascalSource(const AnIdlList: TIDLList; const PascalCode: tstrings;TypeConvList, CTypesList: TStrings; AlwaysAddPrefixToParam: boolean);
|
||||||
|
|
||||||
@@ -71,10 +72,18 @@ end;
|
|||||||
|
|
||||||
function CValueToPascalValue(AValue: string) : string;
|
function CValueToPascalValue(AValue: string) : string;
|
||||||
begin
|
begin
|
||||||
|
AValue := trim(AValue);
|
||||||
if copy(AValue,1,2)='0x' then
|
if copy(AValue,1,2)='0x' then
|
||||||
result := '$'+copy(AValue,3,16)
|
result := '$'+copy(AValue,3,16)
|
||||||
else
|
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;
|
result := AValue;
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function IdentifierNameToPascalName(AName: string) : string;
|
function IdentifierNameToPascalName(AName: string) : string;
|
||||||
|
@@ -227,17 +227,39 @@ var
|
|||||||
else if PriorState = psInterfaceBlockFuncName then
|
else if PriorState = psInterfaceBlockFuncName then
|
||||||
CurrentIDLMember.MemberName:=AWord
|
CurrentIDLMember.MemberName:=AWord
|
||||||
else if PriorState = psInterfaceBlockFuncParamName then
|
else if PriorState = psInterfaceBlockFuncParamName then
|
||||||
CurrentIDLMemberParam.ParamName:=AWord
|
CurrentIDLMemberParam.ParamName:=AWord;
|
||||||
else if PriorState = psConstValue then
|
|
||||||
begin
|
|
||||||
if CurrentIDLMember.ConstValue<>'' then CurrentIDLMember.ConstValue := CurrentIDLMember.ConstValue + ' ';
|
|
||||||
CurrentIDLMember.ConstValue:=CurrentIDLMember.ConstValue + AWord;
|
|
||||||
end;
|
|
||||||
ParseState := ASetParseState;
|
ParseState := ASetParseState;
|
||||||
result := True;
|
result := True;
|
||||||
end;
|
end;
|
||||||
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;
|
function CheckInterfaceStart: boolean;
|
||||||
begin
|
begin
|
||||||
result := CheckChar(idlInterface, psInterface);
|
result := CheckChar(idlInterface, psInterface);
|
||||||
@@ -428,7 +450,7 @@ begin
|
|||||||
if not (CheckStartWord(psWord, psInterfaceBlockFuncName) or
|
if not (CheckStartWord(psWord, psInterfaceBlockFuncName) or
|
||||||
CheckChar(idlStartFuncParams,psInterfaceBlockFuncParams) or
|
CheckChar(idlStartFuncParams,psInterfaceBlockFuncParams) or
|
||||||
CheckChar(idlMemberEnd,psInterfaceBlock) or
|
CheckChar(idlMemberEnd,psInterfaceBlock) or
|
||||||
CheckChar(idlConstAssign,psConstValue) or
|
CheckStartConst or
|
||||||
CheckChar(idlStartMultiLineComment,psMultiLineComment,ParseState)) then
|
CheckChar(idlStartMultiLineComment,psMultiLineComment,ParseState)) then
|
||||||
inc(pCurrent)
|
inc(pCurrent)
|
||||||
end;
|
end;
|
||||||
@@ -468,9 +490,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
psConstValue:
|
psConstValue:
|
||||||
begin
|
begin
|
||||||
if not (CheckStartWord(psWord, psConstValue) or
|
if not (CheckChar(idlStartMultiLineComment,psMultiLineComment,ParseState) or
|
||||||
CheckChar(idlStartMultiLineComment,psMultiLineComment,ParseState) or
|
CheckChar(idlStartSingleLineComment,psSingleLineComment,ParseState) or
|
||||||
CheckChar(idlMemberEnd,psInterfaceBlock)) then
|
CheckEndConst) then
|
||||||
inc(pCurrent)
|
inc(pCurrent)
|
||||||
end;
|
end;
|
||||||
psWord:
|
psWord:
|
||||||
|
Reference in New Issue
Block a user