Class Class

Inheritance Relationships

Derived Types

Class Documentation

class Class

Subclassed by Quack::NothingClass, Quack::ObjectClass, Quack::PrimitiveClass

Public Functions

Class(char *name, char *super_type, Param::Container *params, AST::Block *constructor, Method::Container *methods)
virtual ~Class()

Clear all dynamic memory in the object.

bool has_field(const std::string &name)

Checks whether this class (or any of its super classes) has a field with the specified name.

Return
True if the field exists
Parameters

bool has_method(const std::string &name)

Checks if this class (or any of its super classes) has the specified method.

Return
True if the class has a method with the specified name
Parameters
  • name: Name of the method to check

Method *get_method(const std::string &name)

Accessor for a method by the method’s name.

Return
Method pointer.
Parameters

Class *has_no_cyclic_inheritance(std::vector<Class *> &all_super)

Used to check for cyclical class inheritance. When classes are correctly configured, each class eventually points back (through the Object class) back to a single common class. If there is a cyclic dependency, the current class dependency will eventually appear in the all_super list built via recursive calls.

Return
true if the class has no cyclic dependencies.
Parameters
  • all_super: All super classes observed so far.

Class *least_common_ancestor(Class *other)

Perform least common ancestor determination on the implicit class and the other class.

Return
Parameters
  • other: Another

bool is_type(const std::string &name)

Check if the class is of the specified type.

Return
True if the class is of the specified type.
Parameters
  • name: Name of the type

bool is_subtype(Class *other_type)

Determines if the implicit class is a subtype of the specified type.

Return
True if this class is a subtype of other_type.
Parameters
  • other_type: Type to check whether this class is a subtype

void initial_type_check()

Performs an initial type check and configuration for the class’s super class as well as for the method parameters, return types, and constructor parameters.

void print_original_src(unsigned int indent_depth)

Accessor for all the methods in the class.

Return
Methods in the class. Debug function used to print a representation of the original quack source code used to visualize the AST.
Parameters
  • indent_depth: Depth to indent the generated code. Used for improved readability.

virtual bool is_user_class() const

Base classes are built into the Quack language and include Boolean, Integer, String, and Object. User classes are NOT built into the Quack language by default and are defined by the user..

Return
True if the class is abase class.

Method *get_constructor()

Accessor for the class constructor.

Return
Constructor method

const std::string generated_object_type_name() const

Type name for generated objects of this type

Return

const std::string generated_clazz_type_name() const

Type used to for the clazz field of objects of this type.

Return
Class name for object

const std::string generated_struct_clazz_name() const

Used to define the struct that stores the class information.

Return
Class struct information

const std::string generated_constructor_name() const

Gets the name used for constructors of this class.

Return
Constructor function name

const std::string generated_clazz_obj_struct_name() const

Gets the name of the struct object used to store the clazz information include super class. This function is used in typecase statements and in the generated class definitions.

Return
Name of the struct clazz struct const object

void generate_code(CodeGen::Settings settings)

Generates all code associated with a specific class

Parameters
  • settings: Code generator settings

Public Members

const std::string name_

Name of the class

Public Static Functions

static void check_well_formed_hierarchy()

Checks all classes for any cyclical inheritance.

static Class *least_common_ancestor(Class *c1, Class *c2)

Helper function used to find the least common ancestor of two classes. If there is no common ancestor, the function

Return
Class shared by the two classes in the hierarchy
Parameters
  • c1: First class to compare
  • c2: Second class to compare

static std::string generated_method_name(Class *q_class, Method *method)

Builds a method name for a class

Return
Method name for the class
Parameters

Protected Functions

void add_binop_method(const std::string &method_name, const std::string &return_type, const std::string &param_type)

Used to add binary operation methods to the a class. Only used for base classes like Obj, Boolean, Integer, etc.

Parameters
  • method_name: Name of the binary operation method
  • return_type: Return type of binary operation
  • param_type: Type of the other parameter’s type

void add_unary_op_method(const std::string &method_name, const std::string &return_type)

Protected Attributes

Method::Container *methods_

All methods supported by the class

Field::Container *fields_

Name of all fields in the class

GenObjContainer<Method> *gen_methods_

Generated methods for the class in order

GenObjContainer<Field> *gen_fields_

Generated fields for the class in order

Friends

friend Quack::Class::CodeGen::Gen
class Container : public MapContainer<Class>

Public Functions

const void print_original_src(unsigned int indent_depth)

Prints the user defined classes only.

Parameters
  • indent_depth: Depth to tab the contents.

Container(Container const&)
Container &operator=(Container const&)

Public Static Functions

Quack::Class::Container *singleton()

Singleton object containing all of the class information.

Return
Pointer to a set of classes.

static void reset()

Empty all stored classes in the singleton.

static Class *Int()

Static accessor to get the Integer class.

Return
Integer class reference.

static Class *Bool()

Static accessor to get the Boolean class.

Return
Boolean class reference.

static Class *Nothing()

Static accessor to get the Boolean class.

Return
Boolean class reference.

static Class *Str()

Static accessor to get the String class.

Return
String class reference.

static Class *Obj()

Static accessor to get the Object class.

Return
Object class reference