fixed config file usage, that prevented from using more than one config file; fixed result types not converted to objc.id, fixed file including

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@445 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
skalogryz 2008-04-29 14:10:17 +00:00
parent dda68f13a0
commit ece0e03c29
5 changed files with 629 additions and 372 deletions

View File

@ -82,6 +82,7 @@ type
public
owner : TEntity;
Items : TList;
TagComment : AnsiString;
constructor Create(AOwner: TEntity);
destructor Destroy; override;
function Parse(AParser: TTextParser): Boolean; virtual;
@ -238,11 +239,12 @@ type
{ TObjCParameterDef }
TObjCResultTypeDef = class(TTypeDef)
TObjCResultTypeDef = class(TEntity)
{updating}
protected
function DoParse(AParser: TTextParser): Boolean; override;
public
_Type : TEntity;
_isRef : Boolean;
_isConst : Boolean; // (const Sometype)
_Prefix : AnsiString; // reserved-word type descriptors
@ -253,7 +255,7 @@ type
protected
function DoParse(AParser: TTextParser): Boolean; override;
public
_Res : TObjCResultTypeDef;
_Type : TObjCResultTypeDef;
_Name : AnsiString;
end;
@ -1100,7 +1102,9 @@ begin
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';
res._Type := TTypeDef.Create(res);
TTypeDef(res._Type)._Name := 'id';
Items.Add(res);
AParser.Index := AParser.TokenPos;
end else
@ -1141,10 +1145,10 @@ var
tt : TTokenType;
begin
Result := false;
_Res := TObjCResultTypeDef.Create(Self);
if not _Res.Parse(AParser) then Exit;
_Type := TObjCResultTypeDef.Create(Self);
if not _Type.Parse(AParser) then Exit;
Items.Add(_Res);
Items.Add(_Type);
AParser.FindNextToken(_Name, tt);
if tt <> tt_Ident then begin
AParser.SetError(ErrExpectStr('Identifier', _Name));
@ -1153,12 +1157,33 @@ begin
Result := true;
end;
function isParamFuncPointer(AParser: TTextParser): Boolean;
var
i : Integer;
s : AnsiString;
tt : TTokenType;
begin
i := AParser.Index;
AParser.FindNextToken(s, tt);
Result := (tt = tt_Symbol) and (s = '(');
if not Result then Exit;
AParser.FindNextToken(s, tt);
Result := (tt = tt_Symbol) and (s = '*');
if not Result then Exit;
AParser.FindNextToken(s, tt);
Result := (tt = tt_Symbol) and (s = ')');
if not Result then Exit;
end;
{ TResultTypeDef }
function TObjCResultTypeDef.DoParse(AParser: TTextParser): Boolean;
var
s : AnsiString;
tt : TTokenType;
fnt : TFunctionTypeDef;
begin
Result := false;
AParser.FindNextToken(s, tt);
@ -1166,7 +1191,10 @@ begin
AParser.SetError(ErrExpectStr('"("', s));
Exit;
end;
Result := inherited DoParse(AParser);
_Type := TTypeDef.Create(Self);
Result := _Type.Parse(AParser);
if not Result then Exit;
if Result then begin
AParser.FindNextToken(s, tt);
@ -1175,8 +1203,23 @@ begin
AParser.FindNextToken(s, tt);
end;
if s = '(' then begin // ptr funciton (*)?
AParser.Index := AParser.TokenPos;
if not isParamFuncPointer(APArser) then begin
AParser.SetError(ErrExpectStr(')', s));
Result := false;
Exit;
end;
fnt := TFunctionTypeDef.Create(Self);
fnt._ResultType := _Type;
Result := fnt.Parse(AParser);
_Type := fnt;
if not Result then Exit;
AParser.FindNextToken(s, tt);
end;
Result := s = ')';
if not Result then
AParser.SetError( ErrExpectStr(')', s));
end;
@ -1642,8 +1685,10 @@ begin
Exit;
end;
_Spec := _Spec + vl;
if _Name = '' then _Name := s
else _Name := _Name + ' ' + s;
if (s <> 'const') and (s <> 'volatile') then begin
if _Name = '' then _Name := s
else _Name := _Name + ' ' + s;
end;
AParser.FindNextToken(s, tt);
end; {of while}

View File

@ -47,17 +47,21 @@ type
DefineReplace : TReplaceList;
TypeDefReplace : TReplaceList; // replaces for C types
PtrTypeReplace : TReplaceList; // replaces for C types pointers
IgnoreTokens : TStringList;
ConvertPrefix : TStringList;
FloatTypes : TStringList;
StructTypes : TStringList;
ObjCTypes : TStringList;
ObjCClassTypes : TStringList;
CustomTypes : TStringList;
constructor Create;
destructor Destroy; override;
procedure AssignNewTypeName(const AName, TypeDefStr: AnsiString; var NewTypeName: AnsiString);
end;
var
@ -70,13 +74,15 @@ procedure WriteOutIncludeFile(hdr: TObjCHeader; st: TStrings);
procedure WriteOutMainFramework(hdr: TObjCHeader; st: TStrings);
function ObjCToDelphiType(const objcType: AnsiString; isPointer: Boolean): AnsiString;
function ObjCResultToDelphiType(Res: TObjCResultTypeDef) : AnsiString;
function CToDelphiFuncType(AFuncType: TFunctionTypeDef): AnsiString;
function StrFromFile(const FileName: AnsiString): AnsiString;
function IsMethodConstructor(cl: TClassDef; m: TClassMethodDef): Boolean;
function GetMethodStr(cl: TClassDef; m: TClassMethodDef; ForImplementation: Boolean): AnsiString;
function GetProcFuncHead(const FuncName, OfClass, Params, ResType: AnsiString; const FuncDest: AnsiString = ''): AnsiString;
function GetMethodParams(const m: TClassMethodDef): AnsiString;
function GetMethodParams(const m: TClassMethodDef; NamesOnly: Boolean): AnsiString;
function GetMethodResultType(const m: TClassMethodDef): AnsiString;
function IsPascalReserved(const s: AnsiString): Boolean;
@ -96,12 +102,12 @@ begin
Result := vt_FloatPoint;
Exit;
end;
if ConvertSettings.FloatTypes.IndexOf(TypeName) >= 0 then
Result := vt_FloatPoint
else if ConvertSettings.StructTypes.IndexOf(TypeName) >= 0 then
Result := vt_Struct
else if ConvertSettings.ObjCTypes.IndexOf(TypeName) >= 0 then
else if ConvertSettings.ObjCClassTypes.IndexOf(TypeName) >= 0 then
Result := vt_Object;
end;
@ -171,33 +177,66 @@ end;
function GetMethodResultType(const m: TClassMethodDef): AnsiString;
var
res : TObjCResultTypeDef;
tp : TTypeDef;
begin
res := m.GetResultType;
if not Assigned(res) then Result := ''
else Result := ObjCToDelphiType(m.GetResultType._Name, m.GetResultType._IsPointer);
else begin
if m.GetResultType._Type is TTypeDef then begin
tp := TTypeDef(m.GetResultType._Type);
Result := ObjCToDelphiType(tp._Name, tp._IsPointer);
end else begin
ConvertSettings.AssignNewTypeName('', CToDelphiFuncType(TFunctionTypeDef(m.GetResultType._Type)), Result);
end;
end;
end;
function GetMethodParams(const m: TClassMethodDef): AnsiString;
function GetMethodParams(const m: TClassMethodDef; NamesOnly: Boolean): AnsiString;
var
i : Integer;
p : TObject;
vname : AnsiString;
vtype : AnsiString;
tp : TTypeDef;
prc : AnsiString;
begin
Result := '';
vname := '';
vtype := '';
for i := 0 to m.Items.Count - 1 do begin
p := TObject(m.Items[i]);
if p is TParamDescr then
vname := TParamDescr(p)._Descr
else if p is TObjCParameterDef then begin
if vname = '' then vname := TObjCParameterDef(p)._Name;
vtype := ObjCToDelphiType(TObjCParameterDef(p)._Res._Name, TObjCParameterDef(p)._Res._IsPointer);
if Result <> '' then Result := Result + '; ';
if p is TParamDescr then begin
if vname = '' then vname := TParamDescr(p)._Descr
end else if p is TObjCParameterDef then begin
vname := TObjCParameterDef(p)._Name;
if (TObjCParameterDef(p)._Type._Type) is TTypeDef then begin
tp := TTypeDef(TObjCParameterDef(p)._Type._Type);
vtype := ObjCToDelphiType(tp._Name, tp._IsPointer);
end else begin
prc := 'TProc' + TObjCParameterDef(p)._Name + IntToStr(ConvertSettings.CustomTypes.Count);
ConvertSettings.AssignNewTypeName(prc, CToDelphiFuncType(TFunctionTypeDef(TObjCParameterDef(p)._Type._Type)), vtype);
tp := TTypeDef.Create(TObjCParameterDef(p)._Type);
tp._Name := vtype;
TObjCParameterDef(p)._Type._Type.Free; // replace function type with typename
TObjCParameterDef(p)._Type._Type := tp;
end;
{if IsPascalReserved(vname) then }
vname := '_'+vname;
if Copy(vtype, 1, 5) = 'array' then Result := Result + 'const A'+vname + ': ' + vtype
else Result := Result + 'A'+vname + ': ' + vtype;
if not NamesOnly then begin
if Result <> '' then Result := Result + '; ';
if Copy(vtype, 1, 5) = 'array' then Result := Result + 'const '+vname + ': ' + vtype
else Result := Result + ''+vname + ': ' + vtype;
end else begin
if Result = '' then Result := vname
else Result := Result + ', ' + vname;
end;
vname := '';
end;
end;
@ -282,6 +321,14 @@ begin
end;
end;
function ObjCResultToDelphiType(Res: TObjCResultTypeDef) : AnsiString;
begin
if Res._Type is TTypeDef then
Result := ObjCToDelphiType( TTypeDef(Res._Type)._Name, TTypeDef(Res._Type)._IsPointer)
else begin
end;
end;
function IsMethodConstructor(cl: TClassDef; m: TClassMethodDef): Boolean;
var
res : TObjCResultTypeDef;
@ -298,7 +345,10 @@ begin
if not Result then Exit;
res := m.GetResultType;
l := res._Name;
if res._Type is TTypeDef then
l := TTypeDef(res._Type)._Name
else
l := '!!!todo function';
Result := (l = 'id') or (l = cl._ClassName);
end;
@ -337,8 +387,8 @@ begin
nm := m._Name;
if ForImplementation
then Result := GetProcFuncHead(nm, cl._ClassName, GetMethodParams(m), res, ft)
else Result := GetProcFuncHead(nm, '', GetMethodParams(m), res, ft);
then Result := GetProcFuncHead(nm, cl._ClassName, GetMethodParams(m, false), res, ft)
else Result := GetProcFuncHead(nm, '', GetMethodParams(m, false), res, ft);
if ft = '' then
if m._IsClassMethod then
@ -462,7 +512,7 @@ begin
if (dir = '#import') or (dir = '#include') then begin
prm := GetIncludeFile(Prec._Params);
if (prm <> '') and (prm <> ' .inc') and (ConvertSettings.IgnoreIncludes.IndexOf(prm) < 0) then
if (prm <> '') and (prm <> ' .inc') then
Result := Format('{$include %s}', [prm]);
end else if (dir = '#if') then begin
@ -899,8 +949,9 @@ begin
fntype := '{todo: not implemented... see .h file for type}';
end;
restype := ObjCToDelphiType(fntype, isptr);
Result := GetProcFuncHead('', '', CParamsListToPascalStr(AFuncType._ParamsList), restype);
Result := Copy(Result, 1, length(Result) - 1);
Result := GetProcFuncHead('', '', CParamsListToPascalStr(AFuncType._ParamsList), restype) + ' cdecl';
//Result := Copy(Result, 1, length(Result) - 1);
//Result := Result + '; cdecl';
end;
procedure WriteOutRecordField(AField: TStructField; const Prefix: AnsiString; subs: TStrings);
@ -923,7 +974,7 @@ begin
nm := Prefix + Format('%s : %s', [AField._Name, nm]);
subs[i] := nm;
end;
end else begin
end else begin
if (AField._Type is TFunctionTypeDef) then
pastype := CToDelphiFuncType(AField._Type as TFunctionTypeDef)
@ -1019,7 +1070,7 @@ begin
case GetObjCVarType(FromType) of
vt_FloatPoint: ConvertSettings.FloatTypes.Add(NewType);
vt_Object: ConvertSettings.ObjCTypes.Add(NewType);
vt_Object: ConvertSettings.ObjCClassTypes.Add(NewType);
vt_Struct: ConvertSettings.StructTypes.Add(NewType);
end;
end;
@ -1118,6 +1169,7 @@ var
// cnt : Integer;
s : AnsiString;
nm : AnsiString;
cmt : AnsiString;
j : Integer;
obj : TObject; // or TEntity
@ -1161,6 +1213,13 @@ begin
nm := TClassMethodDef(cl.Items[j])._Name;
i := mtds.IndexOf(nm);
if Integer(mtds.Objects[i]) > 0 then s := s + ' overload;';
if Assigned(TClassMethodDef(cl.Items[j]).GetResultType) then begin
cmt := TClassMethodDef(cl.Items[j]).GetResultType.TagComment;
if cmt <> '' then
s := s + '{'+cmt+'}';
end;
subs.Add(SpacePrefix + s);
end else if obj is TPrecompiler then begin
WriteOutIfDefPrecompiler(TPrecompiler(obj), SpacePrefix, subs);
@ -1199,6 +1258,16 @@ begin
BeginSection('CLASSES', st);
BeginExcludeSection( GetIfDefFileName(hdr._FileName, 'C'), st);
try
if ConvertSettings.CustomTypes.Count > 0 then begin
with ConvertSettings do
for i := 0 to CustomTypes.Count - 1 do
CustomTypes[i] := ' ' + CustomTypes[i];
st.AddStrings(ConvertSettings.CustomTypes);
st.Add('');
ConvertSettings.CustomTypes.Clear;
end;
st.AddStrings(subs);
finally
EndSection(st);
@ -1234,7 +1303,7 @@ var
begin
typeName := MtdPrefix + mtd._Name + MtdPostFix;
subs.Add('type');
ms := GetMethodParams(mtd);
ms := GetMethodParams(mtd, false);
if ms = '' then ms := 'param1: objc.id; param2: SEL'
else ms := 'param1: objc.id; param2: SEL' + ';' + ms;
restype := GetMethodResultType(mtd);
@ -1244,7 +1313,7 @@ begin
subs.Add(s);
end;
function GetParamsNames(mtd: TClassMethodDef): AnsiString;
(*function GetParamsNames(mtd: TClassMethodDef): AnsiString;
var
i : Integer;
obj : TObject;
@ -1262,7 +1331,7 @@ begin
end;
end;
Result := Result + vname;
end;
end;*)
// procedure writes out constructor entity to the implementation section
@ -1288,7 +1357,7 @@ var
begin
cl := TClassDef(mtd.Owner);
ObjCMethodToProcType(mtd, typeName, subs);
prms := GetParamsNames(mtd);
prms := GetMethodParams(mtd, true);
if prms <> '' then prms := ', ' + prms;
if (Pos('init', mtd._Name) = 1) and (not mtd._IsClassMethod) then begin
@ -1342,21 +1411,25 @@ begin
//s := Format('vmethod(%s, sel_registerName(PChar(Str%s_%s)), %s)', [callobj, cl._ClassName, RefixName(mtd._Name), GetParamsNames(mtd)]);
tp := GetObjCVarType(res);
case tp of
vt_Int: s := Format('objc_msgSend(%s, sel_registerName(PChar(Str%s_%s)), [])', [callobj, cl._ClassName, mnm ]);
vt_Int, vt_Object: s := Format('objc_msgSend(%s, sel_registerName(PChar(Str%s_%s)), [])', [callobj, cl._ClassName, mnm ]);
vt_FloatPoint: s := Format('objc_msgSend_fpret(%s, sel_registerName(PChar(Str%s_%s)), [])', [callobj, cl._ClassName, mnm ]);
vt_Struct: s := Format('objc_msgSend_stret(@Result, %s, sel_registerName(PChar(Str%s_%s)), [])', [callobj, cl._ClassName, mnm ]);
end;
if (ObjCToDelphiType(mtd.GetResultType._Name, mtd.GetResultType._IsPointer) <> '') and (tp <> vt_Struct) then
s := 'Result := ' + s;
if (tp <> vt_Struct) and (ObjCResultToDelphiType(mtd.GetResultType) <> '') then begin
if tp <> vt_FloatPoint then
s := Format('Result := %s(%s)', [res, s])
else
s := Format('Result := %s', [s]);
//s := 'Result := ' res(' + s+')';
end;
ObjCMethodToProcType(mtd, typeName, subs);
subs.Add('var');
subs.Add(
Format(' vmethod: %s;', [typeName]));
subs.Add('begin');
subs.Add(
Format(' vmethod := %s(@objc_msgSend);', [typeName]));
subs.Add(
@ -1379,7 +1452,7 @@ begin
res := GetMethodResultType(mtd);
tp := GetObjCVarType(res);
if tp = vt_Object then begin
{ if tp = vt_Object then begin
subs.Add('var');
subs.Add(' hnd: objc.id;');
subs.Add('begin');
@ -1390,27 +1463,30 @@ begin
subs.Add(' end else');
subs.Add(' Result := nil;');
subs.Add('end;');
end else begin
end else begin}
mnm := RefixName(mtd._Name);
case tp of
vt_Int: s := Format('objc_msgSend(%s, sel_registerName(PChar(Str%s_%s)), [])', [callobj, cl._ClassName, mnm ]);
vt_Int, vt_Object: s := Format('objc_msgSend(%s, sel_registerName(PChar(Str%s_%s)), [])', [callobj, cl._ClassName, mnm ]);
vt_FloatPoint: s := Format('objc_msgSend_fpret(%s, sel_registerName(PChar(Str%s_%s)), [])', [callobj, cl._ClassName, mnm ]);
vt_Struct: s := Format('objc_msgSend_stret(@Result, %s, sel_registerName(PChar(Str%s_%s)), [])', [callobj, cl._ClassName, mnm ]);
end;
if (tp <> vt_Struct) and (res <> '') then begin
if res = 'objc.id' then s := 'Result := ' +s
else s := 'Result := '+res+'('+s+')'
if tp <> vt_FloatPoint then
s := Format('Result := %s(%s)', [res, s])
else
s := Format('Result := %s', [s]);
//s := 'Result := '+res+'('+s+')';
//if res = 'objc.id' then s := 'Result := ' +s
//else
end;
s := s + ';';
subs.Add('begin');
subs.Add(' ' + s);
subs.Add('end;');
end;
// end;
end;
procedure WriteOutMethodToImplementation(mtd: TClassMethodDef; subs: TStrings);
@ -1609,6 +1685,8 @@ var
i : Integer;
obj : TEntity;
prm : TObjCParameterDef;
res : TObjCResultTypeDef;
td : TTypeDef;
begin
// i := 0;
for i := 0 to ent.Items.Count - 1 do begin
@ -1625,18 +1703,35 @@ begin
TClassDef(obj)._SuperClass := 'TObject'
end else if (obj is TParamDescr) then begin
if IsPascalReserved(TParamDescr(obj)._Descr) then
TParamDescr(obj)._Descr := '_'+TParamDescr(obj)._Descr;
TParamDescr(obj)._Descr := '_'+TParamDescr(obj)._Descr
end else if (obj is TClassMethodDef) and not IsMethodConstructor(TClassDef(obj.Owner ), TClassMethodDef(obj)) then begin
res := TClassMethodDef(obj).GetResultType;
if ConvertSettings.ObjCClassTypes.IndexOf( ObjCResultToDelphiType(res))>= 0 then
if res._Type is TTypeDef then begin
td := TTypeDef(res._Type);
res.tagComment := td._Name;
td._Name := Format('objc.id', [td._Name] );
end;
end else if (obj is TObjCParameterDef) then begin
prm := TObjCParameterDef(obj);
if ConvertSettings.ObjCTypes.IndexOf(prm._Res._Name) >= 0 then
prm._Res._Name := Format('objc.id {%s}', [prm._Res._Name] );
if ConvertSettings.ObjCClassTypes.IndexOf( ObjCResultToDelphiType(prm._Type) ) >= 0 then begin
if prm._Type._Type is TTypeDef then begin
TTypeDef(prm._Type._Type)._Name := Format('objc.id {%s}', [TTypeDef(prm._Type._Type)._Name] );
end;
end;
if IsPascalReserved(prm._Name) then
prm._Name := '_' + prm._Name;
end else if (obj is TStructField) then begin
if ConvertSettings.ObjCTypes.IndexOf(TStructField(obj)._TypeName) >= 0 then
prm._Res._Name := 'objc.id';
// should _TypeName to be removed?
if ConvertSettings.ObjCClassTypes.IndexOf(TStructField(obj)._TypeName) >= 0 then begin
TStructField(obj)._TypeName := 'objc.id'
end;
end;
end;
// packing list, removing nil references.
@ -1707,6 +1802,7 @@ begin
WriteOutHeaderSection(hdr, st);
WriteOutForwardSection(hdr, st);
for i := 0 to hdr.Items.Count - 1 do
if TObject(hdr.Items[i]) is TClassDef then
@ -1729,6 +1825,18 @@ end;
{ TConvertSettings }
procedure TConvertSettings.AssignNewTypeName(const AName, TypeDefStr: AnsiString; var NewTypeName: AnsiString);
var
typeName : AnsiSTring;
begin
typeName := AName;
if typeName = '' then typeName := 'CnvType' + IntToStr(CustomTypes.Count);
NewTypeName := typeName;
CustomTypes.Add( Format('%s = %s;', [NewTypeName, TypeDefStr]) );
// todo: add! a new type!
end;
constructor TConvertSettings.Create;
begin
IgnoreTokens := TStringList.Create;
@ -1745,16 +1853,17 @@ begin
StructTypes := TStringList.Create;
StructTypes.CaseSensitive := false;
ObjCTypes := TStringList.Create;
ObjCClassTypes := TStringList.Create;
ObjCClassTypes.CaseSensitive := false;
ObjCTypes.CaseSensitive := false;
CustomTypes := TStringList.Create;
end;
destructor TConvertSettings.Destroy;
begin
FloatTypes.Free;
StructTypes.Free;
ObjCTypes.Free;
ObjCClassTypes.Free;
IgnoreTokens.Free;
IgnoreIncludes.Free;
@ -1762,6 +1871,7 @@ begin
PtrTypeReplace.Free;
DefineReplace.Free;
ConvertPrefix.Free;
CustomTypes.Free;
inherited Destroy;
end;
@ -1777,15 +1887,17 @@ begin
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_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';
DefineReplace['__LP64__'] := 'LP64';}
TypeDefReplace['unsigned char'] := 'byte';
TypeDefReplace['uint8_t'] := 'byte';
PtrTypeReplace['uint8_t'] := 'PByte';
PtrTypeReplace['unsigned char'] := 'PChar';
PtrTypeReplace['char'] := 'PChar';
TypeDefReplace['short'] := 'SmallInt';
TypeDefReplace['short int'] := 'SmallInt';
@ -1795,50 +1907,72 @@ begin
TypeDefReplace['uint16_t'] := 'Word';
TypeDefReplace['int'] := 'Integer';
TypeDefReplace['signed'] := 'Integer';
TypeDefReplace['signed int'] := 'Integer';
TypeDefReplace['int32_t'] := 'Integer';
TypeDefReplace['NSInteger'] := 'Integer';
TypeDefReplace['unsigned'] := 'LongWord';
PtrTypeReplace['unsigned'] := 'PLongWord';
TypeDefReplace['unsigned int'] := 'LongWord';
TypeDefReplace['uint32_t'] := 'LongWord';
TypeDefReplace['NSUInteger'] := 'LongWord';
PtrTypeReplace['int'] := 'PInteger';
PtrTypeReplace['signed'] := 'PInteger';
PtrTypeReplace['signed int'] := 'PInteger';
PtrTypeReplace['int32_t'] := 'PInteger';
PtrTypeReplace['NSInteger'] := 'PInteger';
PtrTypeReplace['unsigned'] := 'PLongWord';
PtrTypeReplace['unsigned int'] := 'PLongWord';
PtrTypeReplace['uint32_t'] := 'PLongWord';
PtrTypeReplace['NSUInteger'] := 'PLongWord';
TypeDefReplace['long long'] := 'Int64';
PtrTypeReplace['long long'] := 'PInt64';
TypeDefReplace['signed long long'] := 'Int64';
PtrTypeReplace['signed long long'] := 'PInt64';
TypeDefReplace['singned long long'] := 'Int64';
TypeDefReplace['unsigned long long'] := 'Int64';
PtrTypeReplace['unsigned long long'] := 'PInt64';
TypeDefReplace['int64_t'] := 'Int64';
PtrTypeReplace['int64_t'] := 'PInt64';
TypeDefReplace['uint64_t'] := 'Int64';
PtrTypeReplace['long long'] := 'PInt64';
PtrTypeReplace['singned long long'] := 'PInt64';
PtrTypeReplace['unsigned long long'] := 'PInt64';
PtrTypeReplace['int64_t'] := 'PInt64';
PtrTypeReplace['uint64_t'] := 'PInt64';
TypeDefReplace['float'] := 'Single';
TypeDefReplace['CGFloat'] := 'Single';
PtrTypeReplace['double'] := 'PDouble';
PtrTypeReplace['float'] := 'PSingle';
PtrTypeReplace['CGFloat'] := 'PSingle';
TypeDefReplace['Class'] := '_Class';
TypeDefReplace['SRefCon'] := 'Pointer';
TypeDefReplace['va_list'] := 'array of const';
StructTypes.Add('Int64');
StructTypes.Add('NSAffineTransformStruct');
FloatTypes.Add('NSTimeInterval');
TypeDefReplace['uint8_t']:='byte';
TypeDefReplace['unsigned long long']:='Int64';
TypeDefReplace['long long']:='Int64';
TypeDefReplace['signed long long']:='Int64';
TypeDefReplace['unsigned']:='LongWord';
PtrTypeReplace['uint8_t']:='Pbyte';
PtrTypeReplace['unsigned long long']:='PInt64';
PtrTypeReplace['long long']:='Int64';
PtrTypeReplace['signed long long']:='PInt64';
PtrTypeReplace['unsigned']:='PLongWord';
IgnoreTokens.Add('DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER');
StructTypes.Add('Int64');
{ StructTypes.Add('NSAffineTransformStruct');
FloatTypes.Add('NSTimeInterval');
FloatTypes.Add('CFFloat');}
{IgnoreTokens.Add('DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER');
IgnoreTokens.Add('DEPRECATED_IN_MAC_OS_X_VERSION_10_4_AND_LATER');
IgnoreTokens.Add('AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER');
IgnoreTokens.Add('AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER');
IgnoreTokens.Add('AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER');
IgnoreTokens.Add('AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER');
IgnoreTokens.Add('AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER');}
end;
end;

View File

@ -0,0 +1,250 @@
[common]
ignoreincludes0=CoreFoundation/ Foundation/
ignoreincludes1=setjmp.h stdarg.h stdbool.h limits.h stdarg.h
ignoreincludes2=AvailabilityMacros.h
ignoreincludes3=ApplicationServices/
ignoreincludes4=ApplicationServices/../FrameWorks/CoreGraphics.framework/Headers/
ignoreincludes5=AvailabilityMacros.h
[TypeReplace]
NSStringRef=CFStringRef
NSStringRef*=CFStringRef
NSArray=CFArrayRef
NSArray*=CFArrayRef
NSAttributedString=CFAttributedStringRef
NSAttributesString*=CFAttributedStringRef
NSCalendar=CFCalendarRef
NSCalendar*=CFCalendarRef
NSCharacterSet=CFCharacterSetRef
NSCharacterSet*=CFCharacterSetRef
NSData=CFDataRef
NSData*=CFDataRef
NSDate=CFDateRef
NSDate*=CFDateRef
NSDictionary=CFDictionaryRef
NSDictionary*=CFDictionaryRef
NSError=CFErrorRef
NSError*=CFErrorRef
NSLocale=CFErrorRef
NSLocale*=CFErrorRef
NSMutableArray=CFMutableArrayRef
NSMutableArray*=CFMutableArrayRef
NSMutableAttributedString=CFMutableAttributedStringRef
NSMutableAttributedString*=CFMutableAttributedStringRef
NSMutableCharacterSetRef=CFMutableCharacterSetRef
NSMutableCharacterSetRef*=CFMutableCharacterSetRef
NSMutableData = CFMutableDataRef
NSMutableDictionary = CFMutableDictionaryRef
NSMutableSet = CFMutableSetRef
NSMutableString = CFMutableStringRef
NSNumber = CFNumberRef
NSInputStream = CFReadStreamRef
NSTimer = CFRunLoopTimerRef
NSSet = CFSetRef
NSString = CFStringRef
NSTimeZone = CFTimeZoneRef
NSURL = CFURLRef
NSOutputStream = CFWriteStreamRef
AEDesc*=AEDescPtr
NSMutableData*= CFMutableDataRef
NSMutableDictionary*= CFMutableDictionaryRef
NSMutableSet*= CFMutableSetRef
NSMutableString* = CFMutableStringRef
NSNumber* = CFNumberRef
NSInputStream*= CFReadStreamRef
NSTimer*= CFRunLoopTimerRef
NSSet*= CFSetRef
NSString*= CFStringRef
NSTimeZone*= CFTimeZoneRef
NSURL*= CFURLRef
NSOutputStream*= CFWriteStreamRef
[TypeDefs]
CGRect=struct
CGSize=struct
CGPoint=struct
CFTimeInterval=float
CGAffineTransform=struct
NSPoint=struct
NSSize=struct
NSRange=struct
NSTimeInterval=float
NSAffineTransformStruct=struct
NSAffineTransform=objcclass
NSAppleEventDescriptor=objcclass
NSAppleEventManager=objcclass
NSAppleScript=objcclass
NSArchiver=objcclass
NSUnarchiver=objcclass
NSObject=objcclass
NSArray=objcclass
NSMutableArray=objcclass
NSAttributedString=objcclass
NSMutableAttributedString=objcclass
NSAutoreleasePool=objcclass
NSBundle=objcclass
NSCalendar=objcclass
NSDateComponents=objcclass
NSCalendarDate=objcclass
NSDate=objcclass
NSCharacterSet=objcclass
NSMutableCharacterSet=objcclass
NSClassDescription=objcclass
NSCoder=objcclass
NSComparisonPredicate=objcclass
NSCompoundPredicate=objcclass
NSConnection=objcclass
NSDistantObjectRequest=objcclass
NSData=objcclass
NSMutableData=objcclass
NSDateFormatter=objcclass
NSDecimalNumber=objcclass
NSDecimalNumberHandler=objcclass
NSNumber=objcclass
NSScanner=objcclass
NSDictionary=objcclass
NSMutableDictionary=objcclass
NSDistantObject=objcclass
NSDistributedLock=objcclass
NSDistributedNotificationCenter=objcclass
NSEnumerator=objcclass
NSError=objcclass
NSException=objcclass
NSAssertionHandler=objcclass
NSExpression=objcclass
NSFileHandle=objcclass
NSPipe=objcclass
NSFileManager=objcclass
NSDirectoryEnumerator=objcclass
NSFormatter=objcclass
NSGarbageCollector=objcclass
NSValue=objcclass
NSHashTable=objcclass
NSHost=objcclass
NSHTTPCookie=objcclass
NSHTTPCookieStorage=objcclass
NSIndexPath=objcclass
NSIndexSet=objcclass
NSMutableIndexSet=objcclass
NSInvocation=objcclass
NSKeyedArchiver=objcclass
NSKeyedUnarchiver=objcclass
NSSet=objcclass
NSLocale=objcclass
NSLock=objcclass
NSConditionLock=objcclass
NSRecursiveLock=objcclass
NSCondition=objcclass
NSMapTable=objcclass
NSMetadataQuery=objcclass
NSMetadataItem=objcclass
NSMetadataQueryAttributeValueTuple=objcclass
NSMetadataQueryResultGroup=objcclass
NSMethodSignature=objcclass
NSNetService=objcclass
NSNetServiceBrowser=objcclass
NSNotification=objcclass
NSNotificationCenter=objcclass
NSNotificationQueue=objcclass
NSNull=objcclass
NSNumberFormatter=objcclass
NSOperation=objcclass
NSInvocationOperation=objcclass
NSOperationQueue=objcclass
NSString=objcclass
NSPointerArray=objcclass
NSPointerFunctions=objcclass
NSPort=objcclass
NSMachPort=objcclass
NSMessagePort=objcclass
NSSocketPort=objcclass
NSPortCoder=objcclass
NSPortMessage=objcclass
NSPortNameServer=objcclass
NSMachBootstrapServer=objcclass
NSMessagePortNameServer=objcclass
NSSocketPortNameServer=objcclass
NSPredicate=objcclass
NSMutableSet=objcclass
NSProcessInfo=objcclass
NSPropertyListSerialization=objcclass
NSProtocolChecker=objcclass
NSProxy=objcclass
NSRunLoop=objcclass
NSScriptClassDescription=objcclass
NSScriptCoercionHandler=objcclass
NSScriptCommand=objcclass
NSScriptCommandDescription=objcclass
NSScriptExecutionContext=objcclass
NSScriptObjectSpecifier=objcclass
NSIndexSpecifier=objcclass
NSMiddleSpecifier=objcclass
NSNameSpecifier=objcclass
NSPositionalSpecifier=objcclass
NSPropertySpecifier=objcclass
NSRandomSpecifier=objcclass
NSRangeSpecifier=objcclass
NSRelativeSpecifier=objcclass
NSUniqueIDSpecifier=objcclass
NSWhoseSpecifier=objcclass
NSCloneCommand=objcclass
NSCloseCommand=objcclass
NSCountCommand=objcclass
NSCreateCommand=objcclass
NSDeleteCommand=objcclass
NSExistsCommand=objcclass
NSGetCommand=objcclass
NSMoveCommand=objcclass
NSQuitCommand=objcclass
NSSetCommand=objcclass
NSScriptSuiteRegistry=objcclass
NSScriptWhoseTest=objcclass
NSLogicalTest=objcclass
NSSpecifierTest=objcclass
NSCountedSet=objcclass
NSSortDescriptor=objcclass
NSSpellServer=objcclass
NSStream=objcclass
NSInputStream=objcclass
NSOutputStream=objcclass
NSMutableString=objcclass
NSSimpleCString=objcclass
NSConstantString=objcclass
NSTask=objcclass
NSThread=objcclass
NSTimer=objcclass
NSTimeZone=objcclass
NSUndoManager=objcclass
NSURL=objcclass
NSURLAuthenticationChallenge=objcclass
NSCachedURLResponse=objcclass
NSURLCache=objcclass
NSURLConnection=objcclass
NSURLCredential=objcclass
NSURLCredentialStorage=objcclass
NSURLDownload=objcclass
NSURLHandle=objcclass
NSURLProtectionSpace=objcclass
NSURLProtocol=objcclass
NSURLRequest=objcclass
NSMutableURLRequest=objcclass
NSURLResponse=objcclass
NSHTTPURLResponse=objcclass
NSUserDefaults=objcclass
NSValueTransformer=objcclass
NSXMLDocument=objcclass
NSXMLDTD=objcclass
NSXMLDTDNode=objcclass
NSXMLElement=objcclass
NSXMLNode=objcclass
NSXMLParser=objcclass
[TokenReplace]
DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER=""
DEPRECATED_IN_MAC_OS_X_VERSION_10_4_AND_LATER=""
AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER=""
AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER=""
AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER=""
AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER=""

View File

@ -11,12 +11,13 @@
</Flags>
<MainUnit Value="0"/>
<IconPath Value="./"/>
<TargetFileExt Value=".exe"/>
<UseAppBundle Value="False"/>
<TargetFileExt Value=""/>
<ActiveEditorIndexAtStart Value="1"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
<Language Value=""/>
<CharSet Value=""/>
</VersionInfo>
<PublishOptions>
<Version Value="2"/>
@ -30,270 +31,45 @@
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<Units Count="36">
<Units Count="3">
<Unit0>
<Filename Value="objcparser.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="objcparser"/>
<CursorPos X="1" Y="409"/>
<TopLine Value="388"/>
<CursorPos X="69" Y="3"/>
<TopLine Value="1"/>
<EditorIndex Value="0"/>
<UsageCount Value="81"/>
<UsageCount Value="26"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
<Filename Value="ObjCParserUtils.pas"/>
<UnitName Value="ObjCParserUtils"/>
<CursorPos X="1" Y="1353"/>
<TopLine Value="1334"/>
<CursorPos X="44" Y="1705"/>
<TopLine Value="1703"/>
<EditorIndex Value="1"/>
<UsageCount Value="37"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
</Unit1>
<Unit2>
<Filename Value="ObjCParserTypes.pas"/>
<UnitName Value="ObjCParserTypes"/>
<CursorPos X="9" Y="517"/>
<TopLine Value="517"/>
<CursorPos X="30" Y="85"/>
<TopLine Value="64"/>
<EditorIndex Value="2"/>
<UsageCount Value="37"/>
<Bookmarks Count="1">
<Item0 X="1" Y="626" ID="0"/>
</Bookmarks>
<UsageCount Value="13"/>
<Loaded Value="True"/>
</Unit2>
<Unit3>
<Filename Value="../foundation/foundation.pas"/>
<UnitName Value="foundation"/>
<CursorPos X="28" Y="10"/>
<TopLine Value="1"/>
<UsageCount Value="7"/>
</Unit3>
<Unit4>
<Filename Value="../appkit/AppKit.inc"/>
<CursorPos X="18" Y="156"/>
<TopLine Value="156"/>
<UsageCount Value="10"/>
</Unit4>
<Unit5>
<Filename Value="../../objc/objc.pas"/>
<UnitName Value="objc"/>
<CursorPos X="32" Y="38"/>
<TopLine Value="36"/>
<UsageCount Value="11"/>
</Unit5>
<Unit6>
<Filename Value="../../objc/objc-api.inc"/>
<CursorPos X="106" Y="9"/>
<TopLine Value="8"/>
<UsageCount Value="7"/>
</Unit6>
<Unit7>
<Filename Value="../appkit/NSActionCell.inc"/>
<CursorPos X="49" Y="34"/>
<TopLine Value="13"/>
<UsageCount Value="7"/>
</Unit7>
<Unit8>
<Filename Value="../appkit/NSCell.inc"/>
<CursorPos X="1" Y="48"/>
<TopLine Value="42"/>
<UsageCount Value="7"/>
</Unit8>
<Unit9>
<Filename Value="../foundation/NSGeometry.inc"/>
<CursorPos X="1" Y="46"/>
<TopLine Value="26"/>
<UsageCount Value="9"/>
</Unit9>
<Unit10>
<Filename Value="../foundation/NSObject.inc"/>
<CursorPos X="37" Y="302"/>
<TopLine Value="302"/>
<UsageCount Value="17"/>
<Loaded Value="True"/>
</Unit10>
<Unit11>
<Filename Value="pascodeutils.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="pascodeutils"/>
<CursorPos X="1" Y="13"/>
<TopLine Value="1"/>
<UsageCount Value="78"/>
</Unit11>
<Unit12>
<Filename Value="../appkit/NSWindow.inc"/>
<CursorPos X="37" Y="302"/>
<TopLine Value="302"/>
<UsageCount Value="19"/>
<Loaded Value="True"/>
</Unit12>
<Unit13>
<Filename Value="test.inc"/>
<CursorPos X="9" Y="18"/>
<TopLine Value="1"/>
<UsageCount Value="8"/>
</Unit13>
<Unit14>
<Filename Value="NSWindow.h"/>
<CursorPos X="35" Y="194"/>
<TopLine Value="172"/>
<UsageCount Value="23"/>
<SyntaxHighlighter Value="C++"/>
</Unit14>
<Unit15>
<Filename Value="../../objc/objc-runtime.inc"/>
<CursorPos X="1" Y="127"/>
<TopLine Value="127"/>
<UsageCount Value="11"/>
</Unit15>
<Unit16>
<Filename Value="headers/NSScreen.h"/>
<CursorPos X="1" Y="9"/>
<TopLine Value="1"/>
<UsageCount Value="9"/>
<SyntaxHighlighter Value="C++"/>
</Unit16>
<Unit17>
<Filename Value="../foundation/NSAutoreleasePool.inc"/>
<CursorPos X="16" Y="12"/>
<TopLine Value="12"/>
<UsageCount Value="8"/>
</Unit17>
<Unit18>
<Filename Value="../appkit/NSButton.inc"/>
<CursorPos X="23" Y="15"/>
<TopLine Value="12"/>
<UsageCount Value="8"/>
</Unit18>
<Unit19>
<Filename Value="../appkit/NSControl.inc"/>
<CursorPos X="21" Y="151"/>
<TopLine Value="139"/>
<UsageCount Value="12"/>
</Unit19>
<Unit20>
<Filename Value="headers/NSButton.h"/>
<CursorPos X="1" Y="23"/>
<TopLine Value="4"/>
<UsageCount Value="8"/>
<SyntaxHighlighter Value="C++"/>
</Unit20>
<Unit21>
<Filename Value="NSWindow.inc"/>
<CursorPos X="51" Y="447"/>
<TopLine Value="442"/>
<UsageCount Value="18"/>
</Unit21>
<Unit22>
<Filename Value="NSWindow2.h"/>
<IsPartOfProject Value="True"/>
<CursorPos X="44" Y="16"/>
<TopLine Value="11"/>
<UsageCount Value="59"/>
<SyntaxHighlighter Value="C++"/>
</Unit22>
<Unit23>
<Filename Value="../uikit/UIKit.h"/>
<CursorPos X="1" Y="31"/>
<TopLine Value="1"/>
<UsageCount Value="9"/>
<SyntaxHighlighter Value="C++"/>
</Unit23>
<Unit24>
<Filename Value="../appkit/NSAlert.inc"/>
<CursorPos X="1" Y="61"/>
<TopLine Value="38"/>
<UsageCount Value="9"/>
</Unit24>
<Unit25>
<Filename Value="../appkit/NSPanel.inc"/>
<CursorPos X="1" Y="34"/>
<TopLine Value="11"/>
<UsageCount Value="9"/>
</Unit25>
<Unit26>
<Filename Value="../appkit/NSView.inc"/>
<CursorPos X="5" Y="136"/>
<TopLine Value="121"/>
<UsageCount Value="12"/>
</Unit26>
<Unit27>
<Filename Value="headersMacOS/NSWindow.inc"/>
<CursorPos X="37" Y="302"/>
<TopLine Value="302"/>
<UsageCount Value="11"/>
</Unit27>
<Unit28>
<Filename Value="../appkit/appkit.pas"/>
<UnitName Value="appkit"/>
<CursorPos X="1" Y="7"/>
<TopLine Value="1"/>
<UsageCount Value="10"/>
</Unit28>
<Unit29>
<Filename Value="NSFontPanelUnit.pas"/>
<UnitName Value="NSFontPanelUnit"/>
<CursorPos X="25" Y="93"/>
<TopLine Value="79"/>
<UsageCount Value="9"/>
</Unit29>
<Unit30>
<Filename Value="objc.pas"/>
<UnitName Value="objc"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="9"/>
</Unit30>
<Unit31>
<Filename Value="/usr/local/share/fpcsrc/rtl/objpas/sysutils/finah.inc"/>
<CursorPos X="10" Y="28"/>
<TopLine Value="18"/>
<UsageCount Value="9"/>
</Unit31>
<Unit32>
<Filename Value="/usr/local/share/fpcsrc/rtl/objpas/sysutils/fina.inc"/>
<CursorPos X="1" Y="41"/>
<TopLine Value="34"/>
<UsageCount Value="9"/>
</Unit32>
<Unit33>
<Filename Value="NSAlert.inc"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="9"/>
</Unit33>
<Unit34>
<Filename Value="NSAffineTransform.h"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="9"/>
<SyntaxHighlighter Value="C++"/>
</Unit34>
<Unit35>
<Filename Value="NSAffineTransform.inc"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<UsageCount Value="9"/>
</Unit35>
</Units>
<JumpHistory Count="4" HistoryIndex="3">
<JumpHistory Count="2" HistoryIndex="1">
<Position1>
<Filename Value="ObjCParserUtils.pas"/>
<Caret Line="1830" Column="49" TopLine="1823"/>
<Caret Line="1708" Column="49" TopLine="1699"/>
</Position1>
<Position2>
<Filename Value="ObjCParserUtils.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Caret Line="1707" Column="93" TopLine="1694"/>
</Position2>
<Position3>
<Filename Value="ObjCParserUtils.pas"/>
<Caret Line="94" Column="12" TopLine="83"/>
</Position3>
<Position4>
<Filename Value="ObjCParserUtils.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
</Position4>
</JumpHistory>
</ProjectOptions>
<CompilerOptions>
@ -302,22 +78,17 @@
<Generate Value="Faster"/>
</CodeGeneration>
<Other>
<Verbosity>
<ShowNotes Value="False"/>
</Verbosity>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Debugging>
<BreakPoints Count="2">
<Exceptions Count="2">
<Item1>
<Source Value="C:/Games/CodeTest2/Sources/examples/codecompletion.lpr"/>
<Line Value="47"/>
<Name Value="ECodetoolError"/>
</Item1>
<Item2>
<Source Value="../../LazTest4/consolethreads.pas"/>
<Line Value="18"/>
<Name Value="EFOpenError"/>
</Item2>
</BreakPoints>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -32,8 +32,16 @@ type
end;
var
updIni : AnsiString = '';
noConvert : Boolean = false;
updIni : AnsiString = '';
doOutput : Boolean = false;
doparseAll : Boolean = false;
const
TokenReplaceSec = 'TokenReplace';
TypeDefsSec = 'TypeDefs';
TypeReplaceSec = 'TypeReplace';
IgnoreIncludesSec = 'IgnoreIncludes';
CommonSec = 'Common';
function FindMax(const c: array of Integer; len: Integer): Integer;
var
@ -110,16 +118,16 @@ var
i : Integer;
begin
if Entity is TClassDef then begin
Ini.WriteString('TypeDefs', TClassDef(Entity)._ClassName, 'objcclass');
Ini.WriteString(TypeDefsSec, TClassDef(Entity)._ClassName, 'objcclass');
end else if Entity is TStructTypeDef then begin
Ini.WriteString('TypeDefs', TStructTypeDef(Entity)._Name, 'struct');
Ini.WriteString(TypeDefsSec, TStructTypeDef(Entity)._Name, 'struct');
end else if Entity is TTypeNameDef then begin
if Assigned(Sets) then begin
cnv := AnsiLowerCase(ObjCToDelphiType(TTypeNameDef(Entity)._Inherited, false ));
if (cnv = 'float') or (cnv = 'double') then
Ini.WriteString('TypeDefs', TTypeNameDef(Entity)._TypeName, 'float')
Ini.WriteString(TypeDefsSec, TTypeNameDef(Entity)._TypeName, 'float')
else if (cnv = 'Int64') then
Ini.WriteString('TypeDefs', TTypeNameDef(Entity)._TypeName, 'struct')
Ini.WriteString(TypeDefsSec, TTypeNameDef(Entity)._TypeName, 'struct')
end;
end;
@ -204,13 +212,13 @@ var
f : Text;
err : AnsiString;
begin
err := '';
{ err := '';
writeln('would you like to parse all current directory files .h to inc?');
readln(ch);
if (ch <> 'Y') and (ch <> 'y') then begin
writeln('as you wish, bye!');
Exit;
end;
end;}
pth := IncludeTrailingPathDelimiter( GetCurrentDir);
writeln('looking for .h files in ', pth);
@ -227,13 +235,16 @@ begin
incs := pth + Copy(srch.Name,1, length(srch.Name) - length(ExtractFileExt(srch.Name)));
incs := incs + '.inc';
//writeln(incs);
assignfile(f, incs); rewrite(f);
try
for i := 0 to st.Count - 1 do
writeln(f, st[i]);
finally
closefile(f);
if doOutput then begin
assignfile(f, incs); rewrite(f);
try
for i := 0 to st.Count - 1 do
writeln(f, st[i]);
finally
closefile(f);
end;
end;
st.Clear;
writeln(' converted!');
end else begin
@ -293,17 +304,25 @@ var
values : TStringList;
a, b : AnsiString;
i : Integer;
IniName : AnsiString;
begin
// uikit.ini
if not FileExists(FileName) then begin
writeln('//ini file is not found');
Exit;
end;
ini := TIniFile.Create(FileName);
{$ifndef fpc}
if ExtractFileName(FileName) = FileName then
IniName := IncludeTrailingPathDelimiter( GetCurrentDir) + FileName
else
IniName := FileName;
{$else}
IniName := FileName;
{$endif}
ini := TIniFile.Create(IniName);
values := TStringList.Create;
try
values.Clear;
values.Clear;
{ ini.ReadSection('TypeReplace', values);
for i := 0 to values.Count - 1 do begin
a := values.ValueFromIndex[i];
@ -314,22 +333,49 @@ begin
end;}
values.Clear;
a := ini.ReadString(CommonSec, 'mainunit', '');
if a <> '' then begin
b := '{%mainunit '+ a + '}';
for i := 0 to ConvertSettings.ConvertPrefix.Count - 1 do
if Pos(ConvertSettings.ConvertPrefix[i], '{%mainunit') = 1 then begin
ConvertSettings.ConvertPrefix[i] := b;
a := '';
Break;
end;
if a <> '' then
ConvertSettings.ConvertPrefix.Add(b);
end;
a := ini.ReadString(CommonSec, 'ignoreincludes', '');
ini.ReadSection('Common', values);
for i := 0 to values.Count - 1 do begin
if Pos('ignoreincludes', values[i]) = 1 then begin
b := ini.ReadString(CommonSec,values[i], '');
AddSpaceSeparated(b, ConvertSettings.IgnoreIncludes);
end;
end;
{ini.ReadSectionValues(IgnoreIncludesSec, values);
for i := 0 to values.Count - 1 do begin
ConvertSettings.IgnoreIncludes.AddStrings(values);
end;}
//ini.ReadSectionValues('ReplaceToken', values);
ini.ReadSection('ReplaceToken', values);
ini.ReadSection(TokenReplaceSec, values);
for i := 0 to values.Count - 1 do begin
a := Values[i];
b := ini.ReadString('ReplaceToken', a, '');
b := ini.ReadString(TokenReplaceSec, a, '');
if b ='' then
Settings.IgnoreTokens.Add(a);
end;
values.Clear;
ini.ReadSection('TypeDefs', values);
ini.ReadSection(TypeDefsSec, values);
for i := 0 to values.Count - 1 do begin
a := Values[i];
b := AnsiLowerCase(ini.ReadString('TypeDefs', a, ''));
b := AnsiLowerCase(ini.ReadString(TypeDefsSec, a, ''));
if b = 'objcclass' then
Settings.ObjCTypes.Add(a)
Settings.ObjCClassTypes.Add(a)
else if b = 'struct' then
Settings.StructTypes.Add(a)
else if b = 'float' then
@ -337,10 +383,10 @@ begin
end;
values.Clear;
ini.ReadSection('TypeReplace', values);
ini.ReadSection(TypeReplaceSec, values);
for i := 0 to values.Count - 1 do begin
a := Values[i];
b := ini.ReadString('TypeReplace', a, '');
b := ini.ReadString(TypeReplaceSec, a, '');
if isNameofPointer(a) then
Settings.PtrTypeReplace[ Copy(a, 1, length(a) - 1)] := b
else
@ -369,35 +415,40 @@ begin
for i := 1 to ParamCount do begin
if isParamValue(ParamStr(i), prm, vlm) then begin
prm := AnsiLowerCase(prm);
if prm = 'mu' then prm := 'mainunit'
else if prm = 'ii' then prm := 'ignoreinclude';
Params.Values[prm] := vlm;
if prm = 'noout' then doOutput:=false
else if prm = 'all' then doparseAll:=true
else if prm = 'ini' then begin
ReadIniFile(Settings, vlm);
end else
Params.Values[prm] := vlm;
end else
FileName := ParamStr(i);
end;
vlm := Params.Values['ini'];
if vlm <> '' then
ReadIniFile(Settings, vlm);
vlm := Params.Values['mainunit'];
if vlm <> '' then
Settings.ConvertPrefix.Add ('{%mainunit '+vlm+'}');
vlm := Params.Values['ignoreinclude'];
if vlm <> '' then
AddSpaceSeparated(vlm, Settings.IgnoreIncludes);
vlm := Params.Values['updini'];
vlm := Params.Values['uini'];
if vlm <> '' then
updIni := vlm;
finally
Params.Free;
end;
Result := true;
end;
procedure TypeHelp;
begin
writeln('Obj-C parser usage:');
writeln('objcparser [switches] objcheaderfilename');
writeln('');
writeln('keys:');
writeln(' -ini=filename.ini config file to use for pascal file generation');
writeln(' multiple "-ini" switches are allowed');
writeln(' -uini=filename.ini config file to update the data');
writeln(' -noout prevents from .inc files generated');
writeln(' -all parses headers (*.h) in the current directory');
end;
var
inpf : AnsiString = '';
st : TStrings = nil;
@ -406,20 +457,26 @@ var
begin
doOutput := true;
try
GetConvertSettings(ConvertSettings, inpf);
if not FileExists(inpf) then begin
if doParseAll then begin
ParseAll;
Exit;
end else if not FileExists(inpf) then begin
TypeHelp;
Exit;
end;
st := TStringList.Create;
try
if not ReadAndParseFile(inpf, st, err) then
writeln('Error: ', err)
else
for i := 0 to st.Count - 1 do
writeln(st[i]);
else begin
if doOutput then
for i := 0 to st.Count - 1 do
writeln(st[i]);
end;
except
end;
st.Free;