* 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:
skalogryz 2008-04-16 14:33:21 +00:00
parent aae8d060c4
commit 0d6ffd6e22
3 changed files with 114 additions and 75 deletions

View File

@ -150,7 +150,9 @@ type
protected
function DoParse(AParser: TTextParser): Boolean; override;
public
_Name : AnsiString;
_Name : AnsiString;
_IsArray : Boolean;
_ArraySize : AnsiSTring;
_BitSize : Integer;
_Type : TEntity;
_TypeName : AnsiString;
@ -181,7 +183,7 @@ type
{ TTypeDef }
//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}
TTypeDef = class(TEntity)
@ -205,7 +207,7 @@ type
_Type : TEntity;
_TypeName : AnsiString;
end;
{ TObjCParameterDef }
TObjCResultTypeDef = class(TTypeDef)
@ -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 ParseTypeDef(Owner: TEntity; AParser: TTextParser): TEntity;
function ParseCVarDef(AParser: TTextParser; var Name: AnsiString; isArray: Boolean; var ArraySize:AnsiString): Boolean;
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 IsTypePointer(AType: TEntity; DefResult: Boolean ): Boolean;
function ErrExpectStr(const Expected, Found: AnsiString): AnsiString;
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;
begin
Result := DefResult;
@ -832,7 +866,7 @@ begin
// parsing methods
if s[1] ='#' then SkipLine(AParser.buf, AParser.Index);
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.Parse(AParser);
Items.Add(mtd);
@ -912,7 +946,7 @@ begin
AParser.SetError( ErrExpectStr(' + or -, method descriptor ', s));
Exit;
end;
_CallChar := s[1];
_IsClassMethod := _CallChar = '+';
@ -926,11 +960,21 @@ begin
Exit;
end;
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
AParser.SetError(ErrExpectStr('method name Identifier', s));
Exit;
end;
if _Name = 'defaultCStringEncoding' then
_Name := 'defaultCStringEncoding';
while AParser.FindNextToken(s, tt) do begin
if s = ';' then
@ -1330,11 +1374,13 @@ begin
if not Assigned(prev) then begin
if not st.Parse(AParser) then Exit;
end else begin
AParser.FindNextToken(st._Name, tt);
if tt <> tt_Ident then begin
Result := ParseCVarDef(APArser, st._Name, st._IsArray, st._ArraySize );
if not Result then
Exit;
{if tt <> tt_Ident then begin
AParser.SetError(ErrExpectStr('field name', st._Name));
Exit;
end;
end;}
st._TypeName := prev._TypeName;
end;
@ -1346,10 +1392,11 @@ begin
if s = ';' then begin
AParser.FindNextToken(s, tt);
if s <> '}' then AParser.Index := AParser.TokenPos;
end else begin
if s <> '}' then
AParser.Index := AParser.TokenPos;
end;{ else begin
AParser.Index := AParser.TokenPos;
end;
end;}
end;
Result := true;
@ -1371,18 +1418,20 @@ function TStructField.DoParse(AParser: TTextParser): Boolean;
var
tt : TTokenType;
s : AnsiString;
fld : TStructField;
begin
Result := false;
_Type := ParseTypeDef(Self, AParser);
if not Assigned(_Type) then Exit;
_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));
Exit;
end;
_Name := s;
end;}
Result := ParseCVarDef(AParser, _Name, _IsArray, _ArraySize );
if not Result then Exit;
AParser.FindNextToken(s, tt);
if (tt = tt_Symbol) and (s = ':') then begin
@ -1392,7 +1441,6 @@ begin
Exit;
end;
CVal(s, _BitSize);
AParser.FindNextToken(s, tt);
end else
AParser.Index := AParser.TokenPos;
Result := true;
@ -1425,6 +1473,9 @@ begin
end else if (s = 'char') then begin
SpecVal := [td_Char];
SpecMask := [td_Long, td_Short, td_Char];
end else if (s = 'int') then begin
SpecVal := [td_Int];
SpecMask := [td_Int];
end else
Result := false;
end;
@ -1438,7 +1489,8 @@ var
begin
Result := false;
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
if (_Spec * msk <> []) and (s <> 'long') then begin
AParser.SetError( ErrExpectStr('Type identifier', s));
@ -1448,29 +1500,31 @@ begin
if _Name = '' then _Name := s
else _Name := _Name + ' ' + s;
AParser.FindNextToken(s, tt);
end {of while}
else begin
end; {of while}
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;
AParser.FindNextToken(s, tt);
Result := true;
end;
if tt = tt_Ident then begin
Result := true; // type name can be: usigned long!
AParser.Index := AParser.TokenPos;
Exit;
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) );
if Result then begin
if (tt = tt_Symbol) and (s = '*')
then _isPointer := true
else AParser.Index := AParser.TokenPos;
end;
end;

View File

@ -219,7 +219,9 @@ begin
r := ConvertSettings.TypeDefReplace[objcType];
if r <> '' then Result := r;
end;
if isPointer then
if ((objctype = 'char') or (objctype = 'const char')) then
Result := 'PChar'
end;
@ -305,9 +307,9 @@ begin
pth := vs;
{$IFDEF MSWINDOWS}
{$ENDIF}
{$ifdef MSWINDOWS}
{$endif}
while (pth <> '') and (length(pth)>1) do begin
if ConvertSettings.IgnoreIncludes.IndexOf(pth) >= 0 then
@ -316,10 +318,10 @@ begin
end;
Result := ExtractFileName(vs);
Result := Copy(Result, 1, length(Result) - length(ExtractFileExt(vs))) + '.inc';
(*
Result := '';
if s = '' then Exit;
@ -1225,7 +1227,7 @@ begin
for i := 0 to Items.Count - 1 do
if TObject(Items[i]) is TClassDef then begin
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
cl.Items.Add(category.Items[j]);
TEntity(category.Items[j]).owner := cl;
@ -1339,19 +1341,27 @@ begin
// Add('Foundation/NSObject.h');
// Add('Foundation/Foundation.h');
end;
with ConvertSettings do begin
DefineReplace['MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2'] := 'MAC_OS_X_VERSION_10_2';
DefineReplace['MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3'] := 'MAC_OS_X_VERSION_10_3';
DefineReplace['MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4'] := 'MAC_OS_X_VERSION_10_4';
DefineReplace['MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5'] := 'MAC_OS_X_VERSION_10_5';
DefineReplace['__LP64__'] := 'LP64';
TypeDefReplace['uint32_t'] := 'LongWord';
TypeDefReplace['uint8_t'] := 'byte';
TypeDefReplace['NSUInteger'] := 'LongWord';
TypeDefReplace['NSInteger'] := 'Integer';
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');
end;

View File

@ -13,7 +13,7 @@
<IconPath Value="./"/>
<TargetFileExt Value=".exe"/>
<UseAppBundle Value="False"/>
<ActiveEditorIndexAtStart Value="0"/>
<ActiveEditorIndexAtStart Value="2"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
@ -35,7 +35,7 @@
<Filename Value="objcparser.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Project1"/>
<CursorPos X="1" Y="17"/>
<CursorPos X="1" Y="10"/>
<TopLine Value="3"/>
<EditorIndex Value="0"/>
<UsageCount Value="71"/>
@ -44,7 +44,7 @@
<Unit1>
<Filename Value="ObjCParserUtils.pas"/>
<UnitName Value="ObjCParserUtils"/>
<CursorPos X="1" Y="11"/>
<CursorPos X="47" Y="8"/>
<TopLine Value="1"/>
<EditorIndex Value="2"/>
<UsageCount Value="33"/>
@ -53,7 +53,7 @@
<Unit2>
<Filename Value="ObjCParserTypes.pas"/>
<UnitName Value="ObjCParserTypes"/>
<CursorPos X="1" Y="1553"/>
<CursorPos X="1" Y="1539"/>
<TopLine Value="1531"/>
<EditorIndex Value="1"/>
<UsageCount Value="33"/>
@ -249,17 +249,13 @@
<Filename Value="/usr/local/share/fpcsrc/rtl/objpas/sysutils/finah.inc"/>
<CursorPos X="10" Y="28"/>
<TopLine Value="18"/>
<EditorIndex Value="3"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit31>
<Unit32>
<Filename Value="/usr/local/share/fpcsrc/rtl/objpas/sysutils/fina.inc"/>
<CursorPos X="1" Y="41"/>
<TopLine Value="34"/>
<EditorIndex Value="4"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit32>
<Unit33>
<Filename Value="NSAlert.inc"/>
@ -268,28 +264,7 @@
<UsageCount Value="10"/>
</Unit33>
</Units>
<JumpHistory Count="5" HistoryIndex="4">
<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>
<JumpHistory Count="0" HistoryIndex="-1"/>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>