net.sourceforge.nrl.parser.ast.impl
Class AntlrModelResolverVisitor

java.lang.Object
  extended by net.sourceforge.nrl.parser.ast.impl.AntlrAstVisitor
      extended by net.sourceforge.nrl.parser.ast.impl.AntlrModelResolverVisitor
All Implemented Interfaces:
INRLAstVisitor

public class AntlrModelResolverVisitor
extends AntlrAstVisitor

A visitor for resolving a single rule. Given a model, and an initial rule context, this visitor resolves all model references in the rule.

After this visitor is done, all IModelReference elements within the rule will have been resolved, or the relevant errors raised.

This visitor cannot, in the same iteration, check that all references are also appropriate. For example, it will not check that in the comparison date = '2005-12-30', the date reference is an attribute rather than a model element. This is done using type checking later.

Author:
Christian Nentwich

Field Summary
protected  Map<String,IVariableDeclaration> globalVariables
           
 
Constructor Summary
AntlrModelResolverVisitor(IClassifier ruleContext, IModelCollection models, Map<String,IVariableDeclaration> globalVariables, List<NRLError> errors)
          Initialize a constraint visitor with a rule context classifier, the model, a map of global variables and an error list to populate.
AntlrModelResolverVisitor(IClassifier ruleContext, IModelCollection models, Map<String,IVariableDeclaration> globalVariables, List<Variable> contextVariables, List<NRLError> errors)
           
AntlrModelResolverVisitor(IModelCollection models, Map<String,IVariableDeclaration> globalVariables, List<Variable> contextVariables, List<NRLError> errors)
           
 
Method Summary
 void bindVariable(IVariable var, INRLAstNode declarationNode, boolean checkDuplicates)
           
protected  IModelElement getCurrentContext()
           
protected  Stack<IModelElement> getCurrentContextStack()
           
 List<NRLError> getErrors()
           
protected  IModelCollection getModels()
           
protected  IClassifier getRuleContext()
           
 VariableContext getVariableContext()
           
 void pushCurrentContext(IModelElement context)
          Explicitly push a model element on the current context stack.
protected  void raiseError(INRLAstNode node, int statusCode, String message)
           
protected  void raiseError(ModelReferenceImpl ref, int statusCode, String message)
          Convenience method to add an error to the error list, for a particular model reference
protected  void visitAfter(Antlr3NRLBaseAst node)
          Visit the current node and pop the context stack where necessary, for example when a quantifier goes out of scope.
protected  boolean visitBefore(Antlr3NRLBaseAst node)
          Visit the current node and keep the "current context" up to date.
 
Methods inherited from class net.sourceforge.nrl.parser.ast.impl.AntlrAstVisitor
visitAfter, visitBefore
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

globalVariables

protected Map<String,IVariableDeclaration> globalVariables
Constructor Detail

AntlrModelResolverVisitor

public AntlrModelResolverVisitor(IClassifier ruleContext,
                                 IModelCollection models,
                                 Map<String,IVariableDeclaration> globalVariables,
                                 List<NRLError> errors)
Initialize a constraint visitor with a rule context classifier, the model, a map of global variables and an error list to populate.

Parameters:
ruleContext -
models -
globalVariables -
errors -

AntlrModelResolverVisitor

public AntlrModelResolverVisitor(IClassifier ruleContext,
                                 IModelCollection models,
                                 Map<String,IVariableDeclaration> globalVariables,
                                 List<Variable> contextVariables,
                                 List<NRLError> errors)

AntlrModelResolverVisitor

public AntlrModelResolverVisitor(IModelCollection models,
                                 Map<String,IVariableDeclaration> globalVariables,
                                 List<Variable> contextVariables,
                                 List<NRLError> errors)
Method Detail

bindVariable

public void bindVariable(IVariable var,
                         INRLAstNode declarationNode,
                         boolean checkDuplicates)

getErrors

public List<NRLError> getErrors()

getModels

protected IModelCollection getModels()

getCurrentContext

protected IModelElement getCurrentContext()

getCurrentContextStack

protected Stack<IModelElement> getCurrentContextStack()

getRuleContext

protected IClassifier getRuleContext()

getVariableContext

public VariableContext getVariableContext()

pushCurrentContext

public void pushCurrentContext(IModelElement context)
Explicitly push a model element on the current context stack.

Parameters:
context - the new context element

visitBefore

protected boolean visitBefore(Antlr3NRLBaseAst node)
Visit the current node and keep the "current context" up to date. The current context only changes with a quantifier or a where clause, which introduce a sub context.

The method also keeps the variable context up to date.

Specified by:
visitBefore in class AntlrAstVisitor

visitAfter

protected void visitAfter(Antlr3NRLBaseAst node)
Visit the current node and pop the context stack where necessary, for example when a quantifier goes out of scope.

Also pop the variable stack when variables go out of scope.

Overrides:
visitAfter in class AntlrAstVisitor

raiseError

protected void raiseError(ModelReferenceImpl ref,
                          int statusCode,
                          String message)
Convenience method to add an error to the error list, for a particular model reference

Parameters:
ref - the model reference
statusCode - the error status code
message - the message

raiseError

protected void raiseError(INRLAstNode node,
                          int statusCode,
                          String message)


Copyright © 2006-2013. All Rights Reserved.