Resending to right mailing list.

On 10/01/2012 07:19 PM, Enea Zaffanella wrote:
Please review the attached patch, adding source locations for
parentheses in DeclTypeTypeLoc.

Enea.


_______________________________________________
cfe-dev mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


Index: include/clang/Parse/Parser.h
===================================================================
--- include/clang/Parse/Parser.h	(revision 163963)
+++ include/clang/Parse/Parser.h	(working copy)
@@ -486,6 +486,8 @@
       Tok.setAnnotationValue(ER.get());
   }
 
+  typedef std::pair<Expr*, SourceLocation> DecltypeAnnotation;
+
   // If NeedType is true, then TryAnnotateTypeOrScopeToken will try harder to
   // find a type name by attempting typo correction.
   bool TryAnnotateTypeOrScopeToken(bool EnteringContext = false,
Index: include/clang/AST/TypeLoc.h
===================================================================
--- include/clang/AST/TypeLoc.h	(revision 163963)
+++ include/clang/AST/TypeLoc.h	(working copy)
@@ -1435,12 +1435,58 @@
   }
 };
 
-// FIXME: location of the 'decltype' and parens.
-class DecltypeTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
-                                                         DecltypeTypeLoc,
-                                                         DecltypeType> {
+struct DecltypeTypeLocInfo {
+  SourceLocation DecltypeLoc;
+  SourceLocation LParenLoc;
+  SourceLocation RParenLoc;
+};
+
+class DecltypeTypeLoc
+  : public ConcreteTypeLoc<UnqualTypeLoc,
+                           DecltypeTypeLoc,
+                           DecltypeType,
+                           DecltypeTypeLocInfo> {
 public:
   Expr *getUnderlyingExpr() const { return getTypePtr()->getUnderlyingExpr(); }
+
+  SourceLocation getDecltypeLoc() const {
+    return this->getLocalData()->DecltypeLoc;
+  }
+  void setDecltypeLoc(SourceLocation Loc) {
+    this->getLocalData()->DecltypeLoc = Loc;
+  }
+
+  SourceLocation getLParenLoc() const {
+    return this->getLocalData()->LParenLoc;
+  }
+  void setLParenLoc(SourceLocation Loc) {
+    this->getLocalData()->LParenLoc = Loc;
+  }
+
+  SourceLocation getRParenLoc() const {
+    return this->getLocalData()->RParenLoc;
+  }
+  void setRParenLoc(SourceLocation Loc) {
+    this->getLocalData()->RParenLoc = Loc;
+  }
+
+  SourceRange getParensRange() const {
+    return SourceRange(getLParenLoc(), getRParenLoc());
+  }
+  void setParensRange(SourceRange range) {
+      setLParenLoc(range.getBegin());
+      setRParenLoc(range.getEnd());
+  }
+
+  SourceRange getLocalSourceRange() const {
+    return SourceRange(getDecltypeLoc(), getRParenLoc());
+  }
+
+  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
+    setDecltypeLoc(Loc);
+    setLParenLoc(Loc);
+    setRParenLoc(Loc);
+  }
 };
 
 struct UnaryTransformTypeLocInfo {
Index: lib/Sema/TreeTransform.h
===================================================================
--- lib/Sema/TreeTransform.h	(revision 163963)
+++ lib/Sema/TreeTransform.h	(working copy)
@@ -4392,14 +4392,15 @@
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
       E.get() != T->getUnderlyingExpr()) {
-    Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
+    Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
     if (Result.isNull())
       return QualType();
   }
   else E.take();
 
   DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
-  NewTL.setNameLoc(TL.getNameLoc());
+  NewTL.setDecltypeLoc(TL.getDecltypeLoc());
+  NewTL.setParensRange(TL.getParensRange());
 
   return Result;
 }
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp	(revision 163963)
+++ lib/Sema/SemaExprCXX.cpp	(working copy)
@@ -5283,7 +5283,8 @@
 
   TypeLocBuilder TLB;
   DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);
-  DecltypeTL.setNameLoc(DS.getTypeSpecTypeLoc());
+  DecltypeTL.setDecltypeLoc(DS.getTypeSpecTypeLoc());
+  DecltypeTL.setParensRange(DS.getTypeofParensRange());
   TypeSourceInfo *DestructedTypeInfo = TLB.getTypeSourceInfo(Context, T);
   PseudoDestructorTypeStorage Destructed(DestructedTypeInfo);
 
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp	(revision 163963)
+++ lib/Sema/SemaType.cpp	(working copy)
@@ -3088,6 +3088,11 @@
       else
         TL.copy(cast<TemplateSpecializationTypeLoc>(OldTL));
     }
+    void VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
+      assert(DS.getTypeSpecType() == DeclSpec::TST_decltype);
+      TL.setDecltypeLoc(DS.getTypeSpecTypeLoc());
+      TL.setParensRange(DS.getTypeofParensRange());
+    }
     void VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
       assert(DS.getTypeSpecType() == DeclSpec::TST_typeofExpr);
       TL.setTypeofLoc(DS.getTypeSpecTypeLoc());
Index: lib/Sema/SemaCXXScopeSpec.cpp
===================================================================
--- lib/Sema/SemaCXXScopeSpec.cpp	(revision 163963)
+++ lib/Sema/SemaCXXScopeSpec.cpp	(working copy)
@@ -727,7 +727,8 @@
 
   TypeLocBuilder TLB;
   DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);
-  DecltypeTL.setNameLoc(DS.getTypeSpecTypeLoc());
+  DecltypeTL.setDecltypeLoc(DS.getTypeSpecTypeLoc());
+  DecltypeTL.setParensRange(DS.getTypeofParensRange());
   SS.Extend(Context, SourceLocation(), TLB.getTypeLocInContext(Context, T),
             ColonColonLoc);
   return false;
Index: lib/Parse/ParseDeclCXX.cpp
===================================================================
--- lib/Parse/ParseDeclCXX.cpp	(revision 163963)
+++ lib/Parse/ParseDeclCXX.cpp	(working copy)
@@ -659,14 +659,20 @@
 SourceLocation Parser::ParseDecltypeSpecifier(DeclSpec &DS) {
   assert((Tok.is(tok::kw_decltype) || Tok.is(tok::annot_decltype))
            && "Not a decltype specifier");
-  
 
   ExprResult Result;
   SourceLocation StartLoc = Tok.getLocation();
+  SourceLocation LParenLoc;
   SourceLocation EndLoc;
 
   if (Tok.is(tok::annot_decltype)) {
-    Result = getExprAnnotation(Tok);
+    DecltypeAnnotation* Annot = (DecltypeAnnotation*) Tok.getAnnotationValue();
+    if (Annot == 0)
+      Result = ExprResult(true);
+    else {
+      Result = Annot->first;
+      LParenLoc = Annot->second;
+    }
     EndLoc = Tok.getAnnotationEndLoc();
     ConsumeToken();
     if (Result.isInvalid()) {
@@ -715,6 +721,7 @@
       return T.getCloseLocation();
     }
 
+    LParenLoc = T.getOpenLocation();
     EndLoc = T.getCloseLocation();
   }
 
@@ -726,6 +733,8 @@
     Diag(StartLoc, DiagID) << PrevSpec;
     DS.SetTypeSpecError();
   }
+  if (LParenLoc.isValid())
+    DS.setTypeofParensRange(SourceRange(LParenLoc, EndLoc));
   return EndLoc;
 }
 
@@ -739,8 +748,13 @@
     PP.EnterToken(Tok);
 
   Tok.setKind(tok::annot_decltype);
-  setExprAnnotation(Tok, DS.getTypeSpecType() == TST_decltype ? 
-                         DS.getRepAsExpr() : ExprResult());
+  if (DS.getTypeSpecType() != TST_decltype)
+    Tok.setAnnotationValue(0);
+  else {
+    SourceLocation LParenLoc = DS.getTypeofParensRange().getBegin();
+    Tok.setAnnotationValue(new (Actions.Context)
+                           DecltypeAnnotation(DS.getRepAsExpr(), LParenLoc));
+  }
   Tok.setAnnotationEndLoc(EndLoc);
   Tok.setLocation(StartLoc);
   PP.AnnotateCachedTokens(Tok);
Index: lib/Serialization/ASTWriter.cpp
===================================================================
--- lib/Serialization/ASTWriter.cpp	(revision 163963)
+++ lib/Serialization/ASTWriter.cpp	(working copy)
@@ -513,7 +513,9 @@
   Writer.AddTypeSourceInfo(TL.getUnderlyingTInfo(), Record);
 }
 void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
-  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+  Writer.AddSourceLocation(TL.getDecltypeLoc(), Record);
+  Writer.AddSourceLocation(TL.getLParenLoc(), Record);
+  Writer.AddSourceLocation(TL.getRParenLoc(), Record);
 }
 void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
   Writer.AddSourceLocation(TL.getKWLoc(), Record);
Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp	(revision 163963)
+++ lib/Serialization/ASTReader.cpp	(working copy)
@@ -4286,7 +4286,9 @@
   TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx));
 }
 void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
-  TL.setNameLoc(ReadSourceLocation(Record, Idx));
+  TL.setDecltypeLoc(ReadSourceLocation(Record, Idx));
+  TL.setLParenLoc(ReadSourceLocation(Record, Idx));
+  TL.setRParenLoc(ReadSourceLocation(Record, Idx));
 }
 void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
   TL.setKWLoc(ReadSourceLocation(Record, Idx));
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to