[cfe-commits] r82423 - in /cfe/trunk: lib/CodeGen/Mangle.cpp test/CodeGenCXX/mangle.cpp

Anders Carlsson andersca at mac.com
Sun Sep 20 18:21:10 PDT 2009


Author: andersca
Date: Sun Sep 20 20:21:10 2009
New Revision: 82423

URL: http://llvm.org/viewvc/llvm-project?rev=82423&view=rev
Log:
Start mangling expressions.

Modified:
    cfe/trunk/lib/CodeGen/Mangle.cpp
    cfe/trunk/test/CodeGenCXX/mangle.cpp

Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=82423&r1=82422&r2=82423&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Sun Sep 20 20:21:10 2009
@@ -96,7 +96,7 @@
     void mangleType(const TagType*);
     void mangleBareFunctionType(const FunctionType *T,
                                 bool MangleReturnType);
-    void mangleExpression(Expr *E);
+    void mangleExpression(const Expr *E);
     void mangleCXXCtorType(CXXCtorType T);
     void mangleCXXDtorType(CXXDtorType T);
 
@@ -917,8 +917,41 @@
   mangleType(QualType(T->getBaseType(), 0));
 }
 
-void CXXNameMangler::mangleExpression(Expr *E) {
-  assert(false && "Cannot mangle expressions yet");
+void CXXNameMangler::mangleExpression(const Expr *E) {
+  // <expression> ::= <unary operator-name> <expression>
+	//              ::= <binary operator-name> <expression> <expression>
+	//              ::= <trinary operator-name> <expression> <expression> <expression>
+  //              ::= cl <expression>* E	        # call
+  //              ::= cv <type> expression           # conversion with one argument
+  //              ::= cv <type> _ <expression>* E # conversion with a different number of arguments
+  //              ::= st <type>		        # sizeof (a type)
+  //              ::= at <type>                      # alignof (a type)
+  //              ::= <template-param>
+  //              ::= <function-param>
+  //              ::= sr <type> <unqualified-name>                   # dependent name
+  //              ::= sr <type> <unqualified-name> <template-args>   # dependent template-id
+  //              ::= sZ <template-param>                            # size of a parameter pack
+	//              ::= <expr-primary>
+  switch (E->getStmtClass()) {
+  default: assert(false && "Unhandled expression kind!");
+  case Expr::DeclRefExprClass: {
+    const Decl *D = cast<DeclRefExpr>(E)->getDecl();
+    
+    switch (D->getKind()) {
+    default: assert(false && "Unhandled decl kind!");
+    case Decl::NonTypeTemplateParm: {
+      const NonTypeTemplateParmDecl *PD = cast<NonTypeTemplateParmDecl>(D);
+      
+      if (PD->getIndex() == 0)
+        Out << "T_";
+      else
+        Out << 'T' << (PD->getIndex() - 1) << '_';
+      break;
+    }
+
+    }
+  }
+  }
 }
 
 // FIXME: <type> ::= G <type>   # imaginary (C 2000)
@@ -997,6 +1030,11 @@
   case TemplateArgument::Type:
     mangleType(A.getAsType());
     break;
+  case TemplateArgument::Expression:
+    Out << 'X';
+    mangleExpression(A.getAsExpr());
+    Out << 'E';
+    break;
   case TemplateArgument::Integral:
     //  <expr-primary> ::= L <type> <value number> E # integer literal
 

Modified: cfe/trunk/test/CodeGenCXX/mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle.cpp?rev=82423&r1=82422&r2=82423&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle.cpp Sun Sep 20 20:21:10 2009
@@ -99,7 +99,7 @@
   template<typename T> void ft1(T) { }
 }
 
-void g() {
+void g1() {
   // CHECK: @_Z3ft1IidEvT0_T_
   ft1<int, double>(1, 0);
   
@@ -113,6 +113,18 @@
   NS::ft1<int>(1);
 }
 
+// Expressions
+template<int I> struct S5 { };
+
+template<int I> void ft4(S5<I>) { }
+void g2() {
+  // CHECK: @_Z3ft4ILi10EEv2S5IXT_EE
+  ft4(S5<10>());
+  
+  // CHECK: @_Z3ft4ILi20EEv2S5IXT_EE
+  ft4(S5<20>());
+}
+
 extern "C++" {
   // CHECK: @_Z1hv
  void h() { } 





More information about the cfe-commits mailing list