]> git.lizzy.rs Git - rust.git/commitdiff
librustc: Add export_name attribute to specify symbol name.
authorLuqman Aden <laden@csclub.uwaterloo.ca>
Sat, 31 Aug 2013 17:23:31 +0000 (13:23 -0400)
committerLuqman Aden <laden@csclub.uwaterloo.ca>
Sat, 31 Aug 2013 17:23:31 +0000 (13:23 -0400)
src/librustc/middle/trans/base.rs

index 1dc30d2221da897d53b4afb9882eba90515c12a1..a5cbb1cfe1df49fd08c1cae05537e60d67a4a06e 100644 (file)
@@ -2453,10 +2453,16 @@ pub fn item_path(ccx: &CrateContext, id: &ast::NodeId) -> path {
 }
 
 fn exported_name(ccx: @mut CrateContext, path: path, ty: ty::t, attrs: &[ast::Attribute]) -> ~str {
-    if attr::contains_name(attrs, "no_mangle") {
-        path_elt_to_str(*path.last(), token::get_ident_interner())
-    } else {
-        mangle_exported_name(ccx, path, ty)
+    match attr::first_attr_value_str_by_name(attrs, "export_name") {
+        // Use provided name
+        Some(name) => name.to_owned(),
+
+        // Don't mangle
+        _ if attr::contains_name(attrs, "no_mangle")
+            => path_elt_to_str(*path.last(), token::get_ident_interner()),
+
+        // Usual name mangling
+        _ => mangle_exported_name(ccx, path, ty)
     }
 }