chelper: added support for #import preprocessor, and c block objects declaration parsing

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1376 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
skalogryz
2010-11-20 03:07:24 +00:00
parent 83d8b4b3b9
commit 07d1f556a6
3 changed files with 48 additions and 20 deletions

View File

@ -19,6 +19,9 @@
<CharSet Value=""/>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
@ -50,7 +53,7 @@
<Filename Value="cconvert"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)/"/>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
@ -66,9 +69,6 @@
<GenerateDebugInfo Value="True"/>
<UseLineInfoUnit Value="False"/>
</Debugging>
<Options>
<LinkerOptions Value="-macosx_version_min 10.4 "/>
</Options>
</Linking>
<Other>
<CompilerMessages>

View File

@ -76,14 +76,48 @@ begin
end;
end;
procedure PrintHelp;
begin
writeln('cconvert - c to pascal convert utility');
writeln('possible options:');
writeln(' -all - convert the whole header to pascal, instead of a first entity');
writeln(' -o filename - specify the output file. if not specified, outputs to stdout');
writeln(' -ro - prevent the configuration file from modifications (adding new types, etc)');
writeln(' -cfg filename - specifies the configuration file');
writeln(' -defines filename - macros definition file. should be in C-preprocessor format');
end;
procedure ReadParams(var InputFileName: String);
var
i : integer;
s : string;
begin
for i:=1 to ParamCount do begin
s:=LowerCase(ParamStr(i));
if (s='-h') or (s='-help') or (s='-?') then begin
PrintHelp;
Halt;
end;
end;
InputFileName:=ParamStr(ParamCount);
end;
var
inps, outs : TStringList;
i : Integer;
p : TPoint;
cfg : TConvertSettings;
err : TErrorInfo;
fn : String;
begin
if ParamCount=0 then Exit;
ReadParams(fn);
if not FileExists(fn) then begin
writeln('file doesn''t exist: ', fn);
Exit;
end;
inps := TStringList.Create;
outs := TStringList.Create;

View File

@ -721,13 +721,13 @@ begin
idx := Index;
i := idx+1;
ScanWhile(Buf, i, WhiteSpaceChars);
s := ScanTo(Buf, i, WhiteSpaceChars);
if s = 'define' then df := TCPrepDefine.Create(idx)
else if s = 'include' then df := TCPrepInclude.Create(idx)
else if s = 'else' then df := TCPrepInclude.Create(idx)
else if s = 'endif' then df := TCPrepEndif.Create(idx)
else if s = 'pragma' then df := TCPrepPragma.Create(idx)
else if (s = 'if') or (s = 'elif') or (s = 'ifdef') or (s = 'ifndef') then begin
s := ScanTo(Buf, i, SpaceEolnChars);
if s='define' then df := TCPrepDefine.Create(idx)
else if (s='include') or (s='import') then df := TCPrepInclude.Create(idx)
else if s='else' then df := TCPrepInclude.Create(idx)
else if s='endif' then df := TCPrepEndif.Create(idx)
else if s='pragma' then df := TCPrepPragma.Create(idx)
else if (s='if') or (s='elif') or (s='ifdef') or (s='ifndef') then begin
df := TCPrepIf.Create(idx);
TCPrepIf(df).IfOp:=s;
end else
@ -739,12 +739,9 @@ begin
Result := df.Parse(Self);
Comments.Add(df);
if Assigned(OnPrecompile) then OnPrecompile(Self, df);
end;
end else
SetError('cannot handle preprocessor: "'+s+'"');
if not Result then begin
SetError('cannot handle preprocessor');
Exit;
end;
finally
ProcessingMacro := false;
end;
@ -1168,8 +1165,6 @@ begin
try
AParser.TokenTable.Symbols := AParser.TokenTable.Symbols + ['"'];
//i := AParser.TokenPos;
AParser.FindNextToken(s, tt);
Result := (s = '"') or (s = '<');
if not Result then Exit;
@ -1182,7 +1177,6 @@ begin
if (s = '/') or (s = '\') or (tt = tt_Ident) then
Included := Included + s;
until (tt =tt_Symbol) and ((s <> '\') or (s <> '/'));
Result := s = exp;
SkipLine(AParser.buf, AParser.Index);
finally
@ -1689,7 +1683,7 @@ begin
Parser.NextToken;
id:=ParseNamePart(Parser);
ConsumeToken(Parser, ')');
end else if Parser.TokenType=tt_Ident then begin
end else if (Parser.TokenType=tt_Ident) or (Parser.Token='^') then begin
id:=TNamePart.Create(nk_Ident);
id.id:=Parser.Token;
Parser.NextToken;