diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-25 08:06:05 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-25 08:06:05 +0000 |
commit | eaaebc7cf10dc1a2016183a262ad3256bc468759 (patch) | |
tree | 7f1a898c82d6097bdf09e0f9333590a6660f82d3 /lib/Sema/SemaType.cpp | |
parent | 7b3b24ecdf0e41eb6b734e4dd268d0af10874ad0 (diff) |
This is a pretty big cleanup for how invalid decl/type are handle.
This gets rid of a bunch of random InvalidDecl bools in sema, changing
us to use the following approach:
1. When analyzing a declspec or declarator, if an error is found, we
set a bit in Declarator saying that it is invalid.
2. Once the Decl is created by sema, we immediately set the isInvalid
bit on it from what is in the declarator. From this point on, sema
consistently looks at and sets the bit on the decl.
This gives a very clear separation of concerns and simplifies a bunch
of code. In addition to this, this patch makes these changes:
1. it renames DeclSpec::getInvalidType() -> isInvalidType().
2. various "merge" functions no longer return bools: they just set the
invalid bit on the dest decl if invalid.
3. The ActOnTypedefDeclarator/ActOnFunctionDeclarator/ActOnVariableDeclarator
methods now set invalid on the decl returned instead of returning an
invalid bit byref.
4. In SemaType, refering to a typedef that was invalid now propagates the
bit into the resultant type. Stuff declared with the invalid typedef
will now be marked invalid.
5. Various methods like CheckVariableDeclaration now return void and set the
invalid bit on the decl they check.
There are a few minor changes to tests with this, but the only major bad
result is test/SemaCXX/constructor-recovery.cpp. I'll take a look at this
next.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70020 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaType.cpp')
-rw-r--r-- | lib/Sema/SemaType.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 62d2489b34..7519aff630 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -50,7 +50,8 @@ QualType Sema::adjustParameterType(QualType T) { /// \returns The type described by the declaration specifiers, or NULL /// if there was an error. QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, - SourceLocation DeclLoc) { + SourceLocation DeclLoc, + bool &isInvalid) { // FIXME: Should move the logic from DeclSpec::Finish to here for validity // checking. QualType Result; @@ -205,8 +206,15 @@ QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS, DeclLoc = DS.getSourceRange().getBegin(); Diag(DeclLoc, diag::err_invalid_protocol_qualifiers) << DS.getSourceRange(); + isInvalid = true; } } + + // If this is a reference to an invalid typedef, propagate the invalidity. + if (TypedefType *TDT = dyn_cast<TypedefType>(Result)) + if (TDT->getDecl()->isInvalidDecl()) + isInvalid = true; + // TypeQuals handled by caller. break; } @@ -614,9 +622,12 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip) { // the first return statement. T = Context.DependentTy; } else { - T = ConvertDeclSpecToType(DS, D.getIdentifierLoc()); + bool isInvalid = false; + T = ConvertDeclSpecToType(DS, D.getIdentifierLoc(), isInvalid); if (T.isNull()) return T; + if (isInvalid) + D.setInvalidType(true); } break; } |