ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

escjava.backpred
Class FindContributors

java.lang.Object
  extended byescjava.backpred.FindContributors

public class FindContributors
extends java.lang.Object

This class is responsible for determining the contributors to a given TypeSig or RoutineDecl.

The contributors are divided into a set of TypeSigs, a set of Invariants, and a set of Fields.


Field Summary
private  Set contributorFields
          The set of fields (elementType FieldDecl) we've determined to be contributors so far.
private  Set contributorInvariants
          The set of invariants (elementType ExprDeclPragmas) we've determined to be contributors so far.
private  Set contributorTypes
          The set of TypeSigs we've determined to be contributors so far.
(package private)  java.util.Hashtable fieldToPossible
          A mapping from fields (FieldDecls) to possible invariant contributors (ExprDeclPragmaVec).
 TypeSig originType
          Our origin type; used to determine visibility and accessibility when needed.
 int preFieldMode
           
 Set preFields
           
private  Set visitedRoutines
          The set of routines visited so far.
 
Constructor Summary
FindContributors(RoutineDecl rd)
          Generate the contributors for a given RoutineDecl.
FindContributors(TypeSig T)
          Generate the contributors for a given TypeSig.
 
Method Summary
private  void addField(FieldDecl fd)
          Add a given field to contributorFields, maintaining all the closure properties.
private  void addImplicitConstructorRefs(ConstructorDecl cd, FieldDeclVec fields, boolean addTypes, java.util.LinkedList visited)
          Add implicit references from a ConstructorDecl that do not appear in Java code or via backedges as per walk(,,).
private  void addInvariant(ExprDeclPragma J)
          Add a given invariant to contributorInvarints, maintaining all closure properties.
private  void addPossibleInvariant(ExprDeclPragma J)
          Add a possible invariant contributor to either fieldToPossible or contributorInvariants as approperiate, maintaining all closure properties.
private  void addPossibleMentions(FieldDecl fd, ExprDeclPragma J)
          Add the mapping (fd, J) to fieldToPossible.
private  void addType(Type T)
          Add the TypeSigs mentioned explicitly in a given Type to contributorTypes, maintaining all the closure properties.
private  void backedgeToGenericVarDecl(GenericVarDecl decl, FieldDeclVec fields, boolean addTypes, java.util.LinkedList visited)
          Calculate the fields and types "mentioned" by a backedge to a GenericVarDecl and then add them as per walk(,,).
private  void backedgeToRoutineDecl(RoutineDecl rd, FieldDeclVec fields, boolean addTypes, int inlined, java.util.LinkedList visited)
          Calculate the fields and types "mentioned" by a backedge to a RoutineDecl and then add them as per walk(,,).
 java.util.Enumeration fields()
          Enumerate the field contributors
private  FieldDeclVec fieldsInvariantMentions(ExprDeclPragma J)
          Returns the set of fields that a given invariant mentions.
 java.util.Enumeration invariants()
          Enumerate the invariant contributors
private  boolean isNonRecursiveHelperInvocation(RoutineDecl r)
          Returns true if and only if r is a helper routine that has not been visited by this FindContributor object.
(package private)  void typecheck(TypeSig sig)
          Make sure a given TypeSig has been type checked, type checking it if necessary.
 java.util.Enumeration typeSigs()
          Enumerate the TypeSig contributors
private  void walk(ASTNode N)
          Walks a given ASTNode, adding all the types it "mentions" via addType and adding all the fields it "mentions" via addField.
private  void walk(ASTNode N, FieldDeclVec fields, boolean addTypes, java.util.LinkedList visited)
          Walks a given ASTNode, finding all the types it "mentions" and all the fields it "mentions".
private  void walkInstanceInitialier(TypeDecl td, FieldDeclVec fields, boolean addTypes, java.util.LinkedList visited)
          Walk the implicit instance initializer code for a given TypeDecl, excluding any field initializations of superinterface fields.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

originType

public TypeSig originType
Our origin type; used to determine visibility and accessibility when needed.


visitedRoutines

private Set visitedRoutines
The set of routines visited so far.


contributorTypes

private Set contributorTypes
The set of TypeSigs we've determined to be contributors so far.

Invariant: This set is closed under taking supertypes


contributorInvariants

private Set contributorInvariants
The set of invariants (elementType ExprDeclPragmas) we've determined to be contributors so far.

Closure Property: walk(-) has been called on each of these invariants.


contributorFields

private Set contributorFields
The set of fields (elementType FieldDecl) we've determined to be contributors so far.

Closure Property: all invariants J that are declared in types in contributorTypes and "mention the field" f for f a field in contributorFields are members of contributorInvariants


preFieldMode

public int preFieldMode

preFields

public Set preFields

fieldToPossible

java.util.Hashtable fieldToPossible
A mapping from fields (FieldDecls) to possible invariant contributors (ExprDeclPragmaVec).

(An invariant is a possible contributor if it is declared in a type of contributorTypes.) Invariant: if (f,J) in fieldToPossible then the invariant J "mentions the field" f and J is a possible invariant contributor Closure property: if J is possible invariant contributor, J not in contributorInvariants, and J "mentions the field" f, then (f,J) is in fieldToPossible.

Constructor Detail

FindContributors

public FindContributors(TypeSig T)
Generate the contributors for a given TypeSig. This may result in errors being reported and TypeSigs being type checked.

The originType is taken to be that Typesig.

Precondition: T must have been typechecked.

Note: in the process of locating contributors, FindContributors may type check additional types leading possibly to type errors. If such error(s) occur, a fatal error is reproted.


FindContributors

public FindContributors(RoutineDecl rd)
Generate the contributors for a given RoutineDecl. This may result in errors being reported and TypeSigs being type checked.

The originType is taken to be the type declaring that RoutineDecl.

Precondition: the type declaring rd must have been typechecked.

Note: in the process of locating contributors, FindContributors may type check additional types leading possibly to type errors. If such error(s) occur, a fatal error is reproted.

Method Detail

typeSigs

public java.util.Enumeration typeSigs()
Enumerate the TypeSig contributors


invariants

public java.util.Enumeration invariants()
Enumerate the invariant contributors


fields

public java.util.Enumeration fields()
Enumerate the field contributors


addType

private void addType(Type T)
Add the TypeSigs mentioned explicitly in a given Type to contributorTypes, maintaining all the closure properties.

Precondition: T has been resolved.


addField

private void addField(FieldDecl fd)
Add a given field to contributorFields, maintaining all the closure properties.


addPossibleMentions

private void addPossibleMentions(FieldDecl fd,
                                 ExprDeclPragma J)
Add the mapping (fd, J) to fieldToPossible. Precondition: J is a possible invariant contributor, J "mentions the field" fd.


addPossibleInvariant

private void addPossibleInvariant(ExprDeclPragma J)
Add a possible invariant contributor to either fieldToPossible or contributorInvariants as approperiate, maintaining all closure properties.

Precondition: J has been type checked.


addInvariant

private void addInvariant(ExprDeclPragma J)
Add a given invariant to contributorInvarints, maintaining all closure properties.

Precondition: J has been type checked.


walk

private void walk(ASTNode N)
Walks a given ASTNode, adding all the types it "mentions" via addType and adding all the fields it "mentions" via addField.

Precondition: N has been typechecked. WARNING: N is assumed to have no free local or parameter varables.


fieldsInvariantMentions

private FieldDeclVec fieldsInvariantMentions(ExprDeclPragma J)
Returns the set of fields that a given invariant mentions.

Precondition: J must be an invariant, J must be typechecked.


walk

private void walk(ASTNode N,
                  FieldDeclVec fields,
                  boolean addTypes,
                  java.util.LinkedList visited)
Walks a given ASTNode, finding all the types it "mentions" and all the fields it "mentions".

If fields is null, the fields mentioned are added via addField; otherwise, they are added to fields directly.

If addTypes is true, the types mentioned are added via addType.

Precondition: N has been typechecked.


isNonRecursiveHelperInvocation

private boolean isNonRecursiveHelperInvocation(RoutineDecl r)
Returns true if and only if r is a helper routine that has not been visited by this FindContributor object.


addImplicitConstructorRefs

private void addImplicitConstructorRefs(ConstructorDecl cd,
                                        FieldDeclVec fields,
                                        boolean addTypes,
                                        java.util.LinkedList visited)
Add implicit references from a ConstructorDecl that do not appear in Java code or via backedges as per walk(,,). Precondition: the type declaring cd has been typechecked.


walkInstanceInitialier

private void walkInstanceInitialier(TypeDecl td,
                                    FieldDeclVec fields,
                                    boolean addTypes,
                                    java.util.LinkedList visited)
Walk the implicit instance initializer code for a given TypeDecl, excluding any field initializations of superinterface fields.

E.g., f_1 = 0; ...; f_3 = ; ... ; ... This is the code that constructors of that type implicitly start with after their super/sibling call modulo the initialization of superinterface fields. See addImplicitConstructorRefs for the full version w/o the exclusion. Addition: This now also pulls in all invariants in the given TypeDecl, regardless of what they mention. This is to avoid user surprise; see also Vanilla.java in test58. Precondition: the TypeDecl has been typechecked.


backedgeToGenericVarDecl

private void backedgeToGenericVarDecl(GenericVarDecl decl,
                                      FieldDeclVec fields,
                                      boolean addTypes,
                                      java.util.LinkedList visited)
Calculate the fields and types "mentioned" by a backedge to a GenericVarDecl and then add them as per walk(,,).


backedgeToRoutineDecl

private void backedgeToRoutineDecl(RoutineDecl rd,
                                   FieldDeclVec fields,
                                   boolean addTypes,
                                   int inlined,
                                   java.util.LinkedList visited)
Calculate the fields and types "mentioned" by a backedge to a RoutineDecl and then add them as per walk(,,).

inlined is one of: 0 (not an inlined routine), 1 (an inlined helper routine), or 2 (a routine inlined for a reason other than being a helper). (Why this complication, why not just use a boolean field "inlined"? By distinguishing cases 1 and 2, one can write a nice run-time assert inside the implementation of this method.)


typecheck

void typecheck(TypeSig sig)
Make sure a given TypeSig has been type checked, type checking it if necessary.

Throws a fatal error if a type error occurs while checking sig.


ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage