diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-03-26 23:56:24 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-03-26 23:56:24 +0000 |
commit | 3507369940bfb269551bfa1fec812481f60e3552 (patch) | |
tree | d8e1877f69616116bfa635c531a08134fc48aa7e /lib | |
parent | ab452ba8323d1985e08bade2bced588cddf2cc28 (diff) |
Simplify CXXScopeSpec a lot. No more weird SmallVector-like hacks here
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67800 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Parse/DeclSpec.cpp | 61 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 3 | ||||
-rw-r--r-- | lib/Parse/ParseExprCXX.cpp | 9 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaCXXScopeSpec.cpp | 8 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaType.cpp | 2 |
7 files changed, 14 insertions, 77 deletions
diff --git a/lib/Parse/DeclSpec.cpp b/lib/Parse/DeclSpec.cpp index 72ac3112f9..94799c3200 100644 --- a/lib/Parse/DeclSpec.cpp +++ b/lib/Parse/DeclSpec.cpp @@ -24,67 +24,6 @@ static DiagnosticBuilder Diag(Diagnostic &D, SourceLocation Loc, return D.Report(FullSourceLoc(Loc, SrcMgr), DiagID); } -/// \brief Double the capacity of this scope specifier. -void CXXScopeSpec::reallocate() { - Action::CXXScopeTy **Data = new Action::CXXScopeTy *[Capacity * 2]; - - Action::CXXScopeTy **From - = Capacity == 4? &InlineScopeReps[0] : ManyScopeReps; - std::memcpy(Data, From, Capacity * sizeof(Action::CXXScopeTy *)); - - if (Capacity > 4) - delete [] ManyScopeReps; - ManyScopeReps = Data; - Capacity *= 2; -} - -CXXScopeSpec::CXXScopeSpec(const CXXScopeSpec &SS) - : Range(SS.Range), NumScopeReps(SS.NumScopeReps), Capacity(SS.Capacity) { - - if (Capacity > 4) { - ManyScopeReps = new Action::CXXScopeTy *[Capacity]; - memcpy(ManyScopeReps, SS.ManyScopeReps, - Capacity * sizeof(Action::CXXScopeTy *)); - } else { - memcpy(InlineScopeReps, SS.InlineScopeReps, - Capacity * sizeof(Action::CXXScopeTy *)); - } -} - -CXXScopeSpec &CXXScopeSpec::operator=(const CXXScopeSpec &SS) { - // FIXME: Does not provide the strong exception safety guarantee. - this->~CXXScopeSpec(); - new (this) CXXScopeSpec(SS); - return *this; -} - -void *CXXScopeSpec::buildAnnotationData() const { - uintptr_t *Data = (uintptr_t *)malloc(sizeof(uintptr_t) * (size() + 1)); - Data[0] = size(); - for (unsigned I = 0; I < size(); ++I) - Data[I + 1] = reinterpret_cast<uintptr_t>(getScopeRep(I)); - return Data; -} - -void CXXScopeSpec::setFromAnnotationData(void *DataIn) { - uintptr_t *Data = static_cast<uintptr_t *>(DataIn); - NumScopeReps = *Data; - - // Allocate enough space for the annotation data. - if (NumScopeReps > Capacity) { - if (Capacity > 4) - delete [] ManyScopeReps; - - Capacity = NumScopeReps; - ManyScopeReps = new Action::CXXScopeTy *[Capacity]; - } - - if (Capacity > 4) - std::memcpy(ManyScopeReps, Data + 1, sizeof(uintptr_t) * NumScopeReps); - else - std::memcpy(InlineScopeReps, Data + 1, sizeof(uintptr_t) * NumScopeReps); -} - /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. /// "TheDeclarator" is the declarator that this will be added to. DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, bool isVariadic, diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 7a92171908..a9fbbbe498 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -515,7 +515,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, goto DoneWithDeclSpec; CXXScopeSpec SS; - SS.setFromAnnotationData(Tok.getAnnotationValue()); + SS.setScopeRep(Tok.getAnnotationValue()); SS.setRange(Tok.getAnnotationRange()); // If the next token is the name of the class type that the C++ scope @@ -532,7 +532,6 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, if (TypeRep == 0) goto DoneWithDeclSpec; - CXXScopeSpec::freeAnnotationData(Tok.getAnnotationValue()); ConsumeToken(); // The C++ scope. isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 731f4c7957..b3ec24f864 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -36,8 +36,7 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS) { "Call sites of this function should be guarded by checking for C++"); if (Tok.is(tok::annot_cxxscope)) { - SS.setFromAnnotationData(Tok.getAnnotationValue()); - CXXScopeSpec::freeAnnotationData(Tok.getAnnotationValue()); + SS.setScopeRep(Tok.getAnnotationValue()); SS.setRange(Tok.getAnnotationRange()); ConsumeToken(); return true; @@ -54,7 +53,7 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS) { // '::' - Global scope qualifier. SourceLocation CCLoc = ConsumeToken(); SS.setBeginLoc(CCLoc); - SS.addScopeRep(Actions.ActOnCXXGlobalScopeSpecifier(CurScope, CCLoc)); + SS.setScopeRep(Actions.ActOnCXXGlobalScopeSpecifier(CurScope, CCLoc)); SS.setEndLoc(CCLoc); HasScopeSpecifier = true; } @@ -80,7 +79,7 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS) { if (SS.isInvalid()) continue; - SS.addScopeRep( + SS.setScopeRep( Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, *II)); SS.setEndLoc(CCLoc); continue; @@ -165,7 +164,7 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS) { HasScopeSpecifier = true; } - SS.addScopeRep( + SS.setScopeRep( Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, TypeToken.getAnnotationValue(), TypeToken.getAnnotationRange(), diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 7a221d007c..5ce8b3dbcd 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -866,7 +866,7 @@ bool Parser::TryAnnotateTypeOrScopeToken() { else PP.EnterToken(Tok); Tok.setKind(tok::annot_cxxscope); - Tok.setAnnotationValue(SS.buildAnnotationData()); + Tok.setAnnotationValue(SS.getScopeRep()); Tok.setAnnotationRange(SS.getRange()); // In case the tokens were cached, have Preprocessor replace them with the @@ -898,7 +898,7 @@ bool Parser::TryAnnotateCXXScopeToken() { else PP.EnterToken(Tok); Tok.setKind(tok::annot_cxxscope); - Tok.setAnnotationValue(SS.buildAnnotationData()); + Tok.setAnnotationValue(SS.getScopeRep()); Tok.setAnnotationRange(SS.getRange()); // In case the tokens were cached, have Preprocessor replace them with the diff --git a/lib/Sema/SemaCXXScopeSpec.cpp b/lib/Sema/SemaCXXScopeSpec.cpp index ca864a2a2e..8fb2811ce5 100644 --- a/lib/Sema/SemaCXXScopeSpec.cpp +++ b/lib/Sema/SemaCXXScopeSpec.cpp @@ -25,7 +25,7 @@ DeclContext *Sema::computeDeclContext(const CXXScopeSpec &SS) { return 0; NestedNameSpecifier *NNS - = static_cast<NestedNameSpecifier *>(SS.getCurrentScopeRep()); + = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); if (NNS->isDependent()) return 0; @@ -57,7 +57,7 @@ bool Sema::isDependentScopeSpecifier(const CXXScopeSpec &SS) { return false; NestedNameSpecifier *NNS - = static_cast<NestedNameSpecifier *>(SS.getCurrentScopeRep()); + = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); return NNS->isDependent(); } @@ -111,7 +111,7 @@ Sema::CXXScopeTy *Sema::ActOnCXXNestedNameSpecifier(Scope *S, SourceLocation CCLoc, IdentifierInfo &II) { NestedNameSpecifier *Prefix - = static_cast<NestedNameSpecifier *>(SS.getCurrentScopeRep()); + = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); // If the prefix is already dependent, there is no name lookup to // perform. Just build the resulting nested-name-specifier. @@ -173,7 +173,7 @@ Sema::CXXScopeTy *Sema::ActOnCXXNestedNameSpecifier(Scope *S, SourceRange TypeRange, SourceLocation CCLoc) { NestedNameSpecifier *Prefix - = static_cast<NestedNameSpecifier *>(SS.getCurrentScopeRep()); + = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); return NestedNameSpecifier::Create(Context, Prefix, /*FIXME:*/false, QualType::getFromOpaquePtr(Ty).getTypePtr()); } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 288b617191..92a4de08e4 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -442,7 +442,7 @@ Sema::BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc, if (SS && !SS->isEmpty()) { return new (Context) QualifiedDeclRefExpr(D, Ty, Loc, TypeDependent, ValueDependent, SS->getRange(), - static_cast<NestedNameSpecifier *>(SS->getCurrentScopeRep())); + static_cast<NestedNameSpecifier *>(SS->getScopeRep())); } else return new (Context) DeclRefExpr(D, Ty, Loc, TypeDependent, ValueDependent); } @@ -617,7 +617,7 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc, if (SS && isDependentScopeSpecifier(*SS)) { return Owned(new (Context) UnresolvedDeclRefExpr(Name, Context.DependentTy, Loc, SS->getRange(), - static_cast<NestedNameSpecifier *>(SS->getCurrentScopeRep()))); + static_cast<NestedNameSpecifier *>(SS->getScopeRep()))); } LookupResult Lookup = LookupParsedName(S, SS, Name, LookupOrdinaryName, diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 0780ad8f4a..f14eb65203 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -1102,6 +1102,6 @@ QualType Sema::getQualifiedNameType(const CXXScopeSpec &SS, QualType T) { return T; NestedNameSpecifier *NNS - = static_cast<NestedNameSpecifier *>(SS.getCurrentScopeRep()); + = static_cast<NestedNameSpecifier *>(SS.getScopeRep()); return Context.getQualifiedNameType(NNS, T); } |