CDT Assembly parser removes parenthesis from the code - eclipse-cdt

When I try to fetch assembly code using below CASTASMDeclaration API,
org.eclipse.cdt.internal.core.dom.parser.c.CASTASMDeclaration.getAssembly()
the parenthesis are removed from code.
In assembly code I have following code
(uint32)sizeof(uint32))
Which when I try to get via getAssembly() method it removes parenthesis and gives this:
uint32 sizeof uint32
Is there a way I get the result including parenthesis?

Related

How to set up clang-format comment pragmas so multiline doxygen comments don't get touched?

I am trying to introduce clang-format to a couple of our projects at work (C and C++), but I am having trouble getting it to format multi-line Doxygen comments the way I want.
All comments have the same format:
/*! #brief Some text
*
* Some more text
*
* #verbatim
*
* A very long line of text that exceeds the clang-format column width but should not be touched
*
* #endverbatim
*/
I want clang-format to leave the verbatim blocks alone and not reflow them. I am using clang-format-6.0
Turning ReflowComments off is not an option as non-doxygen comments must be taken care of by clang-format
I have tried various regular expressions in the CommentPragmas config item but to no avail:
#verbatim(.*\n)*.*#endverbatim to treat the entire verbatim block as a comment pragma. This is the ideal situation, as any other part of the Doxygen comment I do not mind being broken into multiple lines.
#brief(.*\n)+ to match the entire comment block as the pragma. I've also tried this with an arbitrary token at the end of the comment to act as an explicit end-of-block marker. This isn't ideal as it doesn't force the non-verbatim part of the comment to conform, but is a compromise I'm willing to live with if I have to.
Various other regexes I've seen in other discussions, adapted to fit our Doxygen markup.
All I've managed to get it to do so far is to leave the first line of the multi-line comment alone, if it happens to exceed the column limit. However, any following long line is still broken up.
The only other tool I have left in my box is to use // clang-format off and // clang-format on around these comments but again I'd like to avoid it if I can because:
a) it'll be quite tedious to add them throughout the code base
b) I'll have to surround the entire comments with these, rather than just the verbatim blocks (I haven't figured out if you can disable it just for a portion of a multi-line comment - I've only managed to get it working for an entire one, and even if that was possible the clang-format directives would end up in the generated Doxygen docs which is unacceptable)
c) I don't really like the way it looks in code.
Any help is appreciated. Thanks.
Ran into this issue also, and the only work around found was to use clang-format on/off.
clang-format re flowing comments tends to:
break #page, #section, etc titles, and links generated from them (in rare cases).
break #startuml blocks, which have a specific syntax.
break #verbatim blocks.
See an example of usage in MySQL:
https://github.com/mysql/mysql-server/blob/8.0/storage/perfschema/pfs.cc
Update:
Filed a feature request on clang-format itself:
https://bugs.llvm.org/show_bug.cgi?id=44486

Trouble with C++ Regex POSIX character class

I'm trying to create a regex that is capable of analysing something like this:
002561-1415179671591i.jpg
The second part is a unix timestamp (before the i), and I need to extract that. I came up with the following syntax, but std::regex keeps throwing a regex_error before I even check for a match and I'm not too sure what's wrong.
Here's what I've got so far:([:d:])*-[[:d:]]*([:alpha:])\.jpg
The C++ code line that throws the error is the constructor to regex
std::regex reg(regex_expr);
where regex_expr is a string that has been read in from a file.
Really appreciate any help you can give.
Edit: I wrote a try catch section, and it seems I'm getting the following error code
std::regex_constants::error_brack
Edit 2: Ok... seems I'm still getting the error even with a cut-down test:
([:alpha:])*
Edit 3:
Seems I can't get any expression to work. Here's a bit more info. I'm using clang++ 3.5.0 on Kubuntu 14.04.
Not sure that [:d:] can stand for [:digit:]. [EDIT] (It seems it's possible)
When you use a POSIX character class, it must be enclosed in a character class like that:
[[:digit:]]
(This syntax allows to compose other classes [[:digit:]ab])
so:
std::string regex_expr = "([[:digit:]]*)-([[:digit:]]*)([[:alpha:]])\\.jpg";
or if you use the basic mode:
std::string regex_expr = "\\([[:digit:]]*\\)-\\([[:digit:]]*\\)\\([[:alpha:]]\\)\\.jpg";
I would rather use the perl-compatible syntax instead of character classes:
\d+-(\d+)[a-z]*\.jpg
After many tests, for whatever reason, I couldn't get this to work. As I had boost anyway, I tried out the boost::regex and it worked straight away, so I presume that something to do with either clang, or the version of the standard on this pc just wasn't working.
So simply put, tried boost and it worked straight away. Not much of an answer, but I guess that's how things go sometimes.

clang-format breaks lint annotations

We use lint in our codebase at work for C/C++, I'm trying to start integrating clang-format in my workflow as well.
Unfortunately, lint occasionally requires annotations to ignore a specific check, either of the format:
/*lint -[annotation] */
or
//lint -[annotation]
Specifically, if there's a space between the opening token for the comment and 'lint', it doesn't recognize it as an annotation directive. Unfortunately, the default settings I have for clang-format see that as an error and helpfully insert the space.
Is there any way to get clang-format to recognize comments matching that pattern and leave them alone? Right now I'm using 3.4, but could upgrade if needed.
Clang-format has a `CommentPragmas' option that is
A regular expression that describes comments with special meaning, which should not be split into lines or otherwise changed.
When I put the following line in my .clang-format file, my Lint comments remain untouched.
CommentPragmas: '^lint'
Other comments that still have "lint" in them, but are not Lint comments still get formatted.
You can disable clang-format for that section of your file by using:
int formatted_code;
// clang-format off
void unformatted_code ;
// clang-format on
void formatted_code_again;
See the Disabling formating on a piece of code section.

How to mask potential macro variables as part of a filename URL string

I have written the following filename statement as part of a program to dynamically pull down stock quotes in iterative steps. This now works fine, except for three warning messages I am getting in the log:
1) &s= is not resolved
2) &f= is not resolved
3) Warnings: String is more than 252 characters long, you may have unbalanced quotations
filename loader url "http://finance.yahoo.com/d/quotes.csv?s=&svar1.+&svar2.+&svar3.+&svar4.+&svar5.+&svar6.+&svar7.+&svar8.+&svar9.+&svar10.+
&svar11.+&svar12.+&svar13.+&svar14.+&svar15.+&svar16.+&svar17.+&svar18.+&svar19.+&svar20.+
&svar21.+&svar22.+&svar23.+&svar24.+&svar25.+&svar26.+&svar27.+&svar28.+&svar29.+&svar30.+
&svar31.+&svar32.+&svar33.+&svar34.+&svar35.+&svar36.+&svar37.+&svar38.+&svar39.+&svar40.+
&svar41.+&svar42.+&svar43.+&svar44.+&svar45.+&svar46.+&svar47.+&svar48.+&svar49.+&svar50.+
&svar51.+&svar52.+&svar53.+&svar54.+&svar55.+&svar56.+&svar57.+&svar58.+&svar59.+&svar60.+
&svar61.+&svar62.+&svar63.+&svar64.+&svar65.+&svar66.+&svar67.+&svar68.+&svar69.+&svar70.+
&svar71.+&svar72.+&svar73.+&svar74.+&svar75.+&svar76.+&svar77.+&svar78.+&svar79.+&svar80.+
&svar81.+&svar82.+&svar83.+&svar84.+&svar85.+&svar86.+&svar87.+&svar88.+&svar89.+&svar90.+
&svar91.+&svar92.+&svar93.+&svar94.+&svar95.+&svar96.+&svar97.+&svar98.+&svar99.+&svar100.+
&svar101.+&svar102.+&svar103.+&svar104.+&svar105.+&svar106.+&svar107.+&svar108.+&svar109.+&svar110.+
&svar111.+&svar112.+&svar113.+&svar114.+&svar115.+&svar116.+&svar117.+&svar118.+&svar119.+&svar120.+
&svar121.+&svar122.+&svar123.+&svar124.+&svar125.+&svar126.+&svar127.+&svar128.+&svar129.+&svar130.+
&svar131.+&svar132.+&svar133.+&svar134.+&svar135.+&svar136.+&svar137.+&svar138.+&svar139.+&svar140.+
&svar141.+&svar142.+&svar143.+&svar144.+&svar145.+&svar146.+&svar147.+&svar148.+&svar149.+&svar150.+
&svar151.+&svar152.+&svar153.+&svar154.+&svar155.+&svar156.+&svar157.+&svar158.+&svar159.+&svar160.+
&svar161.+&svar162.+&svar163.+&svar164.+&svar165.+&svar166.+&svar167.+&svar168.+&svar169.+&svar170.+
&svar171.+&svar172.+&svar173.+&svar174.+&svar175.+&svar176.+&svar177.+&svar178.+&svar179.+&svar180.+
&svar181.+&svar182.+&svar183.+&svar184.+&svar185.+&svar186.+&svar187.+&svar188.+&svar189.+&svar190.+
&svar191.+&svar192.+&svar193.+&svar194.+&svar195.+&svar196.+&svar197.+&svar198.+&svar199.+&svar200.
&f=&&fvar&a.";
Firstly, how can I mask the &s= &f= from the processor, but allow it still resolve the &svar macro variables? I have tried various attempts at using %superq and %nrbquote but not had much luck.
Also, is there a way to a mask the warning about the string being long other than using log errors to suppress all options? Ideally I don't want to do that as I would still like to see any new errors that may arise for whatever reason.
Thanks
To turn off the warning about string being too long, use system option NOQUOTELENMAX.
To mask an & that you can see, try %NRSTR(), e.g. %NRSTR(&f).
To "mask" the ampersand so it is not scanned by the macro processor, just use the %STR function. I don't see any reference to an &s variable in the code you show, but I do see one from&f. Change that last parameter to:
%str(&)f=&&fvar&a.
Also, to assist debugging things like this, I strongly suggest that you build the entire string into it's own macro variable (perhaps named url). In other words:
%let url="http://finance.yahoo.com/d/quotes.csv?%str(&)s=//svars// %str(&)f=&&fvar&a.";
%put url=&url;
filename loader url "&url";
I'm guessing that the s= was &s= in the code that had the error and I substituted your long parameter string with //svars// only to save formatting in this answer.
Using a "helper macro variable" like this should help during development. The %put just echos the string during testing and would not be part of the final macro.

Have error output include last couple lines of code

Is it possible, and if so, how would you make error output include the last couple lines of code? I know about GNU g++'s support for __LINE__ and __FUNC__ but those only give the line number as an int and the function name as a string - I'd like to dump the function that failed's code or at least the last several commands executed by the program.
I was thinking maybe write a m4 script that would parse through the code base and inject string structures of the functions they're put in (excluding themselves, of course).
Any other/better ideas?
Do not change your code at all. Use __LINE__ and __FUNC__ and post process the error output. That is, run your program as my-prog > $(tty) 2>&1 | post-process where post-process has access to your code base and can generate the desired text. You might want to modify the code slightly by adding tags to make it easier for post-process to find the function name and line number.