You've already forked lazarus-ccr
chelper: added obj-c properties writting to pascal
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1287 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -22,8 +22,7 @@ program cconvert;
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils,Classes,
|
SysUtils,Classes,
|
||||||
ctopasconvert,cparsertypes,cparserutils,cconvconfig, objcparsing,
|
ctopasconvert,cparsertypes,cparserutils,cconvconfig, objcparsing;
|
||||||
objctopasconvert;
|
|
||||||
|
|
||||||
var
|
var
|
||||||
ConfigFile : AnsiString = '';
|
ConfigFile : AnsiString = '';
|
||||||
|
@ -51,6 +51,7 @@ type
|
|||||||
|
|
||||||
// obj-c
|
// obj-c
|
||||||
RemoveLastUnderscores : Boolean;
|
RemoveLastUnderscores : Boolean;
|
||||||
|
PropsAsMethods : Boolean;
|
||||||
|
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -136,7 +137,7 @@ type
|
|||||||
procedure WriteFuncOrVar(cent: TVarFuncEntity; StartVar, WriteComment: Boolean); // todo: deprecate!
|
procedure WriteFuncOrVar(cent: TVarFuncEntity; StartVar, WriteComment: Boolean); // todo: deprecate!
|
||||||
procedure WriteTypeDef(tp: TTypeDef);
|
procedure WriteTypeDef(tp: TTypeDef);
|
||||||
procedure WriteEnum(en: TEnumType);
|
procedure WriteEnum(en: TEnumType);
|
||||||
procedure WriteEnumAsConst(en: TEnumType);
|
procedure WriteEnumAsConst(en: TEnumType; FinishWithInteger: Boolean=True);
|
||||||
procedure WriteUnion(st: TUnionType);
|
procedure WriteUnion(st: TUnionType);
|
||||||
procedure WriteStruct(st: TStructType);
|
procedure WriteStruct(st: TStructType);
|
||||||
procedure WriteCommentToPas(cent: TComment);
|
procedure WriteCommentToPas(cent: TComment);
|
||||||
@ -145,6 +146,7 @@ type
|
|||||||
|
|
||||||
function GetPasObjCMethodName(names: TStrings): AnsiString;
|
function GetPasObjCMethodName(names: TStrings): AnsiString;
|
||||||
procedure WriteObjCMethod(m: TObjCMethod);
|
procedure WriteObjCMethod(m: TObjCMethod);
|
||||||
|
procedure WriteObjCProperty(p: TObjCProperty);
|
||||||
procedure WriteObjCMethods(list: TList);
|
procedure WriteObjCMethods(list: TList);
|
||||||
procedure WriteObjCInterface(cent: TObjCInterface);
|
procedure WriteObjCInterface(cent: TObjCInterface);
|
||||||
procedure WriteObjCProtocol(cent: TObjCProtocol);
|
procedure WriteObjCProtocol(cent: TObjCProtocol);
|
||||||
@ -633,6 +635,37 @@ begin
|
|||||||
wr.W(''';');
|
wr.W(''';');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCodeConvertor.WriteObjCProperty(p:TObjCProperty);
|
||||||
|
var
|
||||||
|
tp : AnsiString;
|
||||||
|
mtd : AnsiString;
|
||||||
|
nmp : TNamePart;
|
||||||
|
nm : AnsiString;
|
||||||
|
begin
|
||||||
|
//if not Assigned(p.Name) or (p.Name.Kind<>nk_Ident) then Exit;
|
||||||
|
nmp:=GetIdPart(p.Name);
|
||||||
|
if not Assigned(nmp) or (nmp.Id='') then Exit;
|
||||||
|
tp:=GetPasTypeName(p.RetType, nmp.owner);
|
||||||
|
if tp='' then Exit;
|
||||||
|
|
||||||
|
nm:=nmp.Id;
|
||||||
|
if (cfg.PropsAsMethods) then begin
|
||||||
|
|
||||||
|
if p.GetterName='' then mtd:=nmp.Id else mtd:=p.GetterName;
|
||||||
|
wr.W('function '+nm+': '+tp+'; message '''+mtd+''';');
|
||||||
|
|
||||||
|
if p.Props.IndexOf('readonly')<0 then begin
|
||||||
|
wr.Wln;
|
||||||
|
|
||||||
|
nm:='set'+UpperCase(nm[1])+Copy(nm, 2, length(nm)-1);
|
||||||
|
if p.SetterName='' then mtd:=nm+':' else mtd:=p.SetterName;
|
||||||
|
|
||||||
|
wr.W('procedure '+nm+'(AValue: '+tp+'); message '''+mtd+''';');
|
||||||
|
end;
|
||||||
|
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCodeConvertor.WriteObjCMethods(list:TList);
|
procedure TCodeConvertor.WriteObjCMethods(list:TList);
|
||||||
var
|
var
|
||||||
ent : TEntity;
|
ent : TEntity;
|
||||||
@ -644,7 +677,10 @@ begin
|
|||||||
if not Assigned(ent) then Continue;
|
if not Assigned(ent) then Continue;
|
||||||
WriteLnCommentsBeforeOffset(ent.Offset);
|
WriteLnCommentsBeforeOffset(ent.Offset);
|
||||||
if ent is TObjCMethod then
|
if ent is TObjCMethod then
|
||||||
WriteObjCMethod(TObjCMethod(ent));
|
WriteObjCMethod(TObjCMethod(ent))
|
||||||
|
else if ent is TObjCProperty then begin
|
||||||
|
WriteObjCProperty(TObjCProperty(ent));
|
||||||
|
end;
|
||||||
WriteLnCommentForOffset(ent.Offset);
|
WriteLnCommentForOffset(ent.Offset);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -652,7 +688,6 @@ end;
|
|||||||
procedure TCodeConvertor.WriteObjCInterface(cent:TObjCInterface);
|
procedure TCodeConvertor.WriteObjCInterface(cent:TObjCInterface);
|
||||||
var
|
var
|
||||||
i : Integer;
|
i : Integer;
|
||||||
m : TObjCMethod;
|
|
||||||
sc : TObjCScope;
|
sc : TObjCScope;
|
||||||
v : TObjCInstVar;
|
v : TObjCInstVar;
|
||||||
sect : AnsiString;
|
sect : AnsiString;
|
||||||
@ -692,16 +727,10 @@ begin
|
|||||||
if cent.Methods.Count>0 then begin
|
if cent.Methods.Count>0 then begin
|
||||||
wr.Wln('public');
|
wr.Wln('public');
|
||||||
wr.IncIdent;
|
wr.IncIdent;
|
||||||
for i:=0 to cent.Methods.Count-1 do
|
WriteObjCMethods(cent.Methods);
|
||||||
if TObject(cent.Methods[i]) is TObjCMethod then begin
|
|
||||||
m:=TObjCMethod(cent.Methods[i]);
|
|
||||||
WriteLnCommentsBeforeOffset(m.Offset);
|
|
||||||
WriteObjCMethod(m);
|
|
||||||
WriteLnCommentForOffset(m.Offset);
|
|
||||||
end;
|
|
||||||
wr.DecIdent;
|
wr.DecIdent;
|
||||||
wr.Wln('end external;')
|
|
||||||
end;
|
end;
|
||||||
|
wr.Wln('end external;')
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCodeConvertor.WriteObjCProtocol(cent:TObjCProtocol);
|
procedure TCodeConvertor.WriteObjCProtocol(cent:TObjCProtocol);
|
||||||
@ -1026,6 +1055,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCodeConvertor.WriteCtoPas(cent: TEntity; comments: TList; const ParsedText: AnsiString);
|
procedure TCodeConvertor.WriteCtoPas(cent: TEntity; comments: TList; const ParsedText: AnsiString);
|
||||||
|
var
|
||||||
|
tp : AnsiString;
|
||||||
begin
|
begin
|
||||||
CmtList:=comments;
|
CmtList:=comments;
|
||||||
Breaker:=TLineBreaker.Create;
|
Breaker:=TLineBreaker.Create;
|
||||||
@ -1035,9 +1066,17 @@ begin
|
|||||||
WriteFuncOrVar(cent as TVarFuncEntity, True, True)
|
WriteFuncOrVar(cent as TVarFuncEntity, True, True)
|
||||||
end else if cent is TTypeDef then
|
end else if cent is TTypeDef then
|
||||||
WriteTypeDef(cent as TTypeDef)
|
WriteTypeDef(cent as TTypeDef)
|
||||||
else if (cent is TStructType) or (cent is TEnumType) or (cent is TUnionType) then begin
|
else if (cent is TStructType) or (cent is TUnionType) then begin
|
||||||
DeclarePasType(cent, GetComplexTypeName(cent));
|
DeclarePasType(cent, GetComplexTypeName(cent));
|
||||||
wr.Wln(';');
|
wr.Wln(';');
|
||||||
|
end else if (cent is TEnumType) then begin
|
||||||
|
tp:=GetComplexTypeName(cent);
|
||||||
|
if cfg.EnumsAsConst and (tp='') then
|
||||||
|
WriteEnumAsConst(TEnumType(cent), false)
|
||||||
|
else begin
|
||||||
|
DeclarePasType(TEnumType(cent), GetComplexTypeName(cent));
|
||||||
|
wr.Wln(';');
|
||||||
|
end;
|
||||||
end else if cent is TComment then
|
end else if cent is TComment then
|
||||||
WriteCommentToPas(cent as TComment)
|
WriteCommentToPas(cent as TComment)
|
||||||
else if cent is TCPrepDefine then
|
else if cent is TCPrepDefine then
|
||||||
@ -1212,7 +1251,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCodeConvertor.WriteEnumAsConst(en:TEnumType);
|
procedure TCodeConvertor.WriteEnumAsConst(en:TEnumType; FinishWithInteger: Boolean);
|
||||||
var
|
var
|
||||||
i : Integer;
|
i : Integer;
|
||||||
v : Int64;
|
v : Int64;
|
||||||
@ -1247,7 +1286,7 @@ begin
|
|||||||
|
|
||||||
PopWriter;
|
PopWriter;
|
||||||
end;
|
end;
|
||||||
wr.W('Integer');
|
if FinishWithInteger then wr.W('Integer');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCodeConvertor.WriteUnion(st:TUnionType);
|
procedure TCodeConvertor.WriteUnion(st:TUnionType);
|
||||||
@ -1523,6 +1562,9 @@ begin
|
|||||||
CtoPasTypes.Values['signed long'] := 'Integer';
|
CtoPasTypes.Values['signed long'] := 'Integer';
|
||||||
CtoPasTypes.Values['...'] := 'array of const';
|
CtoPasTypes.Values['...'] := 'array of const';
|
||||||
CtoPasTypes.Values['va_list'] := 'array of const';
|
CtoPasTypes.Values['va_list'] := 'array of const';
|
||||||
|
|
||||||
|
// obj-c
|
||||||
|
PropsAsMethods:=True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TConvertSettings.Destroy;
|
destructor TConvertSettings.Destroy;
|
||||||
|
@ -533,7 +533,7 @@ begin
|
|||||||
if s='setter' then p.SetterName:=nm
|
if s='setter' then p.SetterName:=nm
|
||||||
else p.GetterName:=nm;
|
else p.GetterName:=nm;
|
||||||
end else begin
|
end else begin
|
||||||
p.Props.Add(nm);
|
if APArser.TokenType=tt_Ident then p.Props.Add(AParser.Token);
|
||||||
AParser.NextToken;
|
AParser.NextToken;
|
||||||
end;
|
end;
|
||||||
if AParser.Token=',' then AParser.NextToken;
|
if AParser.Token=',' then AParser.NextToken;
|
||||||
@ -546,7 +546,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
if ParseName(AParser, p.RetType, p.Name) then begin
|
if ParseName(AParser, p.RetType, p.Name) then begin
|
||||||
Result:=p;
|
Result:=p;
|
||||||
if APArser.Token=';' then AParser.NextToken;
|
if AParser.Token=';' then AParser.NextToken;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user