[cfe-commits] r170606 - in /cfe/trunk: include/clang/AST/PrettyPrinter.h lib/AST/DeclPrinter.cpp tools/libclang/CXComment.cpp unittests/AST/DeclPrinterTest.cpp
Dmitri Gribenko
gribozavr at gmail.com
Wed Dec 19 15:41:50 PST 2012
On Thu, Dec 20, 2012 at 1:36 AM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Wed Dec 19 17:36:00 2012
> New Revision: 170606
>
> URL: http://llvm.org/viewvc/llvm-project?rev=170606&view=rev
> Log:
> Audit DeclPrinter with -ast-dump on Cocoa.h and
> fix any bad objectiveC syntax coming out of
> DeclPrinter. This is on going. Also, introduce a new
> PrintPolicy and use it as needed when declaration tag
> is to be produced via DeclPrinter.
Tests, please.
> Modified:
> cfe/trunk/include/clang/AST/PrettyPrinter.h
> cfe/trunk/lib/AST/DeclPrinter.cpp
> cfe/trunk/tools/libclang/CXComment.cpp
> cfe/trunk/unittests/AST/DeclPrinterTest.cpp
>
> Modified: cfe/trunk/include/clang/AST/PrettyPrinter.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/PrettyPrinter.h?rev=170606&r1=170605&r2=170606&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/PrettyPrinter.h (original)
> +++ cfe/trunk/include/clang/AST/PrettyPrinter.h Wed Dec 19 17:36:00 2012
> @@ -40,7 +40,7 @@
> SuppressUnwrittenScope(false), SuppressInitializers(false),
> ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
> SuppressStrongLifetime(false), Bool(LO.Bool),
> - TerseOutput(false), SuppressAttributes(false),
> + TerseOutput(false), PolishForDeclaration(false),
> DumpSourceManager(0) { }
>
> /// \brief What language we're printing.
> @@ -143,9 +143,10 @@
> /// only the requested declaration.
> unsigned TerseOutput : 1;
>
> - /// \brief When true, do not print attributes attached to the declaration.
> + /// \brief When true, do certain refinement needed for producing proper
> + /// declaration tag; such as, do not print attributes attached to the declaration.
> ///
> - unsigned SuppressAttributes : 1;
> + unsigned PolishForDeclaration : 1;
>
> /// \brief If we are "dumping" rather than "pretty-printing", this points to
> /// a SourceManager which will be used to dump SourceLocations. Dumping
>
> Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=170606&r1=170605&r2=170606&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
> +++ cfe/trunk/lib/AST/DeclPrinter.cpp Wed Dec 19 17:36:00 2012
> @@ -193,7 +193,7 @@
> }
>
> void DeclPrinter::prettyPrintAttributes(Decl *D) {
> - if (Policy.SuppressAttributes)
> + if (Policy.PolishForDeclaration)
> return;
>
> if (D->hasAttrs()) {
> @@ -915,7 +915,7 @@
> OMD->getBody()->printPretty(Out, 0, Policy);
> Out << '\n';
> }
> - else
> + else if (Policy.PolishForDeclaration)
> Out << ';';
> }
>
> @@ -950,7 +950,7 @@
> Out << "@class " << I << ";";
> return;
> }
> -
> + bool eolnOut = false;
> if (SID)
> Out << "@interface " << I << " : " << *SID;
> else
> @@ -962,13 +962,12 @@
> for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
> E = Protocols.end(); I != E; ++I)
> Out << (I == Protocols.begin() ? '<' : ',') << **I;
> - }
> -
> - if (!Protocols.empty())
> Out << "> ";
> + }
>
> if (OID->ivar_size() > 0) {
> Out << "{\n";
> + eolnOut = true;
> Indentation += Policy.Indentation;
> for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
> E = OID->ivar_end(); I != E; ++I) {
> @@ -977,19 +976,33 @@
> Indentation -= Policy.Indentation;
> Out << "}\n";
> }
> + else if (SID) {
> + Out << "\n";
> + eolnOut = true;
> + }
>
> VisitDeclContext(OID, false);
> + if (!eolnOut)
> + Out << ' ';
> Out << "@end";
> // FIXME: implement the rest...
> }
>
> void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
> if (!PID->isThisDeclarationADefinition()) {
> - Out << "@protocol " << PID->getIdentifier() << ";\n";
> + Out << "@protocol " << *PID << ";\n";
> return;
> }
> -
> - Out << "@protocol " << *PID << '\n';
> + // Protocols?
> + const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols();
> + if (!Protocols.empty()) {
> + Out << "@protocol " << *PID;
> + for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
> + E = Protocols.end(); I != E; ++I)
> + Out << (I == Protocols.begin() ? '<' : ',') << **I;
> + Out << ">\n";
> + } else
> + Out << "@protocol " << *PID << '\n';
> VisitDeclContext(PID, false);
> Out << "@end";
> }
> @@ -1095,7 +1108,9 @@
> (void) first; // Silence dead store warning due to idiomatic code.
> Out << " )";
> }
> - Out << ' ' << PDecl->getType().getAsString(Policy) << ' ' << *PDecl << ';';
> + Out << ' ' << PDecl->getType().getAsString(Policy) << ' ' << *PDecl;
> + if (Policy.PolishForDeclaration)
> + Out << ';';
> }
I don't really understand the motivation behind this condition.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the cfe-commits
mailing list