diff --git a/applications/idlparser/idlgenpascal.pas b/applications/idlparser/idlgenpascal.pas index f88f07960..7694da173 100644 --- a/applications/idlparser/idlgenpascal.pas +++ b/applications/idlparser/idlgenpascal.pas @@ -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; diff --git a/applications/idlparser/idlparser.pas b/applications/idlparser/idlparser.pas index e3288c002..ab2ee3ef8 100644 --- a/applications/idlparser/idlparser.pas +++ b/applications/idlparser/idlparser.pas @@ -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: