diff options
Diffstat (limited to 'lib/puppet/parser/ast')
-rw-r--r-- | lib/puppet/parser/ast/compdef.rb | 2 | ||||
-rw-r--r-- | lib/puppet/parser/ast/component.rb | 12 | ||||
-rw-r--r-- | lib/puppet/parser/ast/hostclass.rb | 16 | ||||
-rw-r--r-- | lib/puppet/parser/ast/node.rb | 16 | ||||
-rw-r--r-- | lib/puppet/parser/ast/nodedef.rb | 2 |
5 files changed, 35 insertions, 13 deletions
diff --git a/lib/puppet/parser/ast/compdef.rb b/lib/puppet/parser/ast/compdef.rb index f1b947ec4..e5758d6f0 100644 --- a/lib/puppet/parser/ast/compdef.rb +++ b/lib/puppet/parser/ast/compdef.rb @@ -9,7 +9,7 @@ class Puppet::Parser::AST # encounter an error if the component is instantiated more than # once. class CompDef < AST::Branch - attr_accessor :type, :args, :code, :keyword + attr_accessor :type, :args, :code, :keyword, :scope def each [@type,@args,@code].each { |child| yield child } diff --git a/lib/puppet/parser/ast/component.rb b/lib/puppet/parser/ast/component.rb index 50e8df5a8..5cf3f5c57 100644 --- a/lib/puppet/parser/ast/component.rb +++ b/lib/puppet/parser/ast/component.rb @@ -19,7 +19,13 @@ class Puppet::Parser::AST objname = hash[:name] arguments = hash[:arguments] || {} - scope = origscope.newscope( + pscope = origscope + #pscope = if ! Puppet[:lexical] or hash[:asparent] == false + # origscope + #else + # @scope + #end + scope = pscope.newscope( :type => @type, :name => objname, :keyword => self.keyword @@ -32,17 +38,13 @@ class Puppet::Parser::AST end @scope = scope - # Additionally, add a tag for whatever kind of class # we are scope.tag(@type) unless objname.nil? - #Puppet.info "tagging with %s" % objname.inspect scope.tag(objname) end - #scope.base = self.class.name - # define all of the arguments in our local scope if self.args diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb index 85beecfe7..7f381db2a 100644 --- a/lib/puppet/parser/ast/hostclass.rb +++ b/lib/puppet/parser/ast/hostclass.rb @@ -14,8 +14,15 @@ class Puppet::Parser::AST # Verify that we haven't already been evaluated # FIXME The second subclass won't evaluate the parent class # code at all, and any overrides will throw an error. - if scope.lookupclass(self.object_id) + if myscope = scope.lookupclass(self.object_id) Puppet.debug "%s class already evaluated" % @type + + # Not used, but will eventually be used to fix #140. + if myscope.is_a? Puppet::Parser::Scope + unless scope.object_id == myscope.object_id + #scope.parent = myscope + end + end return nil end @@ -55,9 +62,14 @@ class Puppet::Parser::AST :type => @type, :name => objname, # might be nil :newcontext => newcontext, - :asparent => hash[:asparent] # might be nil + :asparent => hash[:asparent] || false # might be nil ) + # Now set the class again, this time using the scope. This way + # we can look up the parent scope of this class later, so we + # can hook the children together. + scope.setscope(self.object_id, result) + # This is important but painfully difficult. If we're the top-level # class, that is, we have no parent classes, then the transscope # is our own scope, but if there are parent classes, then the topmost diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb index f1b128ccf..e4e69bed9 100644 --- a/lib/puppet/parser/ast/node.rb +++ b/lib/puppet/parser/ast/node.rb @@ -7,13 +7,21 @@ class Puppet::Parser::AST #def evaluate(scope, facts = {}) def evaluate(hash) - scope = hash[:scope] + origscope = hash[:scope] facts = hash[:facts] || {} - #scope.info "name is %s, type is %s" % [self.name, self.type] + # nodes are never instantiated like a normal object, # but we need the type to be the name users would use for # instantiation, otherwise tags don't work out - scope = scope.newscope( + + pscope = origscope + #pscope = if ! Puppet[:lexical] or hash[:asparent] + # @scope + #else + # origscope + #end + + scope = pscope.newscope( :type => self.type, :keyword => @keyword ) @@ -78,7 +86,7 @@ class Puppet::Parser::AST begin code = node.code - code.safeevaluate(:scope => scope) + code.safeevaluate(:scope => scope, :asparent => true) rescue Puppet::ParseError => except except.line = self.line except.file = self.file diff --git a/lib/puppet/parser/ast/nodedef.rb b/lib/puppet/parser/ast/nodedef.rb index cc710329f..06b104828 100644 --- a/lib/puppet/parser/ast/nodedef.rb +++ b/lib/puppet/parser/ast/nodedef.rb @@ -3,7 +3,7 @@ class Puppet::Parser::AST # specified node, and this parse tree is only ever looked up when # a client connects. class NodeDef < AST::Branch - attr_accessor :names, :code, :parentclass, :keyword + attr_accessor :names, :code, :parentclass, :keyword, :scope def each [@names,@code].each { |child| yield child } |