|
antlraux package v0.2.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--antlraux.context.Scope
This is the class tha modelizes scopes.
Scopes admit data in the form of instances of Declaration
.
Usually scopes are represented as instances of
Hashtable
containing instances of
Declaration
, and organized in a pile.
This implementation is slightly different.
Firstly, the scope's hashtables' elements are linked lists instead of simple
Declarations, so several elements with the same name are allowed on each
tabe's position. This is more flexible than having just one declaration
per position, allowing for example inserting several method declarations
with the same name in a class scope (thus making polymorphism easier).
The counterpoint is that now the search methods return a linked list
instead of a single element - several helping methods (
searchFirst(String)
, searchFirstLocally(String)
,
searchFirst(int)
and searchFirstLocally(int)
) have been
included to ease this issue.
Other difference between this implementation of scopes is scope organization.
Instead of having an explicit pile of scopes, the pile is implicit in this
case. This is achieved simply making every Scope
know its "father scope".
In other words, each "method scope" will have to know the scope of the class that
holds the method, etc. A root ("global") scope will have null as father.
Finally, the declarations are organized in two different ways:
Declaration.type
field for that. The
tag says wether a declaration is a "class", a "parameter", a "method", etc.
This two types allow more powerful search techniques. For example, you can ask for "all the elements named 'foo' in a class scope", but you could also ask for "all the attributes of the class".
There are two ways of working with Scope
. The first one is using the
Context
class. This class has facilities for authomatically checking
scope closing.
The other option is not using Context
, and write subclasses of
Scope
(like GlobalScope, ClassScope,
MethodScope, etc). Override insert(Declaration)
to perform insertion checks and check the opening on every constructor
(see if the father scope allows "this" as a child scope)
Context
,
Declaration
Field Summary | |
protected Scope |
father
The scope's father. |
protected java.lang.String |
name
The name of a scope is just a "caption", that will be used for most printing procedures. |
protected java.util.Hashtable |
namesTable
The scope's set of declarations, hashed by name. |
protected int |
tag
This integer needed on every Scope constructor represents
a type of scope. |
protected java.util.Hashtable |
tagsTable
The scope's set of declarations, hashed by tag. |
Constructor Summary | |
Scope(int tag,
java.lang.String name)
Constructor that sets tag and name |
|
Scope(int tag,
java.lang.String name,
Scope father)
Constructor that sets tag , name and
father |
Method Summary | |
void |
addDeclarations(java.util.LinkedList list)
It adds the declarations contained in "list" to this scope. |
Scope |
getFather()
Accessor for father |
java.lang.String |
getName()
Accessor for name |
int |
getTag()
Accessor for tag |
void |
insert(Declaration d)
Inserts a new Declaration |
java.util.LinkedList |
searchAll(int tag)
It calls searchAllLocally(int) with tag as param and,
if nothing found, it continues with the father, the father of
the father, etc. |
java.util.LinkedList |
searchAll(int tag,
java.lang.String name)
It calls searchAllLocally(int, String) with tag as param and,
if nothing found, it continues with the scope's father, the father of
the father, etc. |
java.util.LinkedList |
searchAll(java.lang.String name)
It calls searchAllLocally(String) with "name" as param and,
if nothing found, it continues with the father, the father of
the father, etc. |
java.util.LinkedList |
searchAllLocally(int tag)
Searches in current scope every Declaration tagged like "tag" |
java.util.LinkedList |
searchAllLocally(int tag,
java.lang.String name)
Searches in current scope every Declaration tagged like "tag"
and named like "name" |
java.util.LinkedList |
searchAllLocally(java.lang.String name)
Searches in current scope every Declaration named "name" |
Declaration |
searchFirst(int tag)
It calls searchFirstLocally(int) with "tag" as param and,
if nothing found, it continues with the father, the father of
the father, etc. |
Declaration |
searchFirst(int tag,
java.lang.String name)
It calls searchFirstLocally(int,String) with
"tag" and "name" as params and, if nothing found,
it continues with the scope's father, the father of
the father, etc. |
Declaration |
searchFirst(java.lang.String name)
It calls searchFirstLocally(String) with "name" as param and,
if nothing found, it continues with the father, the father of
the father, etc. |
Declaration |
searchFirstLocally(int tag)
Searches in current scope the first (last inserted) Declaration with a tag==tag |
Declaration |
searchFirstLocally(int tag,
java.lang.String name)
Searches in current scope the first (last inserted) Declaration with a tag==tag AND name==name |
Declaration |
searchFirstLocally(java.lang.String name)
Searches in current scope the first (last inserted) Declaration named "name" |
void |
setFather(Scope s)
Accessor for father |
void |
setName(java.lang.String s)
Accessor for name |
void |
setTag(int i)
Accessor for tag |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Scope father
protected java.lang.String name
Scope
. For example, the global scope should be called
"global", or "root", while class Foo's scope name should look like
"class Foo".
protected int tag
Scope
constructor represents
a type of scope. This is, it codes if current scope is global scope,
class scope, method scope, etc. It is very usefull for performing
scope closing checks.
protected java.util.Hashtable namesTable
protected java.util.Hashtable tagsTable
Constructor Detail |
public Scope(int tag, java.lang.String name)
tag
and name
public Scope(int tag, java.lang.String name, Scope father)
tag
, name
and
father
Method Detail |
public java.lang.String getName()
name
public int getTag()
tag
public Scope getFather()
father
public void setName(java.lang.String s)
name
public void setTag(int i)
tag
public void setFather(Scope s)
father
public void insert(Declaration d) throws ContextException
Declaration
d
- the Declaration
that is going to be inserted
in the scope.
ContextException
- if could not insert d. (Actually default
implementation of insert will never throw it, but subclasses
may do)public Declaration searchFirstLocally(int tag)
Declaration
with a tag==tag
tag
- the tag of the Declaration
being searched
public Declaration searchFirstLocally(java.lang.String name)
Declaration
named "name"
name
- the name of the Declaration
being searched
public Declaration searchFirstLocally(int tag, java.lang.String name)
Declaration
with a tag==tag AND name==name
tag
- the tag of the Declaration
being searchedname
- the name of the Declaration
being searched
searchAllLocally(int, String)
public Declaration searchFirst(int tag)
searchFirstLocally(int)
with "tag" as param and,
if nothing found, it continues with the father, the father of
the father, etc.
tag
- the searched Declaration
's tag
public Declaration searchFirst(java.lang.String name)
searchFirstLocally(String)
with "name" as param and,
if nothing found, it continues with the father, the father of
the father, etc.
name
- the searched Declaration
's name
public Declaration searchFirst(int tag, java.lang.String name)
searchFirstLocally(int,String)
with
"tag" and "name" as params and, if nothing found,
it continues with the scope's father, the father of
the father, etc.
name
- the searched Declaration
's nametag
- the searched Declaration
's tag
public java.util.LinkedList searchAllLocally(java.lang.String name)
Declaration
named "name"
name
- the name of the Declaration
s being searched
public java.util.LinkedList searchAllLocally(int tag)
Declaration
tagged like "tag"
tag
- the tag of the Declaration
s being searched
public java.util.LinkedList searchAllLocally(int tag, java.lang.String name)
Declaration
tagged like "tag"
and named like "name"
tag
- the tag of the Declaration
s being searchedname
- the name of the Declaration
s being searched
public java.util.LinkedList searchAll(java.lang.String name)
searchAllLocally(String)
with "name" as param and,
if nothing found, it continues with the father, the father of
the father, etc. This is the most powerfull (and slowest) search
method.
name
- the searched Declaration
's name
public java.util.LinkedList searchAll(int tag)
searchAllLocally(int)
with tag as param and,
if nothing found, it continues with the father, the father of
the father, etc.
tag
- the searched Declaration
s' tag
public java.util.LinkedList searchAll(int tag, java.lang.String name)
searchAllLocally(int, String)
with tag as param and,
if nothing found, it continues with the scope's father, the father of
the father, etc.
tag
- the searched Declaration
s' tagname
- the searched Declaration
s' name
public java.lang.String toString()
toString
in class java.lang.Object
public void addDeclarations(java.util.LinkedList list) throws ContextException
ContextException
- if an error ocurrs (never by default,
but subclasses may want to)
|
antlraux package v0.2.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |