Module Klass (.ml)

module Klass: sig .. end
Approximates a class

val klass_to_parent : Ast.class_def -> string
From a class get the parent
Returns The name of the parent object
Parameters:
aklass : Ast.class_def
is a class_def to get the parent of
val section_string : Ast.class_section -> string
Stringify a section to be printed
Returns The stringification of the section for printing
Parameters:
section : Ast.class_section
A class_section value (Privates, Protects, Publics, Refines, or Mains)
val klass_to_variables : Ast.class_def -> (Ast.class_section * Ast.var_def list) list
Return the variables of the class
Returns A list of ordered pairs representing different sections, the first item of each pair is the type of the section, the second is a list of the variables defs (type, name). Note that this only returns pairs for Publics, Protects, and Privates as the others cannot have variables
Parameters:
aklass : Ast.class_def
The class to explore
val klass_to_methods : Ast.class_def -> (Ast.class_section * Ast.func_def list) list
Return the methods of the class
Returns A list of ordered pairs representing different sections, the first item of each pair is the type of the section, the second is a list of the methods. Note that this only returns the methods in Publics, Protects, or Privates as the other sections don't have `normal' methods in them
Parameters:
aklass : Ast.class_def
The class to explore
val klass_to_functions : Ast.class_def -> (Ast.class_section * Ast.func_def list) list
Get anything that is invocable, not just instance methods
Returns The combined list of refinements, mains, and methods
Parameters:
aklass : Ast.class_def
The class to explore
val conflicting_signatures : Ast.func_def -> Ast.func_def -> bool
Return whether two function definitions have conflicting signatures
Returns Whether the functions have the same name and the same parameter type sequence
Parameters:
func1 : Ast.func_def
A func_def
func2 : Ast.func_def
A func_def
val signature_string : Ast.func_def -> string
Return a string that describes a function
Returns A string showing the simple signature (host.name and arg types)
Parameters:
func : Ast.func_def
A func_def
val full_signature_string : Ast.func_def -> string
Return a string representing the full signature of the function
Returns A string showing the signature (section, host.name, arg types)
Parameters:
func : Ast.func_def
A func_def
val class_var_lookup : GlobalData.class_data ->
string -> string -> (Ast.class_section * string) option
Given a class_data record, a class name, and a variable name, lookup the section and type info for that variable.
Returns Either None if the variable is not declared in the class or Some((section, type)) where the variable is declared in section and has the given type.
Parameters:
data : GlobalData.class_data
A class_data record
klass_name : string
The name of a class (string)
var_name : string
The name of a variable (string)
val class_field_lookup : GlobalData.class_data ->
string -> string -> (string * string * Ast.class_section) option
Given a class_data record, a class_name, and a variable name, lookup the class in the hierarchy that provides access to that variable from within that class (i.e. private in that class or public / protected in an ancestor).
Returns (class (string), type (string), class_section) option (None if not found).
Parameters:
data : GlobalData.class_data
A class_data record.
klass_name : string
The name of a class (string)
var_name : string
The name of a variable (string).
val class_field_far_lookup : GlobalData.class_data ->
string ->
string -> bool -> (string * string * Ast.class_section, bool) Util.either
Given a class_data record, a class name, a var_name, and whether the receiver of the field lookup is this, return the lookup of the field in the ancestry of the object. Note that this restricts things that should be kept protected (thus this thusly passed)
Returns Either the left of a triple (class found, type, section) or a Right of a boolean, which is true if the item was found but inaccessible and false otherwise.
Parameters:
data : GlobalData.class_data
A class_data record
klass_name : string
The name of a class (string)
var_name : string
The name of a variable (string)
this : bool
val class_method_lookup : GlobalData.class_data -> string -> string -> Ast.func_def list
Given a class_data record, a class name, and a method name, lookup all the methods in the given class with that name.
Returns A list of methods in the class with that name or the empty list if no such method exists.
Parameters:
data : GlobalData.class_data
A class_data record
klass_name : string
The name of a class (string)
func_name : string
The name of a method (string)
val class_ancestor_method_lookup : GlobalData.class_data -> string -> string -> bool -> Ast.func_def list
Given a class_data record, a class name, a method name, and whether the current context is `this' (i.e. if we want private / protected / etc), then return all methods in the ancestry of that class with that name (in the appropriate sections).
Returns A list of methods with the given name.
Parameters:
data : GlobalData.class_data
A class_data record value
klass_name : string
The name of a class.
method_name : string
The name of a method to look up
this : bool
search mode -- true means public/protected/private and then public/protected, false is always public
val refine_lookup : GlobalData.class_data -> string -> string -> string -> Ast.func_def list
Given a class_data record, class name, method name, and refinement name, return the list of refinements in that class for that method with that name.
Returns A list of func_def values that match the given requirements. Note that this returns the functions defined IN class name, not the ones that could be used INSIDE class name (via a refine invocation). i.e. functions that may be invoked by the parent.
Parameters:
data : GlobalData.class_data
A class_data record value
klass_name : string
A class name
method_name : string
A method name
refinement_name : string
A refinement name
val refinable_lookup : GlobalData.class_data -> string -> string -> string -> Ast.func_def list
Given a class_data record, a class name, a method name, and a refinement name, return the list of refinements across all subclasses for the method with that name.
Returns A list of func_def values that meet the criteria and may be invoked by this given method. i.e. these are all functions residing in SUBCLASSES of the named class.
Parameters:
data : GlobalData.class_data
A class_data record value
klass_name : string
A class name
method_name : string
A method name
refinement_name : string
A refinement name
val get_distance : GlobalData.class_data -> string -> string -> int option
Given a class_data record and two classes, returns the distance between them. If one is a proper subtype of the other then Some(n) is returned where n is non-zero when the two classes are different and comparable (one is a subtype of the other), zero when they are the same, and None when they are incomparable (one is not a subtype of the other)
Returns An int option, None when the two classes are incomparable, Some(positive) when klass2 is an ancestor of klass1, Some(negative) when klass1 is an ancestor of klass2.
Parameters:
data : GlobalData.class_data
A class_data record
klass1 : string
A class to check the relation of to klass2
klass2 : string
A class to check the relation of to klass1
val is_type : GlobalData.class_data -> string -> bool
Check if a type exists in the class data -- convenience function
Returns True if the atype is a known type, false otherwise.
Parameters:
data : GlobalData.class_data
A class_data record
atype : string
The name of a class (string)
val is_subtype : GlobalData.class_data -> string -> string -> bool
Check if a class is a subclass of another given a class_data record
Returns Whether subtype has supertype as an ancestor given data. Note that this is true when the two are equal (trivial ancestor).
Parameters:
data : GlobalData.class_data
A class_data record
subtype : string
A class name (string)
supertype : string
A class name (string)
val is_proper_subtype : GlobalData.class_data -> string -> string -> bool
Check if a class is a proper subclass of another given a class_data record
Returns Whether subtype has supertype as an ancestor given data. Note that this IS NOT true when the two are equal (trivial ancestor).
Parameters:
data : GlobalData.class_data
A class_data record
subtype : string
A class name (string)
supertype : string
A class name (string)
val compatible_formals : GlobalData.class_data -> string list -> string list -> bool
Return whether a list of actuals and a list of formals are compatible. For this to be true, each actual must be a (not-necessarily-proper) subtype of the formal at the same position. This requires that both be the same in quantity, obviously.
Returns Whether the actual arguments are compatible with the formal arguments.
Parameters:
data : GlobalData.class_data
A class_data record (has type information)
actuals : string list
A list of the types (and just the types) of the actual arguments
formals : string list
A list of the types (and just the types) of the formal arguments
val compatible_function : GlobalData.class_data -> string list -> Ast.func_def -> bool
Return whether a given func_def is compatible with a list of actual arguments. This means making sure that it has the right number of formal arguments and that each actual agument is a subtype of the corresponding formal argument.
Returns Whether the given func_def is compatible with the actual arguments.
Parameters:
data : GlobalData.class_data
A class_data record (has type information)
actuals : string list
A list of the types (and just the types) of the actual arguments
func : Ast.func_def
A func_def from which to get formals
val compatible_return : GlobalData.class_data -> string option -> Ast.func_def -> bool
Return whether a function's return type is compatible with a desired return type. Note that if the desired return type is None then the function is compatible. Otherwise if it is not None and the function's is, then it is not compatible. Lastly, if the desired type is a supertype of the function's return type then the function is compatible.
Returns True if compatible, false if not.
Parameters:
data : GlobalData.class_data
A class_data record value
ret_type : string option
The desired return type
func : Ast.func_def
A func_def to test.
val compatible_signature : GlobalData.class_data -> string option -> string list -> Ast.func_def -> bool
Return whether a function's signature is completely compatible with a return type and a set of actuals
Returns True if compatible, false if not.
Parameters:
data : GlobalData.class_data
A class_data record value
ret_type : string option
The return type (string option)
actuals : string list
The list of actual types
func : Ast.func_def
A func_def value
val best_matching_signature : GlobalData.class_data ->
string list -> Ast.func_def list -> Ast.func_def list
Given a class_data record, a list of actual arguments, and a list of methods, find the best matches for the actuals. Note that if there are multiple best matches (i.e. ties) then a non-empty non-singleton list is returned. Raises an error if somehow our list of compatible methods becomes incompatible i.e. there is a logic error in the compiler.
Returns The list of all best matching functions (should be at most one, we hope).
Parameters:
data : GlobalData.class_data
A class_data record
actuals : string list
The list of types (and only types) for the actual arguments
funcs : Ast.func_def list
The list of candidate functions
val best_method : GlobalData.class_data ->
string ->
string -> string list -> Ast.class_section list -> Ast.func_def option
Given a class_data record, method name, and list of actuals, and a list of sections to consider, get the best matching method. Note that if there is more than one then an exception is raised as this should have been reported during collision detection compiler error.
Returns Either None if no function is found, Some(f) if one function is found, or an error is raised.
Parameters:
data : GlobalData.class_data
A class_data record
klass_name : string
method_name : string
The name to lookup candidates for
actuals : string list
The list of types (and only types) for the actual arguments
sections : Ast.class_section list
The sections to filter on (only look in these sections)
val best_inherited_method : GlobalData.class_data ->
string -> string -> string list -> bool -> Ast.func_def option
Parameters:
data : GlobalData.class_data
klass_name : string
method_name : string
actuals : string list
this : bool
val refine_on : GlobalData.class_data ->
string ->
string -> string -> string list -> string option -> Ast.func_def list
Given the name of a refinement to apply, the list of actual types, find the compatible refinements via the data / klass_name / method_name. Partition the refinements by their inklass value and then return a list of the best matches from each partition.
Returns A list of functions to switch on based on the actuals.
Parameters:
data : GlobalData.class_data
A class_data record value
klass_name : string
A class name
method_name : string
A method name
refine_name : string
A refinement name
actuals : string list
The types of the actual arguments
ret_type : string option
val get_class_names : GlobalData.class_data -> string list
Get the names of the classes in level order (i.e. from root down).
Returns The list of known classes, from the root down.
Parameters:
data : GlobalData.class_data
A class_data record
val get_leaves : GlobalData.class_data -> string list
Get leaf classes
Returns A list of leaf classes
Parameters:
data : GlobalData.class_data
A class_data record