Hello,
as mentioned in (accidentally closed) ticket #413 preprocesor indentation doesn't work properly in astyle 3.1 under certain circumstances.
Used arguments: --indent-preproc-block --indent-preproc-cond
Here an example to reproduce it:
#if ABC
#error FOOBAR
#include foobar
#pragma fuubar
#endif
#if ABC
#if ABC2
#error FOOBAR
#include foobar
#pragma fuubar
#endif
#endif
void abc()
{
#if ABC
#error FOOBAR
#include foobar
#pragma fuubar
#endif
}
#if ABC1
#error FOOBAR
#include foobar
#pragma fuubar
#endif
}
#if ABC2
#error FOOBAR2
#include foobar2
#pragma fuubar2
#endif
becomes
#if ABC
#error FOOBAR
#include foobar
#pragma fuubar
#endif
#if ABC
#if ABC2
#error FOOBAR
#include foobar
#pragma fuubar
#endif
#endif
void abc()
{
#if ABC
#error FOOBAR
#include foobar
#pragma fuubar
#endif
}
#if ABC1
#error FOOBAR
#include foobar
#pragma fuubar
#endif
As you see, the first and third preprocessor block is formated wrong whereas the second and fourth one is formated correctly.
Hope we get that fixed
Both problems can be solved by
1) commenting out lines 600 and 601 in ASFormatter.cpp
2) commenting out lines 666 and 667 in ASFormatter.cpp
But I don't know what gets damaged by this?! Maybe a check of file type (fileType == C_TYPE) would be useful if these lines are important for e.g. CSharp!?
Preprocessor stuff is indentend independent from source identation what is probably what most people would expect, wouldn't they?
The result is now:
@jimp03: Can you please check for possible side effects since you are understanding the code much better than I do? And if the changes are ok, can you please add them to the official version?
Thanks a lot in advance!
By the way, are there any "test files" with expected results so they can be used for testing changes in astyle?
Last edit: Foo Bar 2019-03-10
Please find a patch file attached that checks if file tpye is C_TYPE and in that case do the expected format, all other file types will not be affected, hope that will cause the least trouble :)
This type of change should be tested with the AStyleTest programs
http://astyle.sourceforge.net/subversion.html
It's really great that there are so many tests available!
But it seems that some of them are not working with official version 3.1, are they?
[ PASSED ] 2698 tests.
[ FAILED ] 11 tests, listed below:
[ FAILED ] BugFix_V32.ObjCAutoReleasePool
[ FAILED ] BugFix_V32.ObjCTypeVariable
[ FAILED ] ObjCStyleF.WebKit
[ FAILED ] StyleWebKitCppF.LongOption
[ FAILED ] StyleWebKitCppF.Short
[ FAILED ] StyleWebKitCpp.SpaceIndent
[ FAILED ] StyleWebKitCpp.Tab
[ FAILED ] StyleWebKitCpp.TabIndent
[ FAILED ] StyleWebKitCpp.ForceTab
[ FAILED ] StyleWebKitCpp.ForceTabIndent
[ FAILED ] StyleWebKitCpp.IndentClasses
11 FAILED TESTS
All tests ran.
Last edit: Foo Bar 2019-03-11
The tests and astyle need to be the same version.
You need to get the tests for 3.1.
Or use the updated astyle source for 3.2.
The updated 3.2 astyle source is the one you should modify.