Detailed Description

Represents a class being compiled from a nitro code string.

Public Member Functions

 CompiledClass ()
 Creates a new class. Note you must call StartType manually. More...
 
 CompiledClass (CodeFragment classFragment, NitroCode script, string name, Type baseType, bool isPublic)
 
void StartType (string name, NitroCode script, Type baseType)
 Starts creating this class. More...
 
Type GetAsType ()
 Gets this class as a system type. More...
 
void Compile ()
 Compiles this class from its ClassFragment. More...
 
bool ContainsMethod (string name)
 Checks if this class contains the method with the given name. More...
 
bool ContainsField (string field)
 Checks if this class contains the field with the given name. More...
 
Type MethodReturnType (string name)
 Gets the return type of a given method by name. Note all overloads must return the same thing. More...
 
MethodInfo FindMethodOverload (string name, CompiledFragment[] arguments)
 Gets a particular method (it may be overloaded) from this class. More...
 
MethodInfo FindMethodOverload (string name, Type[] arguments)
 Gets a particular method (it may be overloaded) from this class. More...
 
MethodOverloads FindMethodSet (string name)
 Finds the overload set for the method with the given name. More...
 
PropertyInfo GetProperty (string name)
 Gets the property from this class with the given name. More...
 
FieldInfo GetField (string name)
 Gets the field from this class with the given name. More...
 
void FindOperations (CodeFragment fragment)
 Finds any other entries in the given code fragment. More...
 
void FindMethods (CodeFragment fragment)
 Finds methods within the given fragment by looking for 'function'. More...
 

Public Attributes

Type BaseType
 The type that this class derives from, if any. More...
 
Type compiledType
 When fully compiled, this is the resulting system type of this class. More...
 
NitroCode Script
 The script this class belongs to. More...
 
bool IsPublic =true
 True if this is a public class, false for private. More...
 
TypeBuilder Builder
 The type builder used to construct a system type from this class. More...
 
CodeFragment ClassFragment
 The content of this whole class as parsed from the code. More...
 
Dictionary< string, FieldInfo > Fields =new Dictionary<string,FieldInfo>()
 All the fields of this class. More...
 
Dictionary< string,
MethodOverloads
Methods =new Dictionary<string,MethodOverloads>()
 All methods contained by this class grouped into overloads. More...
 

Protected Member Functions

virtual CodeFragment AddFoundMethod (CodeFragment fragment, CodeFragment body, string name, bool anonymous, BracketFragment parameters, TypeFragment returnType, bool isPublic)
 Adds a method that was found into this classes set of methods to compile. More...
 

Protected Attributes

int AnonymousCount
 A counter used to name anonymous methods. More...
 

Package Functions

virtual FieldInfo DefineField (string name, bool isPublic, Type type)
 Defines a new field on this class. More...
 

Private Member Functions

MethodOverloads MakeOrFind (string name, Type returnType)
 Finds the method overload set with the given name and creates it if it doesn't exist. More...
 
void GloballyScope (CodeFragment fragment)
 Globally scopes the given fragment. This is like stripping the word 'var' from any discovered properties. More...
 
CompiledMethod GetStartMethod ()
 Gets the OnScriptReady method. May create it if it's not available. More...
 
CompiledMethod GetInit ()
 Gets the init method. May create it if it's not already available. More...
 

Constructor & Destructor Documentation

Nitro.CompiledClass.CompiledClass ( )
inline

Creates a new class. Note you must call StartType manually.

Nitro.CompiledClass.CompiledClass ( CodeFragment  classFragment,
NitroCode  script,
string  name,
Type  baseType,
bool  isPublic 
)
inline

Member Function Documentation

virtual CodeFragment Nitro.CompiledClass.AddFoundMethod ( CodeFragment  fragment,
CodeFragment  body,
string  name,
bool  anonymous,
BracketFragment  parameters,
TypeFragment  returnType,
bool  isPublic 
)
inlineprotectedvirtual

Adds a method that was found into this classes set of methods to compile.

Parameters
fragmentThe first fragment of the method, used for generating errors. This gives a valid line number.
bodyThe block of code for this method.
nameThe name of the method. Null if anonymous is true.
anonymousTrue if this method is an anonymous one and requires a name.
parametersThe set of parameters for this method.
returnTypeThe type that this method returns.
isPublicTrue if this is a public method; false for private.
Returns
The first fragment following the method, if there is one.
void Nitro.CompiledClass.Compile ( )
inline

Compiles this class from its ClassFragment.

bool Nitro.CompiledClass.ContainsField ( string  field)
inline

Checks if this class contains the field with the given name.

Parameters
fieldThe name of the field to look for.
Returns
True if the field is in this class, false otherwise.
bool Nitro.CompiledClass.ContainsMethod ( string  name)
inline

Checks if this class contains the method with the given name.

Parameters
nameThe name of the method to look for.
Returns
True if the method is in this class, false otherwise.
virtual FieldInfo Nitro.CompiledClass.DefineField ( string  name,
bool  isPublic,
Type  type 
)
inlinepackagevirtual

Defines a new field on this class.

Parameters
nameThe name of the field.
typeThe type of the value held by this field.
Returns
A new FieldBuilder.
MethodInfo Nitro.CompiledClass.FindMethodOverload ( string  name,
CompiledFragment[]  arguments 
)
inline

Gets a particular method (it may be overloaded) from this class.

Parameters
nameThe name of the method.

<param name=arguments">The set of arguments being used in calling this method.

Returns
The MethodInfo for the method if found; null otherwise.
MethodInfo Nitro.CompiledClass.FindMethodOverload ( string  name,
Type[]  arguments 
)
inline

Gets a particular method (it may be overloaded) from this class.

Parameters
nameThe name of the method.

<param name=arguments">The types of the set of arguments being used in calling this method.

Returns
The MethodInfo for the method if found; null otherwise.
void Nitro.CompiledClass.FindMethods ( CodeFragment  fragment)
inline

Finds methods within the given fragment by looking for 'function'.

Parameters
fragmentThe fragment to search.
MethodOverloads Nitro.CompiledClass.FindMethodSet ( string  name)
inline

Finds the overload set for the method with the given name.

Parameters
nameThe name of the method.
Returns
The methods overload set if found; null otherwise.
void Nitro.CompiledClass.FindOperations ( CodeFragment  fragment)
inline

Finds any other entries in the given code fragment.

Parameters
fragmentThe fragment to search.
Type Nitro.CompiledClass.GetAsType ( )
inline

Gets this class as a system type.

Returns
This classes system type.
FieldInfo Nitro.CompiledClass.GetField ( string  name)
inline

Gets the field from this class with the given name.

Parameters
nameThe name to look for.
Returns
A FieldInfo object if the field exists; null otherwise.
CompiledMethod Nitro.CompiledClass.GetInit ( )
inlineprivate

Gets the init method. May create it if it's not already available.

Returns
The init method.
PropertyInfo Nitro.CompiledClass.GetProperty ( string  name)
inline

Gets the property from this class with the given name.

Parameters
nameThe name to look for.
Returns
A PropertyInfo object if the field exists; null otherwise.
CompiledMethod Nitro.CompiledClass.GetStartMethod ( )
inlineprivate

Gets the OnScriptReady method. May create it if it's not available.

Returns
The start method. All code outside of functions that isn't a variable goes into this.
void Nitro.CompiledClass.GloballyScope ( CodeFragment  fragment)
inlineprivate

Globally scopes the given fragment. This is like stripping the word 'var' from any discovered properties.

MethodOverloads Nitro.CompiledClass.MakeOrFind ( string  name,
Type  returnType 
)
inlineprivate

Finds the method overload set with the given name and creates it if it doesn't exist.

Parameters
nameThe name of the method.
returnTypeThe type that this method returns.
Returns
The method overload set.
Type Nitro.CompiledClass.MethodReturnType ( string  name)
inline

Gets the return type of a given method by name. Note all overloads must return the same thing.

Returns
The type of object this method returns.
void Nitro.CompiledClass.StartType ( string  name,
NitroCode  script,
Type  baseType 
)
inline

Starts creating this class.

Parameters
nameThe name of the class.
scriptThe parent script this class belongs to.
baseTypeThe type that this class will derive from.

Member Data Documentation

int Nitro.CompiledClass.AnonymousCount
protected

A counter used to name anonymous methods.

Type Nitro.CompiledClass.BaseType

The type that this class derives from, if any.

TypeBuilder Nitro.CompiledClass.Builder

The type builder used to construct a system type from this class.

CodeFragment Nitro.CompiledClass.ClassFragment

The content of this whole class as parsed from the code.

Type Nitro.CompiledClass.compiledType

When fully compiled, this is the resulting system type of this class.

Dictionary<string,FieldInfo> Nitro.CompiledClass.Fields =new Dictionary<string,FieldInfo>()

All the fields of this class.

bool Nitro.CompiledClass.IsPublic =true

True if this is a public class, false for private.

Dictionary<string,MethodOverloads> Nitro.CompiledClass.Methods =new Dictionary<string,MethodOverloads>()

All methods contained by this class grouped into overloads.

NitroCode Nitro.CompiledClass.Script

The script this class belongs to.