[cfe-commits] [PATCH] Revert predefined tracking
Jordan Rose
jordan_rose at apple.com
Tue Jun 19 08:59:40 PDT 2012
Looks good to me now, go ahead and commit!
(We still do have top-level declarations in the predefines for MS mode and ARC-under-libstdc++, but both of those are C++-only so this change shouldn't break anything.)
On Jun 19, 2012, at 8:54 , Meador Inge <meadori at codesourcery.com> wrote:
>
> On Jun 18, 2012, at 12:26 PM, Jordan Rose wrote:
>
>> Hi, Meador. Now that we don't need two loops, I think it would be cleaner to use an explicit if for the first decl, then a do-while loop to process them all. That way the WarnOnEmptyTU flag goes away. (But don't forget to only warn in non-C++ mode.)
>
>
> Ah, great point. So something more like (we still need a flag in spirit for the preprocessed header check):
>
> Index: lib/Parse/ParseAST.cpp
> ===================================================================
> --- lib/Parse/ParseAST.cpp (revision 158702)
> +++ lib/Parse/ParseAST.cpp (working copy)
> @@ -83,46 +83,24 @@
> // declaration. C++ doesn't have this restriction. We also don't want to
> // complain if we have a precompiled header, although technically if the PCH
> // is empty we should still emit the (pedantic) diagnostic.
> - bool WarnForEmptyTU = !S.getLangOpts().CPlusPlus;
> - if (ExternalASTSource *External = S.getASTContext().getExternalSource()) {
> - External->StartTranslationUnit(Consumer);
> - WarnForEmptyTU = false;
> - }
> -
> - // Clang's predefines contain top-level declarations for things like va_list,
> - // making it hard to tell if the /user's/ translation unit has at least one
> - // top-level declaration. So we parse cautiously, looking for a declaration
> - // that doesn't come from our predefines.
> - // Note that ParseTopLevelDecl returns 'true' at EOF.
> - SourceManager &SM = S.getSourceManager();
> Parser::DeclGroupPtrTy ADecl;
> - while (WarnForEmptyTU && !P.ParseTopLevelDecl(ADecl)) {
> - if (ADecl) {
> - if (!Consumer->HandleTopLevelDecl(ADecl.get()))
> - return;
> - if (DeclGroupRef::iterator FirstDecl = ADecl.get().begin()) {
> - SourceLocation DeclLoc = (*FirstDecl)->getLocation();
> - WarnForEmptyTU = SM.isFromPredefines(DeclLoc);
> - }
> - }
> - }
> + ExternalASTSource *External = S.getASTContext().getExternalSource();
> + if (External)
> + External->StartTranslationUnit(Consumer);
>
> - // If we ended up seeing EOF before any top-level declarations, emit our
> - // diagnostic. Otherwise, parse the rest of the file normally.
> - if (WarnForEmptyTU) {
> - P.Diag(diag::ext_empty_translation_unit);
> + if (P.ParseTopLevelDecl(ADecl)) {
> + if (!External && !S.getLangOpts().CPlusPlus)
> + P.Diag(diag::ext_empty_translation_unit);
> } else {
> - while (!P.ParseTopLevelDecl(ADecl)) { // Not end of file.
> + do {
> // If we got a null return and something *was* parsed, ignore it. This
> // is due to a top-level semicolon, an action override, or a parse error
> // skipping something.
> - if (ADecl) {
> - if (!Consumer->HandleTopLevelDecl(ADecl.get()))
> - return;
> - }
> - };
> + if (ADecl && !Consumer->HandleTopLevelDecl(ADecl.get()))
> + return;
> + } while (!P.ParseTopLevelDecl(ADecl));
> }
> -
> +
> // Process any TopLevelDecls generated by #pragma weak.
> for (SmallVector<Decl*,2>::iterator
> I = S.WeakTopLevelDecls().begin(),
>
>
> Meador Inge
> CodeSourcery / Mentor Embedded
> http://www.mentor.com/embedded-software
>
More information about the cfe-commits
mailing list