From d818eb1292123199ae9b0bb959dc73895f1b10fb Mon Sep 17 00:00:00 2001 From: skalogryz Date: Sat, 17 Jan 2009 22:29:42 +0000 Subject: [PATCH] + c compiler specific syntax parsing added. + GNU CC __attribute__ (...) support * fixed custom entities parsing git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@662 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- bindings/pascocoa/parser/ObjCParserTypes.pas | 5 ++ bindings/pascocoa/parser/gnuccFeatures.pas | 70 ++++++++++++++++++++ bindings/pascocoa/parser/objcparser.lpi | 37 ++++++++--- bindings/pascocoa/parser/objcparser.pas | 2 +- 4 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 bindings/pascocoa/parser/gnuccFeatures.pas diff --git a/bindings/pascocoa/parser/ObjCParserTypes.pas b/bindings/pascocoa/parser/ObjCParserTypes.pas index 721e9ed95..cb74cb831 100755 --- a/bindings/pascocoa/parser/ObjCParserTypes.pas +++ b/bindings/pascocoa/parser/ObjCParserTypes.pas @@ -2676,6 +2676,11 @@ var proc : TCustomEntityProc; index : Integer; begin + if not Assigned(CustomList) then begin + Result := nil; + Exit; + end; + index := Parser.TokenPos; for i := 0 to CustomList.Count - 1 do begin proc := TCustomEntityProc(CustomList[i]); diff --git a/bindings/pascocoa/parser/gnuccFeatures.pas b/bindings/pascocoa/parser/gnuccFeatures.pas new file mode 100644 index 000000000..309ce1510 --- /dev/null +++ b/bindings/pascocoa/parser/gnuccFeatures.pas @@ -0,0 +1,70 @@ +{ * 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. diff --git a/bindings/pascocoa/parser/objcparser.lpi b/bindings/pascocoa/parser/objcparser.lpi index 7b6ae44c3..7b092b27e 100755 --- a/bindings/pascocoa/parser/objcparser.lpi +++ b/bindings/pascocoa/parser/objcparser.lpi @@ -12,7 +12,7 @@ - + @@ -31,13 +31,13 @@ - + - - + + @@ -45,23 +45,32 @@ - + - + - - - + + + + + + + + + + + + - + @@ -126,6 +135,14 @@ + + + + + + + + diff --git a/bindings/pascocoa/parser/objcparser.pas b/bindings/pascocoa/parser/objcparser.pas index 2bf84ad5c..6015a19a8 100755 --- a/bindings/pascocoa/parser/objcparser.pas +++ b/bindings/pascocoa/parser/objcparser.pas @@ -21,7 +21,7 @@ uses SysUtils, ObjCParserUtils, ObjCParserTypes, - CToPasWriter; + CToPasWriter, gnuccFeatures; type // this object is used only for precomile directives handling