]> git.lizzy.rs Git - rust.git/commitdiff
syntax: Allow syntax extensions to have attributes
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Fri, 14 Feb 2014 16:09:51 +0000 (08:09 -0800)
committerErick Tryzelaar <erick.tryzelaar@gmail.com>
Sat, 22 Feb 2014 03:57:02 +0000 (19:57 -0800)
15 files changed:
src/libsyntax/ext/deriving/clone.rs
src/libsyntax/ext/deriving/cmp/eq.rs
src/libsyntax/ext/deriving/cmp/ord.rs
src/libsyntax/ext/deriving/cmp/totaleq.rs
src/libsyntax/ext/deriving/cmp/totalord.rs
src/libsyntax/ext/deriving/decodable.rs
src/libsyntax/ext/deriving/default.rs
src/libsyntax/ext/deriving/encodable.rs
src/libsyntax/ext/deriving/generic.rs
src/libsyntax/ext/deriving/iter_bytes.rs
src/libsyntax/ext/deriving/primitive.rs
src/libsyntax/ext/deriving/rand.rs
src/libsyntax/ext/deriving/show.rs
src/libsyntax/ext/deriving/to_str.rs
src/libsyntax/ext/deriving/zero.rs

index 5595bdee68823b7a08840c2d7c40816a8aac5ea6..f52a2accd8d8266c9de63ccd7deae26f38e697e8 100644 (file)
@@ -21,6 +21,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
                              push: |@Item|) {
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "clone", "Clone"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
@@ -48,6 +49,7 @@ pub fn expand_deriving_deep_clone(cx: &mut ExtCtxt,
                                   push: |@Item|) {
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "clone", "DeepClone"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
index 6592dc97f348eb3dbf6e5daaa8805cf77ab64f9c..b031f69084d33201c9bca5b6ac2228426fa408d1 100644 (file)
@@ -47,6 +47,7 @@ macro_rules! md (
 
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "cmp", "Eq"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
index c41986fceef64ad546b3a72e8cda6ebc4c27f6fa..10a416045cbda7cb0899c31faa9599f18030b55c 100644 (file)
@@ -37,6 +37,7 @@ macro_rules! md (
 
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "cmp", "Ord"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
index 63e13b492020dc32506a994e62ee133257a3dd6f..2bfab8646a6aa211e47a0953c3365ac164ae8fda 100644 (file)
@@ -26,6 +26,7 @@ fn cs_equals(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
 
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "cmp", "TotalEq"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
index 3e58d2edb29603e5763c53f3d02897e1627908b2..2e6c4a5422892c348d2abd38faf3f901ca06765a 100644 (file)
@@ -23,6 +23,7 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
                                 push: |@Item|) {
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "cmp", "TotalOrd"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
index 8b20813e344063cfc5c86d679918bf0de2b83cc1..623e8ef766c698159f8ea01dd514eda22a04e1eb 100644 (file)
@@ -28,6 +28,7 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
                                  push: |@Item|) {
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new_(~["serialize", "Decodable"], None,
                          ~[~Literal(Path::new_local("__D"))], true),
         additional_bounds: ~[],
index 7ed27168bb60612632e65ebc25e0c510265d3f81..c5ef86273b65a38bb0f78d313fc9d61075fd7a97 100644 (file)
@@ -21,6 +21,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
                             push: |@Item|) {
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "default", "Default"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
index 9e0439e5375c9834d60692c6b8209f0307530ca8..2bc661ff27a4513b7d5b7c25591b02191d3c35aa 100644 (file)
@@ -95,6 +95,7 @@ pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
                                  push: |@Item|) {
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new_(~["serialize", "Encodable"], None,
                          ~[~Literal(Path::new_local("__E"))], true),
         additional_bounds: ~[],
index fb7f9b74364b6432f6b52a8cc12eaafc104f1fd9..a3bef1b5eddcb0a274cbe3b30b3ae06552701ea9 100644 (file)
@@ -196,6 +196,8 @@ pub struct TraitDef<'a> {
     /// The span for the current #[deriving(Foo)] header.
     span: Span,
 
+    attributes: ~[ast::Attribute],
+
     /// Path of the trait, including any type parameters
     path: Path<'a>,
 
@@ -355,7 +357,8 @@ pub fn expand(&self,
      */
     fn create_derived_impl(&self,
                            cx: &mut ExtCtxt,
-                           type_ident: Ident, generics: &Generics,
+                           type_ident: Ident,
+                           generics: &Generics,
                            methods: ~[@ast::Method]) -> @ast::Item {
         let trait_path = self.path.to_path(cx, self.span, type_ident, generics);
 
@@ -408,16 +411,16 @@ fn create_derived_impl(&self,
         cx.item(
             self.span,
             ident,
-            ~[doc_attr],
+            vec::append(~[doc_attr], self.attributes),
             ast::ItemImpl(trait_generics, opt_trait_ref,
                           self_type, methods.map(|x| *x)))
     }
 
-    fn expand_struct_def(&self,
-                         cx: &mut ExtCtxt,
-                         struct_def: &StructDef,
-                         type_ident: Ident,
-                         generics: &Generics) -> @ast::Item {
+    pub fn expand_struct_def(&self,
+                             cx: &mut ExtCtxt,
+                             struct_def: &StructDef,
+                             type_ident: Ident,
+                             generics: &Generics) -> @ast::Item {
         let methods = self.methods.map(|method_def| {
             let (explicit_self, self_args, nonself_args, tys) =
                 method_def.split_self_nonself_args(
@@ -447,7 +450,7 @@ fn expand_struct_def(&self,
         self.create_derived_impl(cx, type_ident, generics, methods)
     }
 
-    fn expand_enum_def(&self,
+    pub fn expand_enum_def(&self,
                        cx: &mut ExtCtxt,
                        enum_def: &EnumDef,
                        type_ident: Ident,
index b1adf96b90af8957a4aa5ae41f86e59d0ce36a5d..b39e22bc1adc65f88e1113b67c126e01d372d157 100644 (file)
@@ -22,6 +22,7 @@ pub fn expand_deriving_iter_bytes(cx: &mut ExtCtxt,
                                   push: |@Item|) {
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "to_bytes", "IterBytes"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
index 9391c9cd23c7400e912eacdef606baff32a4fa71..03192cc1cd2f20952052d1d8ced53aca925e8db2 100644 (file)
@@ -23,6 +23,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
                                       push: |@Item|) {
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "num", "FromPrimitive"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
index 351264fed72af051efd51dafe1c7624715323a7c..6efe48015928058938f1618ca41dda4e913c6e5b 100644 (file)
@@ -23,6 +23,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt,
                             push: |@Item|) {
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "rand", "Rand"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
index d5b08503fd03ef623e00331b569cabfaa2521929..56493000a92a37281afec146b17a5fd833649c11 100644 (file)
@@ -31,6 +31,7 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt,
 
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "fmt", "Show"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
index b1c8e62935bdde46c5e803e29b42b1c78d273a51..5cb81d9e762ae7074db533a274f5edb7c100e666 100644 (file)
@@ -24,6 +24,7 @@ pub fn expand_deriving_to_str(cx: &mut ExtCtxt,
                               push: |@Item|) {
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "to_str", "ToStr"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),
index 924ab3c9e0020c4f2df93be6ab90ddc6c79061e1..90f4fa0eb5897672ba83c557fd0d9241dfd4007e 100644 (file)
@@ -21,6 +21,7 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt,
                             push: |@Item|) {
     let trait_def = TraitDef {
         span: span,
+        attributes: ~[],
         path: Path::new(~["std", "num", "Zero"]),
         additional_bounds: ~[],
         generics: LifetimeBounds::empty(),