Dirk Carstensen The short answer is yes. But this will require much more work. To get a list of classes, types, variables etc and to figure out which of them are not used.
Nicholas Ring It works just like a real compiler. Parser can handle compiler directives like {$DEFINE ..}, {$IFDEF...} etc.
As you can see in the demo app, it calls ASTBuilder.InitDefinesDefinedByCompiler method, that defines some standard compiler defines like VER120, CPUX86 or UNICODE. Also you can define something by calling ASTBuilder.AddDefine('SOMETHINGELSE');
Interesting. Why the approach of going through XML, rather than using the AST methods directly?
ReplyDeleteDavid Millington only because it requires a bit less code. Of course you can do the same just using TSyntaxNode class without any XML.
ReplyDeleteDavid Millington also an XML is easier to visualize. It's important when you are writting a blog post :)
ReplyDeleteI used to watch the generated DCU files for this. Your solution is neater.
ReplyDeleteIs it possible to show unused units with this approach?
ReplyDeleteQ: How does it handle compiler conditionals within the uses clause?
ReplyDeleteDirk Carstensen The short answer is yes. But this will require much more work. To get a list of classes, types, variables etc and to figure out which of them are not used.
ReplyDeleteNicholas Ring It works just like a real compiler. Parser can handle compiler directives like {$DEFINE ..}, {$IFDEF...} etc.
As you can see in the demo app, it calls ASTBuilder.InitDefinesDefinedByCompiler method, that defines some standard compiler defines like VER120, CPUX86 or UNICODE. Also you can define something by calling ASTBuilder.AddDefine('SOMETHINGELSE');
Roman Yankovsky Neat - Thanks! :)
ReplyDeleteIt did not work for me Access violation on line
ReplyDeletePreambleSize := TEncoding.GetBufferEncoding(Buffer, Encoding, TEncoding.Default);
Compiled on Delphi xe
changed
Content.Read(Buffer, 0, Content.Size); to Content.Read(Buffer, Content.Size);
shlomo abuisak The AV is because of the incorrect conversion with the Content.Read changes. What needs to be done is to change the Content.Read to be:
ReplyDeleteContent.Read(Buffer[0], Content.Size);
Nicholas Ring Thanks. OK now
ReplyDelete