mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 17:09:21 +02:00
carbon: removed objcparser from pascocoa
git-svn-id: trunk@24107 -
This commit is contained in:
parent
6a78f28957
commit
f1812c07c0
9
.gitattributes
vendored
9
.gitattributes
vendored
@ -4557,15 +4557,6 @@ lcl/interfaces/carbon/pascocoa/foundation/NSString.inc svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/foundation/NSValue.inc svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/foundation/NSZone.inc svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/foundation/foundation.pas svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/parser/ObjCParserTypes.pas svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/parser/ObjCParserUtils.pas svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/parser/ObjCTemplate.pas svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/parser/ObjCToPas.pas svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/parser/default.ini svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/parser/gnuccFeatures.pas svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/parser/objcparser.lpi svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/parser/objcparser.pas svneol=native#text/plain
|
||||
lcl/interfaces/carbon/pascocoa/parser/testparser.sh svneol=native#text/plain
|
||||
lcl/interfaces/cocoa/Makefile svneol=native#text/plain
|
||||
lcl/interfaces/cocoa/Makefile.fpc svneol=native#text/plain
|
||||
lcl/interfaces/cocoa/cocoaint.pas svneol=native#text/plain
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,242 +0,0 @@
|
||||
unit ObjCTemplate;
|
||||
|
||||
interface
|
||||
|
||||
{$ifdef fpc}{$mode delphi}{$h+}{$endif}
|
||||
|
||||
uses
|
||||
Classes, SysUtils, ObjCParserTypes, ObjCParserUtils;
|
||||
|
||||
type
|
||||
TTemplateList = class(TObject)
|
||||
public
|
||||
Params : TStringList;
|
||||
SubLists : TList;
|
||||
Owner : TTemplateList;
|
||||
Name : AnsiString;
|
||||
constructor Create(AOwner: TTemplateList);
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
TTemplateValues = class(TObject)
|
||||
public
|
||||
procedure ProcSpecial(const Special: AnsiString; var ReplaceText: AnsiString); virtual;
|
||||
end;
|
||||
|
||||
TTemplateProc = class(TObject)
|
||||
private
|
||||
fTemplate : AnsiString;
|
||||
|
||||
fRoot : TTemplateList;
|
||||
fStack : TList;
|
||||
|
||||
fValues : TTemplateValues;
|
||||
fText : AnsiString;
|
||||
|
||||
protected
|
||||
function CurrentList: TTEmplateList;
|
||||
|
||||
function GetReplace(const tmp: AnsiString; var AtIndex: Integer): AnsiString;
|
||||
function ParseNextProc(var Proc: AnsiString; var idx: Integer): AnsiString;
|
||||
|
||||
procedure DoParse(var idx: Integer; const EndTmp: AnsiString);
|
||||
public
|
||||
function Parse(const Template: AnsiString; RootList: TTemplateList; AValues: TTemplateValues): AnsiString;
|
||||
end;
|
||||
|
||||
|
||||
TPascalValues = class(TTemplateValues)
|
||||
private
|
||||
fEndsCount : Integer;
|
||||
|
||||
ClassEnd : Boolean;
|
||||
ClassSection : AnsiString;
|
||||
public
|
||||
procedure ProcSpecial(const Special: AnsiString; var ReplaceText: AnsiString); override;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
const
|
||||
PreProcChar : AnsiChar = '%';
|
||||
PreProcMark : TCharSet = ['%'];
|
||||
|
||||
function GetTmpParam(const temp: AnsiString; var i: Integer): AnsiString;
|
||||
begin
|
||||
ScanWhile(temp, i, [#13, #10, #32, #9]);
|
||||
Result := ScanTo(temp, i, [#32, #9, #13, #10]);
|
||||
end;
|
||||
|
||||
{ TTemplate }
|
||||
|
||||
function TTemplateProc.CurrentList: TTemplateList;
|
||||
begin
|
||||
Result := TTemplateList(fStack[fStack.Count-1])
|
||||
end;
|
||||
|
||||
procedure TTemplateProc.DoParse(var idx: Integer; const EndTmp: AnsiString);
|
||||
var
|
||||
prc : AnsiString;
|
||||
isValue : Boolean;
|
||||
t : AnsiString;
|
||||
begin
|
||||
while idx <= length(fTemplate) do begin
|
||||
fText := fText + ParseNextProc(prc, idx);
|
||||
isValue := false;
|
||||
if (EndTmp <> '') and (prc = EndTmp) then Exit;
|
||||
if prc = '' then Continue;
|
||||
|
||||
if prc[1] = '_' then begin
|
||||
prc := Copy(prc, 2, length(prc)-1);
|
||||
isValue := true;
|
||||
end;
|
||||
if prc = '' then Continue;
|
||||
|
||||
if isValue then begin
|
||||
if Assigned(fValues) then begin
|
||||
fValues.ProcSpecial(AnsiLowerCase(prc), t);
|
||||
fText := fText + t
|
||||
end;
|
||||
end else begin
|
||||
//inc(idx);
|
||||
fText := fText + GetReplace(AnsiLowerCase(prc), idx);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TTemplateProc.GetReplace(const tmp: AnsiString; var AtIndex: Integer): AnsiString;
|
||||
var
|
||||
i : Integer;
|
||||
nm : AnsiString;
|
||||
j : Integer;
|
||||
l : TTemplateList;
|
||||
ExitIndex:Integer;
|
||||
idx : Integer;
|
||||
begin
|
||||
Result := '';
|
||||
i := 1;
|
||||
if AnsiLowerCase(GetTmpParam(tmp, i)) = 'foreach' then begin
|
||||
nm := GetTmpParam(tmp, i);
|
||||
ExitIndex := AtIndex;
|
||||
for j := 0 to CurrentList.SubLists.Count - 1 do begin
|
||||
l := TTemplateList(CurrentList.SubLists[j]);
|
||||
idx := AtIndex;
|
||||
if l.Name = nm then begin
|
||||
fStack.Add(l);
|
||||
DoParse(idx, 'end');
|
||||
fStack.Delete(fStack.Count-1);
|
||||
ExitIndex := idx;
|
||||
end;
|
||||
end;
|
||||
AtIndex := ExitIndex;
|
||||
end else begin
|
||||
Result := CurrentList.Params.Values[tmp];
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
function TTemplateProc.Parse(const Template: String;
|
||||
RootList: TTemplateList; AValues: TTemplateValues): AnsiString;
|
||||
var
|
||||
i : integer;
|
||||
begin
|
||||
fTemplate := Template;
|
||||
fRoot := RootList;
|
||||
fValues := AValues;
|
||||
|
||||
fStack := TList.Create;
|
||||
try
|
||||
i := 1;
|
||||
fStack.Add(RootList);
|
||||
DoParse(i, '');
|
||||
finally
|
||||
fStack.Free;
|
||||
end;
|
||||
|
||||
Result := fText;
|
||||
end;
|
||||
|
||||
function TTemplateProc.ParseNextProc(var Proc: string; var idx: Integer): AnsiString;
|
||||
var
|
||||
canQuit : Boolean;
|
||||
begin
|
||||
canQuit := false; // just don't like: repeat until false;
|
||||
Result := '';
|
||||
repeat
|
||||
Result := Result + ScanTo(fTemplate, idx, PreProcMark);
|
||||
|
||||
if idx > length(fTemplate) then begin
|
||||
Proc := '';
|
||||
canQuit := true;
|
||||
end else begin
|
||||
if (idx < length(fTemplate)) and (fTemplate[idx+1] = PreProcChar) then begin
|
||||
Result := Result + PreProcChar;
|
||||
inc(idx,2);
|
||||
end else begin
|
||||
inc(idx);
|
||||
Proc := ScanTo(fTemplate, idx, PreProcMark);
|
||||
CanQuit := true;
|
||||
inc(idx);
|
||||
end;
|
||||
end;
|
||||
until canQuit;
|
||||
|
||||
end;
|
||||
|
||||
{ TTemplateList }
|
||||
|
||||
constructor TTemplateList.Create(AOwner: TTemplateList);
|
||||
begin
|
||||
Owner := AOwner;
|
||||
SubLists := TList.Create;
|
||||
Params := TStringList.Create;
|
||||
end;
|
||||
|
||||
destructor TTemplateList.Destroy;
|
||||
begin
|
||||
SubLists.Free;
|
||||
Params.Free;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
{ TPascalValues }
|
||||
|
||||
procedure TPascalValues.ProcSpecial(const Special: AnsiString;
|
||||
var ReplaceText: AnsiString);
|
||||
begin
|
||||
ReplaceText := '';
|
||||
|
||||
if (Special = 'pasprivate') or (Special = 'pasprotected') or (Special = 'paspublic') then begin
|
||||
|
||||
if ClassSection = '' then begin
|
||||
ClassEnd := true;
|
||||
inc(fEndsCount);
|
||||
end;
|
||||
|
||||
if ClassSection <> Special then
|
||||
ReplaceText := Copy(Special, 4, length(Special) - 3); //removed 'pas' prefix
|
||||
ClassSection := Special;
|
||||
|
||||
end else if (Special = 'pasend') or (Special = 'pasend.') or (Special = 'pasend;')then begin
|
||||
if fEndsCount > 0 then begin
|
||||
ReplaceText := Copy(Special, 4, length(Special) - 3); //removed 'pas' prefix
|
||||
dec(fEndsCount);
|
||||
if classEnd then begin
|
||||
classEnd := false;
|
||||
ClassSection := '';
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
{ TTemplateValues }
|
||||
|
||||
procedure TTemplateValues.ProcSpecial(const Special: AnsiString;
|
||||
var ReplaceText: AnsiString);
|
||||
begin
|
||||
ReplaceText := '';
|
||||
end;
|
||||
|
||||
end.
|
@ -1,95 +0,0 @@
|
||||
unit ObjCToPas;
|
||||
{ * This file is part of ObjCParser tool
|
||||
* Copyright (C) 2008-2009 by Dmitry Boyarintsev under the GNU LGPL
|
||||
* license version 2.0 or 2.1. You should have received a copy of the
|
||||
* LGPL license along with at http://www.gnu.org/
|
||||
}
|
||||
// the unit contains (should contain) lobjc to Pascal convertion utility routines
|
||||
// todo: move all ObjCParserUtils functions here.
|
||||
|
||||
interface
|
||||
|
||||
{$ifdef fpc}{$mode delphi}{$h+}{$endif}
|
||||
|
||||
uses
|
||||
SysUtils, ObjCParserTypes;
|
||||
|
||||
const
|
||||
ObjCDefaultParamDelim = '_';
|
||||
|
||||
|
||||
type
|
||||
TCProcessor = class(TObject)
|
||||
public
|
||||
procedure ProcessTree(Root: TEntity); virtual; abstract;
|
||||
end;
|
||||
|
||||
function ObjCToPasMethodName(mtd: TClassMethodDef; CutLastDelims: Boolean = false; ParamDelim: AnsiChar = ObjCDefaultParamDelim): AnsiString;
|
||||
function IsPascalReserved(const s: AnsiString): Boolean;
|
||||
|
||||
implementation
|
||||
|
||||
function ObjCToPasMethodName(mtd: TClassMethodDef; CutLastDelims: Boolean; ParamDelim: AnsiChar): AnsiString;
|
||||
var
|
||||
i : Integer;
|
||||
obj : TObject;
|
||||
begin
|
||||
Result := mtd._Name;
|
||||
for i := 0 to mtd.Items.Count - 1 do begin
|
||||
obj := mtd.Items[i];
|
||||
if not Assigned(obj) then Continue;
|
||||
if obj is TParamDescr then begin
|
||||
Result := Result + TParamDescr(obj)._Descr;
|
||||
end else if obj is TObjCParameterDef then
|
||||
Result := Result + ParamDelim;
|
||||
end;
|
||||
|
||||
if CutLastDelims then begin
|
||||
i := length(Result);
|
||||
while (i > 0) and (Result[i] = ParamDelim) do dec(i);
|
||||
Result := Copy(Result, 1, i);
|
||||
end;
|
||||
end;
|
||||
|
||||
// 'result' is considered reserved word!
|
||||
function IsPascalReserved(const s: AnsiString): Boolean;
|
||||
var
|
||||
ls : AnsiString;
|
||||
begin
|
||||
//todo: a hash table should be used!
|
||||
Result := false;
|
||||
if s = '' then Exit;
|
||||
ls := AnsiLowerCase(s);
|
||||
case ls[1] of
|
||||
'a': Result := (ls = 'absolute') or (ls = 'abstract') or (ls = 'and') or (ls = 'array') or (ls = 'as') or (ls= 'asm') or (ls = 'assembler');
|
||||
'b': Result := (ls = 'begin') or (ls = 'break');
|
||||
'c': Result := (ls = 'cdecl') or (ls = 'class') or (ls = 'const') or (ls = 'constructor') or (ls = 'continue') or (ls = 'cppclass');
|
||||
'd': Result := (ls = 'deprecated') or (ls = 'destructor') or (ls = 'div') or (ls = 'do') or (ls = 'downto');
|
||||
'e': Result := (ls = 'else') or (ls = 'end') or (ls = 'except') or (ls = 'exit') or (ls = 'export') or (ls = 'exports') or (ls = 'external');
|
||||
'f': Result := (ls = 'fail') or (ls = 'false') or (ls = 'far') or (ls = 'file') or (ls = 'finally') or (ls = 'for') or (ls = 'forward') or (ls = 'function');
|
||||
'g': Result := (ls = 'goto');
|
||||
'i':
|
||||
Result := (ls = 'if') or (ls = 'implementation') or (ls = 'in') or (ls = 'index') or (ls = 'inherited') or (ls = 'initialization') or (ls = 'inline')
|
||||
or (ls = 'interface') or (ls = 'interrupt') or (ls = 'is');
|
||||
'l': Result := (ls = 'label') or (ls = 'library');
|
||||
'm': Result := (ls = 'mod');
|
||||
'n': Result := {(ls = 'name') or} (ls = 'near') or (ls = 'nil') or (ls = 'not');
|
||||
'o': Result := (ls = 'object') or (ls = 'of') or (ls = 'on') or (ls = 'operator') or (ls = 'or') or (ls = 'otherwise');
|
||||
'p':
|
||||
Result := (ls = 'packed') or (ls = 'popstack') or (ls = 'private') or (ls = 'procedure') or (ls = 'program') or (ls = 'property')
|
||||
or (ls = 'protected') or (ls = 'public');
|
||||
'r': Result := (ls = 'raise') or (ls = 'record') or (ls = 'reintroduce') or (ls = 'repeat') or (ls = 'result');
|
||||
's': Result := (ls = 'self') or (ls = 'set') or (ls = 'shl') or (ls = 'shr') or (ls = 'stdcall') or (ls = 'string');
|
||||
't': Result := (ls = 'then') or (ls = 'to') or (ls = 'true') or (ls = 'try') or (ls = 'type');
|
||||
'u': Result := (ls = 'unimplemented') or (ls = 'unit') or (ls = 'until') or (ls = 'uses');
|
||||
'v': Result := (ls = 'var') or (ls = 'virtual');
|
||||
'w': Result := (ls = 'while') or (ls = 'with');
|
||||
'x': Result := (ls = 'xor');
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end.
|
@ -1,270 +0,0 @@
|
||||
[common]
|
||||
ignoreincludes0=CoreFoundation/
|
||||
ignoreincludes1=stdint.h 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
|
||||
NSCharacterSet=CFCharacterSetRef
|
||||
NSCharacterSet*=CFCharacterSetRef
|
||||
NSData=CFDataRef
|
||||
NSData*=CFDataRef
|
||||
NSDate=CFDateRef
|
||||
NSDate*=CFDateRef
|
||||
NSDictionary=CFDictionaryRef
|
||||
NSDictionary*=CFDictionaryRef
|
||||
NSMutableArray=CFMutableArrayRef
|
||||
NSMutableArray*=CFMutableArrayRef
|
||||
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
|
||||
NSRect=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]
|
||||
APPKIT_EXTERN=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED=
|
||||
DEPRECATED_IN_MAC_OS_X_VERSION_10_0_AND_LATER=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_1=
|
||||
DEPRECATED_IN_MAC_OS_X_VERSION_10_1_AND_LATER=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_2=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_2=
|
||||
DEPRECATED_IN_MAC_OS_X_VERSION_10_2_AND_LATER=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER_BUT_DEPRECATED=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3=
|
||||
DEPRECATED_IN_MAC_OS_X_VERSION_10_3_AND_LATER=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER_BUT_DEPRECATED=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4=
|
||||
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_5_AND_LATER_BUT_DEPRECATED=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5=
|
||||
AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5=
|
||||
DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER=
|
@ -1,70 +0,0 @@
|
||||
{ * This file is part of ObjCParser tool
|
||||
* Copyright (C) 2008-2009 by Dmitry Boyarintsev under the GNU LGPL
|
||||
* license version 2.0 or 2.1. You should have received a copy of the
|
||||
* LGPL license along with at http://www.gnu.org/
|
||||
}
|
||||
|
||||
unit gnuccFeatures;
|
||||
|
||||
{list of GNU CC features, that might be found at header files
|
||||
it's extermly possible that these language and precomipler features
|
||||
are not to be compatible with MS C/C++ header files }
|
||||
|
||||
interface
|
||||
|
||||
{$ifdef fpc}{$mode delphi}{$h+}{$endif}
|
||||
|
||||
uses
|
||||
ObjCParserTypes;
|
||||
|
||||
type
|
||||
TAttribute = class(TEntity)
|
||||
protected
|
||||
function DoParse(AParser: TTextParser): Boolean; override;
|
||||
public
|
||||
Expression : AnsiString;
|
||||
end;
|
||||
|
||||
function ParseAttribute(Parent: TEntity; Parser: TTextParser): TEntity;
|
||||
|
||||
implementation
|
||||
|
||||
function ParseAttribute(Parent: TEntity; Parser: TTextParser): TEntity;
|
||||
var
|
||||
attr : TAttribute;
|
||||
begin
|
||||
attr := TAttribute.Create(nil);
|
||||
try
|
||||
if attr.Parse(Parser) then begin
|
||||
Parent.Items.Add(attr);
|
||||
attr.owner := Parent;
|
||||
Result:=attr;
|
||||
end else begin
|
||||
attr.Free;
|
||||
Result := nil;
|
||||
end;
|
||||
finally
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TAttribute }
|
||||
|
||||
function TAttribute.DoParse(AParser: TTextParser): Boolean;
|
||||
var
|
||||
s : string;
|
||||
tt : TTokenType;
|
||||
begin
|
||||
Result := AParser.FindNextToken(s, tt);
|
||||
|
||||
if not Result or (s <> '__attribute__') then begin
|
||||
Result := false;
|
||||
Exit;
|
||||
end;
|
||||
Expression := ParseSeq(AParser, '(', ')');
|
||||
Result := true;
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterEntity( @ParseAttribute);
|
||||
|
||||
end.
|
@ -1,212 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<PathDelim Value="\"/>
|
||||
<Version Value="7"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasUsesSectionForAllUnits Value="False"/>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<LRSInOutputDirectory Value="False"/>
|
||||
</Flags>
|
||||
<MainUnit Value="0"/>
|
||||
<TargetFileExt Value=""/>
|
||||
<ActiveEditorIndexAtStart Value="2"/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<ProjectVersion Value=""/>
|
||||
<Language Value=""/>
|
||||
<CharSet Value=""/>
|
||||
</VersionInfo>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<Units Count="4">
|
||||
<Unit0>
|
||||
<Filename Value="objcparser.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="objcparser"/>
|
||||
<CursorPos X="29" Y="24"/>
|
||||
<TopLine Value="10"/>
|
||||
<EditorIndex Value="0"/>
|
||||
<UsageCount Value="26"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<UnitName Value="ObjCParserUtils"/>
|
||||
<CursorPos X="37" Y="888"/>
|
||||
<TopLine Value="880"/>
|
||||
<EditorIndex Value="2"/>
|
||||
<UsageCount Value="13"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="ObjCParserTypes.pas"/>
|
||||
<UnitName Value="ObjCParserTypes"/>
|
||||
<CursorPos X="18" Y="503"/>
|
||||
<TopLine Value="503"/>
|
||||
<EditorIndex Value="3"/>
|
||||
<UsageCount Value="13"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<Filename Value="gnuccFeatures.pas"/>
|
||||
<UnitName Value="gnuccFeatures"/>
|
||||
<CursorPos X="1" Y="1"/>
|
||||
<TopLine Value="1"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit3>
|
||||
</Units>
|
||||
<JumpHistory Count="30" HistoryIndex="29">
|
||||
<Position1>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="1834" Column="30" TopLine="1824"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="7" Column="1" TopLine="1"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="1171" Column="8" TopLine="1139"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="1" Column="1" TopLine="1"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="144" Column="138" TopLine="128"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="ObjCParserTypes.pas"/>
|
||||
<Caret Line="293" Column="14" TopLine="283"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="ObjCParserTypes.pas"/>
|
||||
<Caret Line="1" Column="1" TopLine="1"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="ObjCParserTypes.pas"/>
|
||||
<Caret Line="284" Column="9" TopLine="274"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="ObjCParserTypes.pas"/>
|
||||
<Caret Line="1" Column="1" TopLine="1"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="ObjCParserTypes.pas"/>
|
||||
<Caret Line="284" Column="9" TopLine="274"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="ObjCParserTypes.pas"/>
|
||||
<Caret Line="285" Column="9" TopLine="274"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="objcparser.pas"/>
|
||||
<Caret Line="17" Column="18" TopLine="1"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="1754" Column="3" TopLine="1751"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="ObjCParserTypes.pas"/>
|
||||
<Caret Line="422" Column="12" TopLine="412"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="ObjCParserTypes.pas"/>
|
||||
<Caret Line="5" Column="18" TopLine="1"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="ObjCParserTypes.pas"/>
|
||||
<Caret Line="16" Column="1" TopLine="11"/>
|
||||
</Position16>
|
||||
<Position17>
|
||||
<Filename Value="ObjCParserTypes.pas"/>
|
||||
<Caret Line="117" Column="29" TopLine="107"/>
|
||||
</Position17>
|
||||
<Position18>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="54" Column="34" TopLine="46"/>
|
||||
</Position18>
|
||||
<Position19>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="124" Column="5" TopLine="93"/>
|
||||
</Position19>
|
||||
<Position20>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="1" Column="1" TopLine="1"/>
|
||||
</Position20>
|
||||
<Position21>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="159" Column="143" TopLine="143"/>
|
||||
</Position21>
|
||||
<Position22>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="838" Column="36" TopLine="822"/>
|
||||
</Position22>
|
||||
<Position23>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="880" Column="51" TopLine="872"/>
|
||||
</Position23>
|
||||
<Position24>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="1" Column="1" TopLine="1"/>
|
||||
</Position24>
|
||||
<Position25>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="151" Column="1" TopLine="143"/>
|
||||
</Position25>
|
||||
<Position26>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="159" Column="143" TopLine="143"/>
|
||||
</Position26>
|
||||
<Position27>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="838" Column="36" TopLine="822"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="888" Column="26" TopLine="872"/>
|
||||
</Position28>
|
||||
<Position29>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="1" Column="1" TopLine="1"/>
|
||||
</Position29>
|
||||
<Position30>
|
||||
<Filename Value="ObjCParserUtils.pas"/>
|
||||
<Caret Line="159" Column="143" TopLine="143"/>
|
||||
</Position30>
|
||||
</JumpHistory>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="8"/>
|
||||
<Other>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="2">
|
||||
<Item1>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item2>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
@ -1,611 +0,0 @@
|
||||
{ * This file is part of ObjCParser tool
|
||||
* Copyright (C) 2008-2009 by Dmitry Boyarintsev under the GNU LGPL
|
||||
* license version 2.0 or 2.1. You should have received a copy of the
|
||||
* LGPL license along with at http://www.gnu.org/
|
||||
}
|
||||
|
||||
program objcparser;
|
||||
|
||||
{$ifdef fpc}
|
||||
{$mode delphi}{$H+}
|
||||
{$else}
|
||||
{$APPTYPE CONSOLE}
|
||||
{$warn unsafe_code off}
|
||||
{$warn unsafe_type off}
|
||||
{$warn unsafe_cast off}
|
||||
{$endif}
|
||||
|
||||
uses
|
||||
Classes,
|
||||
IniFiles,
|
||||
SysUtils,
|
||||
ObjCParserUtils,
|
||||
ObjCParserTypes,
|
||||
ObjCTemplate,
|
||||
gnuccFeatures;
|
||||
|
||||
type
|
||||
// this object is used only for precomile directives handling
|
||||
|
||||
{ TPrecompileHandler }
|
||||
TPrecompileHandler = class(TObject)
|
||||
public
|
||||
hdr : TObjCHeader;
|
||||
procedure OnPrecompile(Sender: TObject; Precomp: TObject);
|
||||
procedure OnComment(Sender: TObject; const Comment: AnsiString);
|
||||
constructor Create(AHeader: TObjCHeader);
|
||||
end;
|
||||
|
||||
var
|
||||
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
|
||||
i : integer;
|
||||
mn : Integer;
|
||||
begin
|
||||
Result := -1;
|
||||
if len = 0 then Exit;
|
||||
|
||||
mn := 0;
|
||||
for i := 1 to len - 1 do begin
|
||||
if c[i] < c[mn] then mn := i;
|
||||
end;
|
||||
Result := mn;
|
||||
end;
|
||||
|
||||
procedure TPrecompileHandler.OnPrecompile(Sender: TObject; Precomp: TObject);
|
||||
var
|
||||
parser : TTextParser;
|
||||
preEntity : TPrecompiler;
|
||||
lst : TEntity;
|
||||
prc : TPrecompilerEvent;
|
||||
begin
|
||||
parser := Sender as TTextParser;
|
||||
//todo: change for something nicier =)
|
||||
prc := parser.OnPrecompile;
|
||||
parser.OnPrecompile := nil;
|
||||
try
|
||||
if parser.Stack.Count > 0 then
|
||||
lst := TEntity(parser.Stack[parser.Stack.Count-1])
|
||||
else
|
||||
lst := nil;
|
||||
|
||||
preEntity := TPrecompiler.Create(lst);
|
||||
preEntity.Parse(parser);
|
||||
lst.Items.Add(preEntity);
|
||||
finally
|
||||
parser.OnPrecompile := prc;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TPrecompileHandler.OnComment(Sender: TObject; const Comment: AnsiString);
|
||||
var
|
||||
parser : TTextParser;
|
||||
cmt : TComment;
|
||||
ent : TEntity;
|
||||
begin
|
||||
if length(Comment) < 2 then Exit;
|
||||
parser := TTextParser(Sender);
|
||||
|
||||
if parser.Stack.Count > 0
|
||||
then ent := TEntity(parser.Stack[parser.Stack.Count-1])
|
||||
else ent := nil;
|
||||
|
||||
if not Assigned(ent) then Exit;
|
||||
cmt := TComment.Create(ent);
|
||||
cmt._Comment := Comment;
|
||||
if IsSubStr('/*', cmt._Comment, 1) then begin
|
||||
cmt._Comment[1] := '(';
|
||||
if isSubStr('*/', cmt._Comment, length(cmt._Comment) - 1) then
|
||||
cmt._Comment[ length(cmt._Comment)] := ')';
|
||||
end;
|
||||
ent.Items.Add(cmt);
|
||||
end;
|
||||
|
||||
constructor TPrecompileHandler.Create(AHeader: TObjCHeader);
|
||||
begin
|
||||
hdr := AHeader;
|
||||
end;
|
||||
|
||||
procedure UpdateIniWithEntity(Sets: TConvertSettings; Ini: TIniFile; Entity: TEntity);
|
||||
var
|
||||
cnv : AnsiString;
|
||||
i : Integer;
|
||||
begin
|
||||
if Entity is TClassDef then begin
|
||||
Ini.WriteString(TypeDefsSec, TClassDef(Entity)._ClassName, 'objcclass');
|
||||
end else if Entity is TEntityStruct then begin
|
||||
Ini.WriteString(TypeDefsSec, TEntityStruct(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(TypeDefsSec, TTypeNameDef(Entity)._TypeName, 'float')
|
||||
else if (cnv = 'Int64') then
|
||||
Ini.WriteString(TypeDefsSec, TTypeNameDef(Entity)._TypeName, 'struct')
|
||||
end;
|
||||
end;
|
||||
|
||||
for i := 0 to Entity.Items.Count - 1 do
|
||||
UpdateIniWithEntity(Sets, Ini, Entity.Items[i]);
|
||||
end;
|
||||
|
||||
function ReadAndParseFile(const FileName: AnsiString; outdata: TStrings; var Err: AnsiString): Boolean;
|
||||
var
|
||||
hdr : TObjCHeader;
|
||||
parser : TTextParser;
|
||||
prec : TPrecompileHandler ;
|
||||
s : AnsiString;
|
||||
i, cnt : integer;
|
||||
upini : TIniFile;
|
||||
|
||||
repl : TStringList;
|
||||
begin
|
||||
Result :=false;
|
||||
if not FileExists(FileName) then begin
|
||||
Err := 'File not found: ' + FileName;
|
||||
Exit;
|
||||
end;
|
||||
|
||||
s := StrFromFile(FileName);
|
||||
hdr := TObjCHeader.Create;
|
||||
prec := TPrecompileHandler.Create(hdr);
|
||||
parser := CreateCParser(s, true);
|
||||
try
|
||||
repl := TStringList.Create;
|
||||
ConvertSettings.TokenReplace.GetReplaces(repl);
|
||||
for i := 0 to repl.Count - 1 do begin
|
||||
TCMacroHandler(parser.MacroHandler).AddSimpleMacro(repl.Names[i], repl.ValueFromIndex[i]);
|
||||
end;
|
||||
parser.Buf := s;
|
||||
try
|
||||
parser.UsePrecompileEntities := false;
|
||||
parser.UseCommentEntities := false;
|
||||
parser.OnPrecompile := prec.OnPrecompile;
|
||||
parser.OnComment := prec.OnComment;
|
||||
|
||||
{for i := 0 to repl.Count - 1 do begin
|
||||
TCMacroHandler(parser.MacroHandler).AddSimpleMacro(
|
||||
ConvertSettings.IgnoreTokens[i], '');
|
||||
//parser.IgnoreTokens.AddStrings(ConvertSettings.IgnoreTokens);
|
||||
end;}
|
||||
|
||||
hdr._FileName := ExtractFileName(FileName);
|
||||
Result := hdr.Parse(parser);
|
||||
if not Result then begin
|
||||
if parser.Errors.Count > 0 then Err := parser.Errors[0]
|
||||
else Err := 'undesribed error';
|
||||
|
||||
Err := Err + #13#10;
|
||||
cnt := 120;
|
||||
i := parser.Index - cnt;
|
||||
if i <= 0 then begin
|
||||
i := 1;
|
||||
cnt := parser.Index;
|
||||
end;
|
||||
Err := Err + Copy(parser.Buf, i, cnt);
|
||||
end;
|
||||
|
||||
except
|
||||
end;
|
||||
|
||||
if updIni <> '' then begin
|
||||
upIni := TIniFile.Create(updIni);
|
||||
try
|
||||
UpdateIniWithEntity(ConvertSettings, upIni, hdr);
|
||||
finally
|
||||
upIni.Free;
|
||||
end;
|
||||
end;
|
||||
WriteOutIncludeFile(hdr, outdata);
|
||||
finally
|
||||
parser.TokenTable.Free;
|
||||
parser.Free;
|
||||
prec.Free;
|
||||
//FreeEntity(hdr);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure ParseAll;
|
||||
var
|
||||
// ch : char;
|
||||
srch : TSearchRec;
|
||||
res : Integer;
|
||||
i : Integer;
|
||||
pth : AnsiString;
|
||||
incs : AnsiString;
|
||||
st : TStringList;
|
||||
f : Text;
|
||||
err : AnsiString;
|
||||
begin
|
||||
{ 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;}
|
||||
|
||||
pth := IncludeTrailingPathDelimiter( GetCurrentDir);
|
||||
res := FindFirst(pth + '*.h', -1, srch);
|
||||
if res = 0 then begin
|
||||
st := TStringList.Create;
|
||||
try
|
||||
repeat
|
||||
write('found: ', srch.Name);
|
||||
write(' parsing...');
|
||||
//writeln('parsing: ', pth+srch.Name);
|
||||
if ReadAndParseFile(pth+srch.Name, st, err) then begin
|
||||
write(' parsed ');
|
||||
incs := pth + Copy(srch.Name,1, length(srch.Name) - length(ExtractFileExt(srch.Name)));
|
||||
incs := incs + '.inc';
|
||||
//writeln(incs);
|
||||
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;
|
||||
end else begin
|
||||
end;
|
||||
until FindNext(srch) <> 0;
|
||||
|
||||
finally
|
||||
FindClose(srch);
|
||||
st.Free;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
const
|
||||
ParamKey = '-';
|
||||
|
||||
function isParamValue(const s: AnsiString; var ParName, ParValue: AnsiString): Boolean;
|
||||
var
|
||||
i : Integer;
|
||||
begin
|
||||
Result := false;
|
||||
if s = '' then Exit;
|
||||
Result := (s[1] = ParamKey);
|
||||
if not Result then Exit;
|
||||
i := 1;
|
||||
ScanWhile(s, i, [ParamKey]);
|
||||
ParName := ScanTo(s, i, [#32, #9, '=']);
|
||||
ScanWhile(s, i, [#32, #9, '=']);
|
||||
ParValue := Copy(s, i, length(s) - i + 1);
|
||||
end;
|
||||
|
||||
procedure AddSpaceSeparated(const s: AnsiString; Strings: TStringList);
|
||||
var
|
||||
i : Integer;
|
||||
ns : AnsiString;
|
||||
begin
|
||||
i := 1;
|
||||
while i <= length(s) do begin
|
||||
ScanTo(s, i, ['A'..'Z', 'a'..'z']);
|
||||
ns := ScanTo(s, i, [#32, #9, '"']);
|
||||
if ns <> '' then Strings.Add(ns);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function isNameofPointer(const name: AnsiString): Boolean;
|
||||
begin
|
||||
Result := false;
|
||||
if name = '' then Exit;
|
||||
Result := name[length(name)] = '*';
|
||||
end;
|
||||
|
||||
procedure ReadIniFile(Settings: TConvertSettings; const FileName: AnsiString);
|
||||
var
|
||||
ini : TIniFile;
|
||||
values : TStringList;
|
||||
a, b : AnsiString;
|
||||
i : Integer;
|
||||
IniName : AnsiString;
|
||||
begin
|
||||
// uikit.ini
|
||||
if not FileExists(FileName) then begin
|
||||
Exit;
|
||||
end;
|
||||
{$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;
|
||||
{ ini.ReadSection('TypeReplace', values);
|
||||
for i := 0 to values.Count - 1 do begin
|
||||
a := values.ValueFromIndex[i];
|
||||
b := values.Values[a];
|
||||
if b <> '' then begin
|
||||
ense
|
||||
Settings.TypeDefReplace[a] := b;
|
||||
end;}
|
||||
|
||||
//[Common]
|
||||
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;}
|
||||
|
||||
// [TokenReplace]
|
||||
Values.Clear;
|
||||
ini.ReadSection(TokenReplaceSec, values);
|
||||
for i := 0 to values.Count - 1 do begin
|
||||
a := Values[i];
|
||||
b := ini.ReadString(TokenReplaceSec, a, '');
|
||||
{if b ='' then
|
||||
Settings.IgnoreTokens.Add(a)
|
||||
else}
|
||||
Settings.TokenReplace[a] := b;
|
||||
end;
|
||||
|
||||
// [TypeReplace]
|
||||
values.Clear;
|
||||
ini.ReadSection(TypeDefsSec, values);
|
||||
for i := 0 to values.Count - 1 do begin
|
||||
a := Values[i];
|
||||
b := AnsiLowerCase(ini.ReadString(TypeDefsSec, a, ''));
|
||||
if b = 'objcclass' then
|
||||
Settings.ObjCClassTypes.Add(a)
|
||||
else if b = 'struct' then
|
||||
Settings.StructTypes.Add(a)
|
||||
else if b = 'float' then
|
||||
Settings.FloatTypes.Add(a);
|
||||
end;
|
||||
|
||||
values.Clear;
|
||||
ini.ReadSection(TypeReplaceSec, values);
|
||||
for i := 0 to values.Count - 1 do begin
|
||||
a := Values[i];
|
||||
b := ini.ReadString(TypeReplaceSec, a, '');
|
||||
if isNameofPointer(a) then
|
||||
Settings.PtrTypeReplace[ Copy(a, 1, length(a) - 1)] := b
|
||||
else
|
||||
Settings.TypeDefReplace[a] := b;
|
||||
end;
|
||||
|
||||
finally
|
||||
values.Free;
|
||||
ini.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function GetConvertSettings(Settings : TConvertSettings; var FileName: AnsiString): Boolean;
|
||||
var
|
||||
i : integer;
|
||||
prm : AnsiString;
|
||||
vlm : AnsiString;
|
||||
Params : TStringList;
|
||||
begin
|
||||
prm := '';
|
||||
vlm := '';
|
||||
Params := TStringList.Create;
|
||||
Params.CaseSensitive := false;
|
||||
try
|
||||
for i := 1 to ParamCount do begin
|
||||
if isParamValue(ParamStr(i), prm, vlm) then begin
|
||||
prm := AnsiLowerCase(prm);
|
||||
if prm = 'noout' then doOutput:=false
|
||||
else if prm = 'all' then doparseAll:=true
|
||||
else if (prm = 'id') and (vlm <> '') then ConvertSettings.ObjcIDReplace:=vlm
|
||||
else if (prm = 'call') then ConvertSettings.CallConv:=vlm
|
||||
else if (prm = 'userefs') then ConvertSettings.UseRefClassType := true
|
||||
else if (prm = 'refpostfix') then ConvertSettings.RefClassPostfix := vlm
|
||||
else if prm = 'ini' then begin
|
||||
ReadIniFile(Settings, vlm);
|
||||
end else
|
||||
Params.Values[prm] := vlm;
|
||||
end else
|
||||
FileName := ParamStr(i);
|
||||
end;
|
||||
|
||||
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');
|
||||
writeln('');
|
||||
writeln(' hidden keys (they''re temporary, and will be removed in future versions)');
|
||||
writeln(' -id=IDENTIFIER the identifier to replace objective-c id type name');
|
||||
writeln(' default = lobjc.id');
|
||||
writeln(' -call=IDENTIFIER specifies the function''s calling convention.');
|
||||
writeln(' default is cdecl. Please note, that calling convention');
|
||||
writeln(' also effect external functions name. Thus, using ');
|
||||
writeln(' if calling convention is not cdecl, the external name');
|
||||
writeln(' -useRefs enables additional types to be created, for lobjc.id ');
|
||||
writeln(' replacements at the parameter and result types');
|
||||
writeln(' -refPostFix post-fix for each ref type. The default postfix is ''Ref''');
|
||||
end;
|
||||
|
||||
var
|
||||
inpf : AnsiString = '';
|
||||
st : TStrings = nil;
|
||||
err : AnsiString = '';
|
||||
i : integer;
|
||||
|
||||
|
||||
function FileToString(const FileName: WideString): AnsiString;
|
||||
var
|
||||
fs : TFileStream;
|
||||
begin
|
||||
Result := '';
|
||||
try
|
||||
fs := TfileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
|
||||
try
|
||||
SetLength(Result, fs.Size);
|
||||
fs.Read(Result[1], fs.Size)
|
||||
finally
|
||||
fs.Free;
|
||||
end;
|
||||
except
|
||||
end;
|
||||
end;
|
||||
|
||||
{procedure DoTest(const InputFile: AnsiString);
|
||||
var
|
||||
hdr : TObjCHeader;
|
||||
|
||||
wrt : TStringsWriter;
|
||||
cnv : TDefaultConverter;
|
||||
i : Integer;
|
||||
names : TPascalNames;
|
||||
begin
|
||||
hdr := TObjCHeader.Create;
|
||||
wrt := TStringsWriter.Create;
|
||||
wrt.Strings := TStringList.Create;
|
||||
try
|
||||
if not ParserCHeader( FileToString(InputFile), hdr) then Exit;
|
||||
|
||||
cnv := TDefaultConverter.Create;
|
||||
names := CreateDefaultPascalNames;
|
||||
try
|
||||
cnv.WriteCHeader(hdr, wrt, names);
|
||||
finally
|
||||
cnv.Free;
|
||||
end;
|
||||
|
||||
for i := 0 to wrt.Strings.Count - 1 do
|
||||
writeln(wrt.Strings[i]);
|
||||
|
||||
finally
|
||||
wrt.Strings.Free;
|
||||
wrt.Free;
|
||||
hdr.Free;
|
||||
end;
|
||||
end;}
|
||||
|
||||
|
||||
procedure TestTemplate;
|
||||
var
|
||||
fn : TFileStream;
|
||||
tmp : AnsiString;
|
||||
|
||||
tp : TTemplateProc;
|
||||
s : string;
|
||||
pv : TPascalValues;
|
||||
root: TTemplateList;
|
||||
cl : TTemplateList;
|
||||
begin
|
||||
root:=TTemplateList.Create(nil);
|
||||
cl:=TTemplateList.Create(root);
|
||||
cl.Name :='class';
|
||||
cl.Params.Values['class_objcname'] := 'NSNotebook';
|
||||
cl.Params.Values['class_objcsupername'] := 'NSObject';
|
||||
|
||||
root.SubLists.Add(cl);
|
||||
|
||||
fn := TFileStream.Create('templatesample.txt', fmOpenRead or fmShareDenyNone);
|
||||
tp := TTemplateProc.Create;
|
||||
pv := TPascalValues.Create;
|
||||
try
|
||||
SetLength(tmp, fn.Size);
|
||||
fn.Read(tmp[1], fn.Size);
|
||||
|
||||
|
||||
s := tp.Parse(tmp, root, pv);
|
||||
writeln(s);
|
||||
readln;
|
||||
finally
|
||||
pv.Free;
|
||||
tp.Free;
|
||||
fn.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
// TestTemplate;
|
||||
// Exit;
|
||||
|
||||
doOutput := true;
|
||||
try
|
||||
GetConvertSettings(ConvertSettings, inpf);
|
||||
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 begin
|
||||
if doOutput then
|
||||
for i := 0 to st.Count - 1 do
|
||||
writeln(st[i]);
|
||||
end;
|
||||
except
|
||||
end;
|
||||
st.Free;
|
||||
except
|
||||
on e: exception do
|
||||
writeln(e.Message);
|
||||
end;
|
||||
end.
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
./objcparser /System/Library/Frameworks/AppKit.framework/Headers/NSButton.h > NSButton.inc
|
Loading…
Reference in New Issue
Block a user