A patch for printing policy and other stuff

Hi @clang,

I've created a patch for some of the issues discussed earlier in "A bunch of more or less related issues" and some other things:
Into the details:

1. In ParentMap I added a function "addStmt" which actually adds a Statement or updates the parent relations of an already existing statement. Due to the second functionality I'm rather unsure with the name but updateStmt sounds not right too as it conceals the add part.
2. In PrinterHelper::handledStmt I introduced the IndentLevel. This can be useful if someone (e.g. me) want to print something before a particular statement (e.g. a comment) properly formatted. This affected AST/CFG.cpp.
3. PrintingPolicy gets a new property IndentStyle. At the moment this property is only evaluated in StmtPrinter.
4. A harmless but useful typedef in StmtVisitor.

Best
Olaf Krzikalla

printingStuff.patch (9.77 KB)

Seems pretty reasonable. Some syntactic issues: please keep code in 80 columns, and please end sentences in a comment with a period. Also, is there some way that you can expose the new printing style through to the command line?

-Chris

Hi Olaf,

Since ParentMap acts as an observer of the parent-child relationships in an AST, I'm not so certain about the name 'addStmt' (which seems a little content-free). A couple suggestions for alternate names are 'updateParents' (or 'updateDescendants'; see comment below), 'addRootStmt', or 'updateRoot'. I'm fine with keeping 'addStmt', however, as long as the method declaration is well documented (see below).

One other nit:

+ void addStmt(Stmt* S); // adds and/or updates the parent/child-relations of the stmt tree of S

Hi @clang,

find attached a new patch considering the comments (includin Ted's).

Chris Lattner schrieb:

Also, is there some way that you can expose the new printing style through to the command line?

Hmm, as far as I can see the printing policy is not customized by the command line yet. This is related to the fact that PrintingPolicy objects are constructed here and there even if one exists in the ASTContext. I think that the PrintingPolicy object in ASTContext has to be used consequently to expose printing style options through to the command line. That said one could think of making the PrintingPolicy ctor private and ASTContext a friend of PrintingPolicy. However this might be a too strict restriction (but not IMO).

Best
Olaf Krzikalla

printingStuff.patch (12.4 KB)

Hello.

According to the C99 standard (6.7.2p5):

"[...] it is implementation-defined whether the specifier 'int' designates the same type as 'signed int' or the same type as 'unsigned int'."

Similarly, in the C89 standard I have found:

"Each of the above comma-separated lists designates the same type,
except that for bit-field declarations, signed int (or signed ) may
differ from int (or no type specifiers)."

I have searched for a language or target specific option to specify this implementation-defined behavior ... but I found nothing.
Was I looking in the wrong places?
If not, are there plans to add such an option?

Thanks in advance,
Enea Zaffanella.

Hello.

According to the C99 standard (6.7.2p5):

"[...] it is implementation-defined whether the specifier 'int'
designates the same type as 'signed int' or the same type as 'unsigned
int'."

Similarly, in the C89 standard I have found:

"Each of the above comma-separated lists designates the same type,
except that for bit-field declarations, signed int (or signed ) may
differ from int (or no type specifiers)."

I have searched for a language or target specific option to specify this
implementation-defined behavior ... but I found nothing.
Was I looking in the wrong places?

I don't believe we have any way to specify this implementation-defined behavior. If we did, we'd expose it by supporting the GNU -fsigned-bitfields/-funsigned-bitfields command-line options.

If not, are there plans to add such an option?

No specific plans that I know of. However, we will eventually need to support these options to improve our compatibility with GCC. If you're inclined to submit a patch to add support for this feature, that's wonderful; if not, please file a bug report against Clang so we don't forget about this feature.

   - Doug

You can expose it as an option for -ast-print mode pretty easily.

-Eli

Eli Friedman schrieb:

You can expose it as an option for -ast-print mode pretty easily.

-Eli
  

Well, to do it right we would need the indentation and the style. And IMHO the flags should start with rewrite, that is we have -rewrite-style=(KR | ANSI) and -rewrite-indent=number. I could do that but as said before it requires some more changes to prevent printing policies being constructed freehandly.

Best
Olaf Krzikalla