* objc methods parsing fixed (for untyped methods) * struct (unions) parsing fixed
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@425 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
aae8d060c4
commit
0d6ffd6e22
@ -151,6 +151,8 @@ type
|
|||||||
function DoParse(AParser: TTextParser): Boolean; override;
|
function DoParse(AParser: TTextParser): Boolean; override;
|
||||||
public
|
public
|
||||||
_Name : AnsiString;
|
_Name : AnsiString;
|
||||||
|
_IsArray : Boolean;
|
||||||
|
_ArraySize : AnsiSTring;
|
||||||
_BitSize : Integer;
|
_BitSize : Integer;
|
||||||
_Type : TEntity;
|
_Type : TEntity;
|
||||||
_TypeName : AnsiString;
|
_TypeName : AnsiString;
|
||||||
@ -181,7 +183,7 @@ type
|
|||||||
{ TTypeDef }
|
{ TTypeDef }
|
||||||
//C token - any type, including unsigned short
|
//C token - any type, including unsigned short
|
||||||
|
|
||||||
TTypeDefSpecs = set of (td_Unsigned, td_Signed, td_Volitale, td_Const, td_Long, td_Short, td_Char);
|
TTypeDefSpecs = set of (td_Unsigned, td_Signed, td_Volitale, td_Const, td_Long, td_Short, td_Char, td_Int);
|
||||||
|
|
||||||
{updated}
|
{updated}
|
||||||
TTypeDef = class(TEntity)
|
TTypeDef = class(TEntity)
|
||||||
@ -302,6 +304,7 @@ function ScanWhile(const s: AnsiString; var index: Integer; const ch: TCharSet):
|
|||||||
function ScanTo(const s: AnsiString; var index: Integer; const ch: TCharSet): AnsiString;
|
function ScanTo(const s: AnsiString; var index: Integer; const ch: TCharSet): AnsiString;
|
||||||
|
|
||||||
function ParseTypeDef(Owner: TEntity; AParser: TTextParser): TEntity;
|
function ParseTypeDef(Owner: TEntity; AParser: TTextParser): TEntity;
|
||||||
|
function ParseCVarDef(AParser: TTextParser; var Name: AnsiString; isArray: Boolean; var ArraySize:AnsiString): Boolean;
|
||||||
|
|
||||||
procedure FreeEntity(Item: TEntity);
|
procedure FreeEntity(Item: TEntity);
|
||||||
|
|
||||||
@ -309,9 +312,40 @@ procedure ParseCNumeric(const S: AnsiString; var idx: integer; var NumStr: AnsiS
|
|||||||
function CToPascalNumeric(const Cnum: AnsiString): AnsiString;
|
function CToPascalNumeric(const Cnum: AnsiString): AnsiString;
|
||||||
|
|
||||||
function IsTypePointer(AType: TEntity; DefResult: Boolean ): Boolean;
|
function IsTypePointer(AType: TEntity; DefResult: Boolean ): Boolean;
|
||||||
|
function ErrExpectStr(const Expected, Found: AnsiString): AnsiString;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
function ParseCVarDef(AParser: TTextParser; var Name: AnsiString; isArray: Boolean; var ArraySize:AnsiString): Boolean;
|
||||||
|
var
|
||||||
|
tt : TTokenType;
|
||||||
|
s : AnsiString;
|
||||||
|
begin
|
||||||
|
Result := AParser.FindNextToken(Name, tt);
|
||||||
|
if Result then Result := tt = tt_Ident;
|
||||||
|
if not Result then begin
|
||||||
|
AParser.SetError(ErrExpectStr('Identifier', Name) );
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
Result := true;
|
||||||
|
|
||||||
|
AParser.FindNextToken(s, tt);
|
||||||
|
if not ((tt = tt_Symbol) and (s = '[')) then begin
|
||||||
|
AParser.Index := AParser.TokenPos;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
isArray := true;
|
||||||
|
ParseCExpression(APArser, ArraySize);
|
||||||
|
AParser.FindNextToken(s, tt);
|
||||||
|
if s <> ']' then begin
|
||||||
|
Result := false;
|
||||||
|
AParser.SetError( ErrExpectStr('[', ArraySize));
|
||||||
|
AParser.Index := AParser.TokenPos;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
function IsTypePointer(AType: TEntity; DefResult: Boolean ): Boolean;
|
function IsTypePointer(AType: TEntity; DefResult: Boolean ): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := DefResult;
|
Result := DefResult;
|
||||||
@ -832,7 +866,7 @@ begin
|
|||||||
// parsing methods
|
// parsing methods
|
||||||
if s[1] ='#' then SkipLine(AParser.buf, AParser.Index);
|
if s[1] ='#' then SkipLine(AParser.buf, AParser.Index);
|
||||||
if (s = '+') or (s = '-') then begin
|
if (s = '+') or (s = '-') then begin
|
||||||
dec(AParser.Index ); // roll back a single character
|
AParser.Index := AParser.TokenPos; // roll back to the start of method
|
||||||
mtd := TClassMethodDef.Create(Self);
|
mtd := TClassMethodDef.Create(Self);
|
||||||
mtd.Parse(AParser);
|
mtd.Parse(AParser);
|
||||||
Items.Add(mtd);
|
Items.Add(mtd);
|
||||||
@ -926,11 +960,21 @@ begin
|
|||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
Items.Add(res);
|
Items.Add(res);
|
||||||
end;
|
end else if (tt = tt_Ident) then begin
|
||||||
|
// if type is not defined, that it's assumed to be obj-c 'id'
|
||||||
|
res := TObjCResultTypeDef.Create(Self);
|
||||||
|
res._Name := 'id';
|
||||||
|
Items.Add(res);
|
||||||
|
AParser.Index := AParser.TokenPos;
|
||||||
|
end else
|
||||||
|
APArser.SetError(ErrExpectStr('(', s));
|
||||||
|
|
||||||
if not AParser.FindNextToken(_Name, tt) then begin
|
if not AParser.FindNextToken(_Name, tt) then begin
|
||||||
AParser.SetError(ErrExpectStr('method name Identifier', s));
|
AParser.SetError(ErrExpectStr('method name Identifier', s));
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
if _Name = 'defaultCStringEncoding' then
|
||||||
|
_Name := 'defaultCStringEncoding';
|
||||||
|
|
||||||
while AParser.FindNextToken(s, tt) do begin
|
while AParser.FindNextToken(s, tt) do begin
|
||||||
if s = ';' then
|
if s = ';' then
|
||||||
@ -1330,11 +1374,13 @@ begin
|
|||||||
if not Assigned(prev) then begin
|
if not Assigned(prev) then begin
|
||||||
if not st.Parse(AParser) then Exit;
|
if not st.Parse(AParser) then Exit;
|
||||||
end else begin
|
end else begin
|
||||||
AParser.FindNextToken(st._Name, tt);
|
Result := ParseCVarDef(APArser, st._Name, st._IsArray, st._ArraySize );
|
||||||
if tt <> tt_Ident then begin
|
if not Result then
|
||||||
|
Exit;
|
||||||
|
{if tt <> tt_Ident then begin
|
||||||
AParser.SetError(ErrExpectStr('field name', st._Name));
|
AParser.SetError(ErrExpectStr('field name', st._Name));
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;}
|
||||||
st._TypeName := prev._TypeName;
|
st._TypeName := prev._TypeName;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1346,10 +1392,11 @@ begin
|
|||||||
|
|
||||||
if s = ';' then begin
|
if s = ';' then begin
|
||||||
AParser.FindNextToken(s, tt);
|
AParser.FindNextToken(s, tt);
|
||||||
if s <> '}' then AParser.Index := AParser.TokenPos;
|
if s <> '}' then
|
||||||
end else begin
|
|
||||||
AParser.Index := AParser.TokenPos;
|
AParser.Index := AParser.TokenPos;
|
||||||
end;
|
end;{ else begin
|
||||||
|
AParser.Index := AParser.TokenPos;
|
||||||
|
end;}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result := true;
|
Result := true;
|
||||||
@ -1371,6 +1418,7 @@ function TStructField.DoParse(AParser: TTextParser): Boolean;
|
|||||||
var
|
var
|
||||||
tt : TTokenType;
|
tt : TTokenType;
|
||||||
s : AnsiString;
|
s : AnsiString;
|
||||||
|
fld : TStructField;
|
||||||
begin
|
begin
|
||||||
Result := false;
|
Result := false;
|
||||||
_Type := ParseTypeDef(Self, AParser);
|
_Type := ParseTypeDef(Self, AParser);
|
||||||
@ -1378,11 +1426,12 @@ begin
|
|||||||
|
|
||||||
_TypeName := GetTypeNameFromEntity(_Type);
|
_TypeName := GetTypeNameFromEntity(_Type);
|
||||||
|
|
||||||
if not (AParser.FindNextToken(s, tt)) or (tt <> tt_Ident) then begin
|
{if not (AParser.FindNextToken(s, tt)) or (tt <> tt_Ident) then begin
|
||||||
AParser.SetError(ErrExpectStr('Identifier', s));
|
AParser.SetError(ErrExpectStr('Identifier', s));
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;}
|
||||||
_Name := s;
|
Result := ParseCVarDef(AParser, _Name, _IsArray, _ArraySize );
|
||||||
|
if not Result then Exit;
|
||||||
|
|
||||||
AParser.FindNextToken(s, tt);
|
AParser.FindNextToken(s, tt);
|
||||||
if (tt = tt_Symbol) and (s = ':') then begin
|
if (tt = tt_Symbol) and (s = ':') then begin
|
||||||
@ -1392,7 +1441,6 @@ begin
|
|||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
CVal(s, _BitSize);
|
CVal(s, _BitSize);
|
||||||
AParser.FindNextToken(s, tt);
|
|
||||||
end else
|
end else
|
||||||
AParser.Index := AParser.TokenPos;
|
AParser.Index := AParser.TokenPos;
|
||||||
Result := true;
|
Result := true;
|
||||||
@ -1425,6 +1473,9 @@ begin
|
|||||||
end else if (s = 'char') then begin
|
end else if (s = 'char') then begin
|
||||||
SpecVal := [td_Char];
|
SpecVal := [td_Char];
|
||||||
SpecMask := [td_Long, td_Short, td_Char];
|
SpecMask := [td_Long, td_Short, td_Char];
|
||||||
|
end else if (s = 'int') then begin
|
||||||
|
SpecVal := [td_Int];
|
||||||
|
SpecMask := [td_Int];
|
||||||
end else
|
end else
|
||||||
Result := false;
|
Result := false;
|
||||||
end;
|
end;
|
||||||
@ -1438,7 +1489,8 @@ var
|
|||||||
begin
|
begin
|
||||||
Result := false;
|
Result := false;
|
||||||
AParser.FindNextToken(s, tt);
|
AParser.FindNextToken(s, tt);
|
||||||
if (tt = tt_Ident) and (IsSpecifier(s, vl, msk)) then
|
if (tt = tt_Ident) and (IsSpecifier(s, vl, msk)) then begin
|
||||||
|
// search all specifiers
|
||||||
while (tt = tt_Ident) and (IsSpecifier(s, vl, msk)) do begin
|
while (tt = tt_Ident) and (IsSpecifier(s, vl, msk)) do begin
|
||||||
if (_Spec * msk <> []) and (s <> 'long') then begin
|
if (_Spec * msk <> []) and (s <> 'long') then begin
|
||||||
AParser.SetError( ErrExpectStr('Type identifier', s));
|
AParser.SetError( ErrExpectStr('Type identifier', s));
|
||||||
@ -1448,29 +1500,31 @@ begin
|
|||||||
if _Name = '' then _Name := s
|
if _Name = '' then _Name := s
|
||||||
else _Name := _Name + ' ' + s;
|
else _Name := _Name + ' ' + s;
|
||||||
AParser.FindNextToken(s, tt);
|
AParser.FindNextToken(s, tt);
|
||||||
end {of while}
|
end; {of while}
|
||||||
else begin
|
|
||||||
|
if ((_Spec * [td_Int, td_Short, td_Char, td_Long]) = []) then begin
|
||||||
|
// if int, short long or char is not specified
|
||||||
|
// volatile or const are
|
||||||
|
Result := tt = tt_Ident;
|
||||||
|
if not Result then begin
|
||||||
|
AParser.SetError(ErrExpectStr('Identifier', s));
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
_Name := s;
|
||||||
|
AParser.FindNextToken(s, tt);
|
||||||
|
end else
|
||||||
|
Result := true;
|
||||||
|
|
||||||
|
end else begin
|
||||||
_Name := s;
|
_Name := s;
|
||||||
AParser.FindNextToken(s, tt);
|
AParser.FindNextToken(s, tt);
|
||||||
Result := true;
|
Result := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if tt = tt_Ident then begin
|
if Result then begin
|
||||||
Result := true; // type name can be: usigned long!
|
if (tt = tt_Symbol) and (s = '*')
|
||||||
AParser.Index := AParser.TokenPos;
|
then _isPointer := true
|
||||||
Exit;
|
else AParser.Index := AParser.TokenPos;
|
||||||
end else if tt = tt_Symbol then begin
|
|
||||||
if (s = '*') then
|
|
||||||
_isPointer := true
|
|
||||||
else if (s <> ';') or (s <>',') then begin
|
|
||||||
AParser.Index := AParser.TokenPos;
|
|
||||||
AParser.SetError( ErrExpectStr('identifier', 'symbol ' + s ));
|
|
||||||
Exit;
|
|
||||||
end else
|
|
||||||
AParser.Index := AParser.TokenPos;
|
|
||||||
Result := true;
|
|
||||||
end else begin
|
|
||||||
AParser.SetError(ErrExpectStr( 'Identifier', s) );
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
@ -219,7 +219,9 @@ begin
|
|||||||
r := ConvertSettings.TypeDefReplace[objcType];
|
r := ConvertSettings.TypeDefReplace[objcType];
|
||||||
if r <> '' then Result := r;
|
if r <> '' then Result := r;
|
||||||
end;
|
end;
|
||||||
|
if isPointer then
|
||||||
|
if ((objctype = 'char') or (objctype = 'const char')) then
|
||||||
|
Result := 'PChar'
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -305,9 +307,9 @@ begin
|
|||||||
|
|
||||||
pth := vs;
|
pth := vs;
|
||||||
|
|
||||||
{$IFDEF MSWINDOWS}
|
{$ifdef MSWINDOWS}
|
||||||
|
|
||||||
{$ENDIF}
|
{$endif}
|
||||||
|
|
||||||
while (pth <> '') and (length(pth)>1) do begin
|
while (pth <> '') and (length(pth)>1) do begin
|
||||||
if ConvertSettings.IgnoreIncludes.IndexOf(pth) >= 0 then
|
if ConvertSettings.IgnoreIncludes.IndexOf(pth) >= 0 then
|
||||||
@ -1225,7 +1227,7 @@ begin
|
|||||||
for i := 0 to Items.Count - 1 do
|
for i := 0 to Items.Count - 1 do
|
||||||
if TObject(Items[i]) is TClassDef then begin
|
if TObject(Items[i]) is TClassDef then begin
|
||||||
cl := TClassDef(Items[i]);
|
cl := TClassDef(Items[i]);
|
||||||
if (cl._SuperClass <> '') and (cl._Category <> '') then
|
if (cl._ClassName = category._ClassName) and (cl._Category = '') then
|
||||||
for j := 0 to category.Items.Count - 1 do begin
|
for j := 0 to category.Items.Count - 1 do begin
|
||||||
cl.Items.Add(category.Items[j]);
|
cl.Items.Add(category.Items[j]);
|
||||||
TEntity(category.Items[j]).owner := cl;
|
TEntity(category.Items[j]).owner := cl;
|
||||||
@ -1352,6 +1354,14 @@ begin
|
|||||||
TypeDefReplace['NSUInteger'] := 'LongWord';
|
TypeDefReplace['NSUInteger'] := 'LongWord';
|
||||||
TypeDefReplace['NSInteger'] := 'Integer';
|
TypeDefReplace['NSInteger'] := 'Integer';
|
||||||
TypeDefReplace['long long'] := 'Int64';
|
TypeDefReplace['long long'] := 'Int64';
|
||||||
|
TypeDefReplace['short'] := 'SmallInt';
|
||||||
|
TypeDefReplace['short int'] := 'SmallInt';
|
||||||
|
TypeDefReplace['unsigned short'] := 'Word';
|
||||||
|
TypeDefReplace['unsigned int'] := 'LongWord';
|
||||||
|
TypeDefReplace['int'] := 'Integer';
|
||||||
|
TypeDefReplace['unsigned long long'] := 'Int64';
|
||||||
|
TypeDefReplace['CGFloat'] := 'Single';
|
||||||
|
TypeDefReplace['short'] := 'smallInt';
|
||||||
|
|
||||||
IgnoreTokens.Add('DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER');
|
IgnoreTokens.Add('DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER');
|
||||||
end;
|
end;
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<IconPath Value="./"/>
|
<IconPath Value="./"/>
|
||||||
<TargetFileExt Value=".exe"/>
|
<TargetFileExt Value=".exe"/>
|
||||||
<UseAppBundle Value="False"/>
|
<UseAppBundle Value="False"/>
|
||||||
<ActiveEditorIndexAtStart Value="0"/>
|
<ActiveEditorIndexAtStart Value="2"/>
|
||||||
</General>
|
</General>
|
||||||
<VersionInfo>
|
<VersionInfo>
|
||||||
<ProjectVersion Value=""/>
|
<ProjectVersion Value=""/>
|
||||||
@ -35,7 +35,7 @@
|
|||||||
<Filename Value="objcparser.pas"/>
|
<Filename Value="objcparser.pas"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<UnitName Value="Project1"/>
|
<UnitName Value="Project1"/>
|
||||||
<CursorPos X="1" Y="17"/>
|
<CursorPos X="1" Y="10"/>
|
||||||
<TopLine Value="3"/>
|
<TopLine Value="3"/>
|
||||||
<EditorIndex Value="0"/>
|
<EditorIndex Value="0"/>
|
||||||
<UsageCount Value="71"/>
|
<UsageCount Value="71"/>
|
||||||
@ -44,7 +44,7 @@
|
|||||||
<Unit1>
|
<Unit1>
|
||||||
<Filename Value="ObjCParserUtils.pas"/>
|
<Filename Value="ObjCParserUtils.pas"/>
|
||||||
<UnitName Value="ObjCParserUtils"/>
|
<UnitName Value="ObjCParserUtils"/>
|
||||||
<CursorPos X="1" Y="11"/>
|
<CursorPos X="47" Y="8"/>
|
||||||
<TopLine Value="1"/>
|
<TopLine Value="1"/>
|
||||||
<EditorIndex Value="2"/>
|
<EditorIndex Value="2"/>
|
||||||
<UsageCount Value="33"/>
|
<UsageCount Value="33"/>
|
||||||
@ -53,7 +53,7 @@
|
|||||||
<Unit2>
|
<Unit2>
|
||||||
<Filename Value="ObjCParserTypes.pas"/>
|
<Filename Value="ObjCParserTypes.pas"/>
|
||||||
<UnitName Value="ObjCParserTypes"/>
|
<UnitName Value="ObjCParserTypes"/>
|
||||||
<CursorPos X="1" Y="1553"/>
|
<CursorPos X="1" Y="1539"/>
|
||||||
<TopLine Value="1531"/>
|
<TopLine Value="1531"/>
|
||||||
<EditorIndex Value="1"/>
|
<EditorIndex Value="1"/>
|
||||||
<UsageCount Value="33"/>
|
<UsageCount Value="33"/>
|
||||||
@ -249,17 +249,13 @@
|
|||||||
<Filename Value="/usr/local/share/fpcsrc/rtl/objpas/sysutils/finah.inc"/>
|
<Filename Value="/usr/local/share/fpcsrc/rtl/objpas/sysutils/finah.inc"/>
|
||||||
<CursorPos X="10" Y="28"/>
|
<CursorPos X="10" Y="28"/>
|
||||||
<TopLine Value="18"/>
|
<TopLine Value="18"/>
|
||||||
<EditorIndex Value="3"/>
|
|
||||||
<UsageCount Value="10"/>
|
<UsageCount Value="10"/>
|
||||||
<Loaded Value="True"/>
|
|
||||||
</Unit31>
|
</Unit31>
|
||||||
<Unit32>
|
<Unit32>
|
||||||
<Filename Value="/usr/local/share/fpcsrc/rtl/objpas/sysutils/fina.inc"/>
|
<Filename Value="/usr/local/share/fpcsrc/rtl/objpas/sysutils/fina.inc"/>
|
||||||
<CursorPos X="1" Y="41"/>
|
<CursorPos X="1" Y="41"/>
|
||||||
<TopLine Value="34"/>
|
<TopLine Value="34"/>
|
||||||
<EditorIndex Value="4"/>
|
|
||||||
<UsageCount Value="10"/>
|
<UsageCount Value="10"/>
|
||||||
<Loaded Value="True"/>
|
|
||||||
</Unit32>
|
</Unit32>
|
||||||
<Unit33>
|
<Unit33>
|
||||||
<Filename Value="NSAlert.inc"/>
|
<Filename Value="NSAlert.inc"/>
|
||||||
@ -268,28 +264,7 @@
|
|||||||
<UsageCount Value="10"/>
|
<UsageCount Value="10"/>
|
||||||
</Unit33>
|
</Unit33>
|
||||||
</Units>
|
</Units>
|
||||||
<JumpHistory Count="5" HistoryIndex="4">
|
<JumpHistory Count="0" HistoryIndex="-1"/>
|
||||||
<Position1>
|
|
||||||
<Filename Value="ObjCParserTypes.pas"/>
|
|
||||||
<Caret Line="1439" Column="25" TopLine="1415"/>
|
|
||||||
</Position1>
|
|
||||||
<Position2>
|
|
||||||
<Filename Value="ObjCParserTypes.pas"/>
|
|
||||||
<Caret Line="11" Column="1" TopLine="1"/>
|
|
||||||
</Position2>
|
|
||||||
<Position3>
|
|
||||||
<Filename Value="objcparser.pas"/>
|
|
||||||
<Caret Line="18" Column="9" TopLine="1"/>
|
|
||||||
</Position3>
|
|
||||||
<Position4>
|
|
||||||
<Filename Value="objcparser.pas"/>
|
|
||||||
<Caret Line="278" Column="1" TopLine="257"/>
|
|
||||||
</Position4>
|
|
||||||
<Position5>
|
|
||||||
<Filename Value="ObjCParserUtils.pas"/>
|
|
||||||
<Caret Line="1218" Column="19" TopLine="1210"/>
|
|
||||||
</Position5>
|
|
||||||
</JumpHistory>
|
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="5"/>
|
<Version Value="5"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user