From 98869357e2322476ab00ddf36b16f3c93f9b6e15 Mon Sep 17 00:00:00 2001 From: inglorion Date: Fri, 30 Dec 2011 19:25:29 -0800 Subject: [PATCH] Moved features and has_feature? from Voodoo module into code generator API --- lib/voodoo.rb | 26 -------------------------- lib/voodoo/generators/common_code_generator.rb | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/lib/voodoo.rb b/lib/voodoo.rb index 01c8572..e74f33c 100644 --- a/lib/voodoo.rb +++ b/lib/voodoo.rb @@ -71,30 +71,4 @@ require 'voodoo/parser' # module Voodoo - @features = { - :voodoo => 1, - }.freeze - - module_function - - # Returns a hash describing the features supported by this Voodoo - # implementation. Features defined by the Voodoo specification - # have names not starting in 'x-', whereas extensions to the - # standard start in 'x-'. Each feature has a version, where a - # higher version number indicates compatibility with older versions; - # i.e. if the indicated version is 2, then both version 1 and 2 - # are supported. - def features - @features - end - - # Tests if this Voodoo implementation supports the named feature. - # The optional version argument can be used to test for a specific - # version of the feature. In that case, the tests succeeds if the - # supported version is equal to or greater than the requested - # version. - def has_feature? name, version = 1 - v = @features[name] - v != nil && v >= version - end end diff --git a/lib/voodoo/generators/common_code_generator.rb b/lib/voodoo/generators/common_code_generator.rb index df8e723..b4f41ef 100644 --- a/lib/voodoo/generators/common_code_generator.rb +++ b/lib/voodoo/generators/common_code_generator.rb @@ -43,6 +43,9 @@ module Voodoo @top_level = Environment.initial_environment @environment = @top_level @output_file_suffix = '.o' + @features = { + :voodoo => "1.0" # Voodoo language version + } end # Adds code to the given section. @@ -158,6 +161,14 @@ module Voodoo end end + # Returns a hash describing the features supported by this code generator. + # The keys in this hash are the names of the supported features. + # The associated values are strings providing additional information about + # the feature, such as a version number. + def features + @features + end + # Add a function to the current section def function formals, *code begin_function *formals @@ -175,6 +186,12 @@ module Voodoo @sections[real_section_name(@section)] << code end + # Returns true if a feature is supported by this generator, + # false otherwise. + def has_feature? name + @features.has_key? name + end + # Get the real name of a section. # Given a section name which may be an alias, this method returns the # real name of the section. -- 2.11.4.GIT