On 10/10/2012 01:42 AM, Eli Friedman wrote:
On Tue, Oct 9, 2012 at 8:56 AM, Grzegorz Jablonski <[email protected]> wrote:
Hello,

I have made a few patches fixing some cases from bug 11806. Please review
them. I attach also the testcases for them.
Please attach one patch per email; please include automated testcases
to be added to clang/test/ within each patch.


I have sent it already, but it went to the wrong thread. Do the attachements contain what you expect?

Regards,
Grzegorz Jablonski

Index: lib/AST/DeclPrinter.cpp
===================================================================
--- lib/AST/DeclPrinter.cpp	(revision 165633)
+++ lib/AST/DeclPrinter.cpp	(working copy)
@@ -624,13 +624,15 @@
       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)
+      PrintingPolicy SubPolicy(Policy);
+      SubPolicy.SuppressSpecifiers=false;
+      Init->printPretty(Out, 0, SubPolicy, Indentation);
+      if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
         Out << ")";
     }
   }
Index: lib/AST/Type.cpp
===================================================================
--- lib/AST/Type.cpp	(revision 165633)
+++ lib/AST/Type.cpp	(working copy)
@@ -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";
Index: lib/AST/TypePrinter.cpp
===================================================================
--- lib/AST/TypePrinter.cpp	(revision 165633)
+++ lib/AST/TypePrinter.cpp	(working copy)
@@ -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)) {
Index: lib/AST/StmtPrinter.cpp
===================================================================
--- lib/AST/StmtPrinter.cpp	(revision 165633)
+++ lib/AST/StmtPrinter.cpp	(working copy)
@@ -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));
     }
@@ -1451,10 +1466,12 @@
   if (E->isArrow())
     OS << "->";
   else
-    OS << '.';
+    OS << '.';    
   if (E->getQualifier())
     E->getQualifier()->print(OS, Policy);
-
+  
+  OS << "~";
+  
   std::string TypeS;
   if (IdentifierInfo *II = E->getDestroyedTypeIdentifier())
     OS << II->getName();
// RUN: %clang_cc1 -ast-print %s | FileCheck %s

// CHECK: r;
// CHECK-NEXT: r->method();
struct MyClass
{
    void method() {}
};

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

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

// RUN: %clang_cc1 -ast-print %s | FileCheck %s

// CHECK: if (int a = 1)
// CHECK:  while (int a = 1)
// CHECK:  switch (int a = 1)

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

// RUN: %clang_cc1 -ast-print %s | FileCheck %s

// CHECK: a = unsigned(1);


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


// RUN: %clang_cc1 -ast-print %s | FileCheck %s

// CHECK: new (1) int;


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;
}

// RUN: %clang_cc1 -ast-print %s | FileCheck %s

// CHECK: fun((int &)y);

void fun(int& x);
int main() {
    unsigned int y = 0;
    fun((int&)y);
}
// RUN: %clang_cc1 -ast-print %s | FileCheck %s

// CHECK: S s( 1, 2 );

template <class S> void fun()
{
    S s( 1,2 );
}

// RUN: %clang_cc1 -ast-print %s | FileCheck %s

// CHECK: };
// CHECK-NEXT: E a = A;

struct MyClass
{
    void f()
    {
        enum E { A, B, C };
        E a = A;
    }
};
// RUN: %clang_cc1 -ast-print %s | FileCheck %s

// CHECK: struct S *A = (struct S *)a, *B = (struct S *)b;

struct S;

void fun(const void *a, const void *b)
{
   struct S* A = (struct S*)a, *B = (struct S*)b;
}
// RUN: %clang_cc1 -ast-print %s | FileCheck %s

// CHECK: t.~T();

template <typename T> void func(T t) { t.~T(); }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to