Hello,

I have made a few patches fixing some cases from bug 11806. Please review them. I attach also the testcases for them.

Regards,
Grzegorz Jablonski
--- DeclPrinter.cpp.org	2012-10-09 17:27:05.210062199 +0200
+++ DeclPrinter.cpp	2012-10-09 17:37:59.478074450 +0200
@@ -624,13 +624,13 @@
       ImplicitInit = D->getInitStyle() == VarDecl::CallInit &&
           Construct->getNumArgs() == 0 && !Construct->isListInitialization();
     if (!ImplicitInit) {
-      if (D->getInitStyle() == VarDecl::CallInit)
+      if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
         Out << "(";
       else if (D->getInitStyle() == VarDecl::CInit) {
         Out << " = ";
       }
       Init->printPretty(Out, 0, Policy, Indentation);
-      if (D->getInitStyle() == VarDecl::CallInit)
+      if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
         Out << ")";
     }
   }
struct MyClass
{
    void method() {}
};

struct Reference
{
    MyClass* object;
    MyClass* operator ->() { return object; }
};

int main()
{
    Reference r;
    r->method();
}

void f()
{
    if (int a=1) { }
    while (int a=1) { }
    switch (int a=1) { }
}

void f()
{
    unsigned a = unsigned(1);
}


void *operator new (typeof(sizeof(1)) size, int a, int b=2)
{
    int *p = new int[size];
    p[0] = a;
    p[1] = b;
    return p;
}

void f()
{
    new (1) int;
}

void fun(int& x);
int main() {
    unsigned int y = 0;
    fun((int&)y);
}
template <class S> void fun()
{
    S s(1,2);
}

struct MyClass
{
    void f()
    {
        enum E { A, B, C };
        E a = A;
    }
};
--- StmtPrinter.cpp.org	2012-10-09 17:29:49.762065303 +0200
+++ StmtPrinter.cpp	2012-10-09 17:29:35.902064961 +0200
@@ -61,7 +61,7 @@
 
     void PrintRawCompoundStmt(CompoundStmt *S);
     void PrintRawDecl(Decl *D);
-    void PrintRawDeclStmt(DeclStmt *S);
+    void PrintRawDeclStmt(const DeclStmt *S);
     void PrintRawIfStmt(IfStmt *If);
     void PrintRawCXXCatchStmt(CXXCatchStmt *Catch);
     void PrintCallArgs(CallExpr *E);
@@ -121,8 +121,8 @@
   D->print(OS, Policy, IndentLevel);
 }
 
-void StmtPrinter::PrintRawDeclStmt(DeclStmt *S) {
-  DeclStmt::decl_iterator Begin = S->decl_begin(), End = S->decl_end();
+void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
+  DeclStmt::const_decl_iterator Begin = S->decl_begin(), End = S->decl_end();
   SmallVector<Decl*, 2> Decls;
   for ( ; Begin != End; ++Begin)
     Decls.push_back(*Begin);
@@ -187,6 +187,9 @@
 
 void StmtPrinter::PrintRawIfStmt(IfStmt *If) {
   OS << "if (";
+  if (const DeclStmt *DS = If->getConditionVariableDeclStmt())
+    PrintRawDeclStmt(DS);
+  else
   PrintExpr(If->getCond());
   OS << ')';
 
@@ -224,6 +227,9 @@
 
 void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) {
   Indent() << "switch (";
+  if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
+    PrintRawDeclStmt(DS);
+  else
   PrintExpr(Node->getCond());
   OS << ")";
 
@@ -240,6 +246,9 @@
 
 void StmtPrinter::VisitWhileStmt(WhileStmt *Node) {
   Indent() << "while (";
+  if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
+    PrintRawDeclStmt(DS);
+  else
   PrintExpr(Node->getCond());
   OS << ")\n";
   PrintStmt(Node->getBody());
@@ -927,7 +936,7 @@
   OS << Node->getAccessor().getName();
 }
 void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) {
-  OS << "(" << Node->getType().getAsString(Policy) << ")";
+  OS << "(" << Node->getTypeAsWritten().getAsString(Policy) << ")";
   PrintExpr(Node->getSubExpr());
 }
 void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) {
@@ -1130,15 +1139,20 @@
       PrintExpr(Node->getArg(0));
       OS << ' ' << OpStrings[Kind];
     }
+  }
+  else if (Kind == OO_Arrow) {
+    PrintExpr(Node->getArg(0));
   } else if (Kind == OO_Call) {
     PrintExpr(Node->getArg(0));
     OS << '(';
     for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) {
+      if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
+      {
       if (ArgIdx > 1)
         OS << ", ";
-      if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx)))
         PrintExpr(Node->getArg(ArgIdx));
     }
+    }
     OS << ')';
   } else if (Kind == OO_Subscript) {
     PrintExpr(Node->getArg(0));
@@ -1408,6 +1422,7 @@
     OS << "(";
     PrintExpr(E->getPlacementArg(0));
     for (unsigned i = 1; i < NumPlace; ++i) {
+      if (!isa<CXXDefaultArgExpr>(E->getPlacementArg(i)))
       OS << ", ";
       PrintExpr(E->getPlacementArg(i));
     }
--- Type.cpp.org	2012-10-07 17:28:13.890819415 +0200
+++ Type.cpp	2012-10-09 17:30:07.678065621 +0200
@@ -1486,7 +1486,7 @@
   case Int128:            return "__int128";
   case UChar:             return "unsigned char";
   case UShort:            return "unsigned short";
-  case UInt:              return "unsigned int";
+  case UInt:              return "unsigned";
   case ULong:             return "unsigned long";
   case ULongLong:         return "unsigned long long";
   case UInt128:           return "unsigned __int128";
--- TypePrinter.cpp.org	2012-10-07 17:28:13.000000000 +0200
+++ TypePrinter.cpp	2012-10-09 17:31:29.754067116 +0200
@@ -799,6 +799,8 @@
 /// Appends the given scope to the end of a string.
 void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS) {
   if (DC->isTranslationUnit()) return;
+  if (DC->isFunctionOrMethod()) return;
+  
   AppendScope(DC->getParent(), OS);
 
   if (NamespaceDecl *NS = dyn_cast<NamespaceDecl>(DC)) {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to