Top Description Fields Constructors Methods
org.antlr.tool

public Class AttributeScope

extends Object
Class Inheritance
Known Direct Subclasses
org.antlr.tool.RuleLabelScope
Imports
org.antlr.codegen.CodeGenerator, org.antlr.runtime.Token, java.util.*

Track the attributes within a scope. A named scoped has just its list of attributes. Each rule has potentially 3 scopes: return values, parameters, and an implicitly-named scope (i.e., a scope defined in a rule). Implicitly-defined scopes are named after the rule; rules and scopes then must live in the same name space--no collisions allowed.

Field Summary

Modifier and TypeField and Description
public LinkedHashMap<String, GrammarAST>
protected LinkedHashMap<String, Attribute>
attributes

The list of Attribute objects

public Token
derivedFromToken

This scope is associated with which input token (for error handling)?

public Grammar
public boolean
isDynamicGlobalScope

Not a rule scope, but visible to all rules "scope symbols { ...}"

public boolean
isDynamicRuleScope

Visible to all rules, but defined in rule "scope { int i; }"

public boolean
public boolean
public boolean
public boolean
private String
name

The scope name

public static final AttributeScope
tokenScope

All token scopes (token labels) share the same fixed scope of of predefined attributes.

Constructor Summary

AccessConstructor and Description
public
AttributeScope(String name, Token derivedFromToken)

public
AttributeScope(Grammar grammar, String name, Token derivedFromToken)

Method Summary

Modifier and TypeMethod and Description
public void
public void
addAttributes(String definitions, int separator)

From a chunk of text holding the definitions of the attributes, pull them apart and create an Attribute for each one.

public final void
defineNamedAction(GrammarAST nameAST, GrammarAST actionAST)

Given @scope::name {action} define it for this attribute scope.

public Attribute
public List<Attribute>
getAttributes()

Used by templates to get all attributes

public String
public Set<String>
intersection(AttributeScope other)

Return the set of keys that collide from this and other.

public int
size()

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

actionsback to summary
public LinkedHashMap<String, GrammarAST> actions
attributesback to summary
protected LinkedHashMap<String, Attribute> attributes

The list of Attribute objects

derivedFromTokenback to summary
public Token derivedFromToken

This scope is associated with which input token (for error handling)?

grammarback to summary
public Grammar grammar
isDynamicGlobalScopeback to summary
public boolean isDynamicGlobalScope

Not a rule scope, but visible to all rules "scope symbols { ...}"

isDynamicRuleScopeback to summary
public boolean isDynamicRuleScope

Visible to all rules, but defined in rule "scope { int i; }"

isParameterScopeback to summary
public boolean isParameterScope
isPredefinedLexerRuleScopeback to summary
public boolean isPredefinedLexerRuleScope
isPredefinedRuleScopeback to summary
public boolean isPredefinedRuleScope
isReturnScopeback to summary
public boolean isReturnScope
nameback to summary
private String name

The scope name

tokenScopeback to summary
public static final AttributeScope tokenScope

All token scopes (token labels) share the same fixed scope of of predefined attributes. I keep this out of the runtime.Token object to avoid a runtime space burden.

Constructor Detail

AttributeScopeback to summary
public AttributeScope(String name, Token derivedFromToken)
AttributeScopeback to summary
public AttributeScope(Grammar grammar, String name, Token derivedFromToken)

Method Detail

addAttributeback to summary
public void addAttribute(String name, String decl)
addAttributesback to summary
public void addAttributes(String definitions, int separator)

From a chunk of text holding the definitions of the attributes, pull them apart and create an Attribute for each one. Add to the list of attributes for this scope. Pass in the character that terminates a definition such as ',' or ';'. For example, scope symbols { int n; List names; } would pass in definitions equal to the text in between {...} and separator=';'. It results in two Attribute objects.

defineNamedActionback to summary
public final void defineNamedAction(GrammarAST nameAST, GrammarAST actionAST)

Given @scope::name {action} define it for this attribute scope. Later, the code generator will ask for the actions table.

getAttributeback to summary
public Attribute getAttribute(String name)
getAttributesback to summary
public List<Attribute> getAttributes()

Used by templates to get all attributes

getNameback to summary
public String getName()
intersectionback to summary
public Set<String> intersection(AttributeScope other)

Return the set of keys that collide from this and other.

sizeback to summary
public int size()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override