From cf258bf4e5148723940cc757ec032b5aff814f1e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 11 Mar 2015 08:16:10 +0100 Subject: [PATCH] fix(build): fixes to help more projects to build Involving * complete list of reserved words (keywords in Rust) * use namespace for otherwise clashing types in cmn::, io:: --- src/mako/lib.rs.mako | 3 +-- src/mako/lib/mbuild.mako | 10 +++++----- src/mako/lib/rbuild.mako | 2 +- src/mako/lib/util.py | 13 ++++++++++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/mako/lib.rs.mako b/src/mako/lib.rs.mako index c5cefb6979..b9cd0d6e65 100644 --- a/src/mako/lib.rs.mako +++ b/src/mako/lib.rs.mako @@ -41,8 +41,7 @@ use std::io; use std::fs; use std::collections::BTreeMap; -pub use cmn::{Hub, ReadSeek, ResourceMethodsBuilder, MethodBuilder, Resource, Part, ResponseResult, RequestValue, - NestedType, Delegate, DefaultDelegate, Result}; +pub use cmn::{Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate}; // ############## diff --git a/src/mako/lib/mbuild.mako b/src/mako/lib/mbuild.mako index b7dda45d33..227ac3b6e9 100644 --- a/src/mako/lib/mbuild.mako +++ b/src/mako/lib/mbuild.mako @@ -103,7 +103,7 @@ pub struct ${ThisType} % endif } -impl${mb_tparams} MethodBuilder for ${ThisType} {} +impl${mb_tparams} cmn::MethodBuilder for ${ThisType} {} impl${mb_tparams} ${ThisType} where ${', '.join(mb_type_bounds())} { @@ -322,11 +322,11 @@ ${'.' + action_name | indent_by(13)}(${action_args}); where = '' qualifier = 'pub ' add_args = '' - rtype = 'Result<()>' + rtype = 'cmn::Result<()>' response_schema = method_response(schemas, c, m) if response_schema: - rtype = 'Result<%s>' % (response_schema.id) + rtype = 'cmn::Result<%s>' % (response_schema.id) if media_params: stripped = lambda s: s.strip().strip(',') @@ -377,7 +377,7 @@ ${'.' + action_name | indent_by(13)}(${action_args}); ## Additional params - may not overlap with optional params for &field in [${', '.join(enclose_in('"', (p.name for p in field_params)))}].iter() { if ${paddfields}.contains_key(field) { - return Result::FieldClash(field); + return cmn::Result::FieldClash(field); } } for (name, value) in ${paddfields}.iter() { @@ -432,7 +432,7 @@ else { ## return RequestResult::Error(err); ## } - Result::Success(response) + cmn::Result::Success(response) } % for p in media_params: diff --git a/src/mako/lib/rbuild.mako b/src/mako/lib/rbuild.mako index 95c8f40185..7c7368ddbf 100644 --- a/src/mako/lib/rbuild.mako +++ b/src/mako/lib/rbuild.mako @@ -45,7 +45,7 @@ pub struct ${ThisType} hub: &'a ${hub_type_name}${hub_type_params_s()}, } -impl${rb_params} ResourceMethodsBuilder for ${ThisType} {} +impl${rb_params} cmn::ResourceMethodsBuilder for ${ThisType} {} ## Builder Creators Methods #################### impl${rb_params} ${ThisType} { diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index ceaf12231d..cebeae7348 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -24,6 +24,13 @@ TYPE_MAP = {'boolean' : 'bool', 'string' : 'String', 'object' : 'HashMap'} +RESERVED_WORDS = set(('abstract', 'alignof', 'as', 'become', 'box', 'break', 'const', 'continue', 'crate', 'do', + 'else', 'enum', 'extern', 'false', 'final', 'fn', 'for', 'if', 'impl', 'in', 'let', 'loop', + 'macro', 'match', 'mod', 'move', 'mut', 'offsetof', 'override', 'priv', 'pub', 'pure', 'ref', + 'return', 'sizeof', 'static', 'self', 'struct', 'super', 'true', 'trait', 'type', 'typeof', + 'unsafe', 'unsized', 'use', 'virtual', 'where', 'while', 'yield')) + + _words = [w.strip(',') for w in "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.".split(' ')] RUST_TYPE_RND_MAP = {'bool': lambda: str(bool(randint(0, 1))).lower(), 'u32' : lambda: randint(0, 100), @@ -246,8 +253,8 @@ def nested_type_name(sn, pn): # Make properties which are reserved keywords usable def mangle_ident(n): - n = '_'.join(singular(w) for w in camel_to_under(n).split('.')) - if n in ('type', 'where', 'override', 'move'): + n = camel_to_under(n).replace('-', '.').replace('.', '') + if n in RESERVED_WORDS: return n + '_' return n @@ -352,7 +359,7 @@ def schema_markers(s, c): # it should have at least one activity that matches it's type to qualify for the Resource trait for fqan, iot in activities.iteritems(): if activity_name_to_type_name(activity_split(fqan)[1]).lower() == s.id.lower(): - res.add('Resource') + res.add('cmn::Resource') if IO_RESPONSE in iot: res.add('ResponseResult') if IO_REQUEST in iot: