#include <include/EDoc/TranslationUnit.h>
Translation unit instances when created remain around for the entire duration of the program execution.
A translation unit instance should be created for every new translation unit encounteded from a .edc file. This is how we ensure uniqueness of translation units. We assign an integer identifier to a translation unit when it is created that is used throught the execution of the program, but not stored in any .edc files. It is assumed that in a single execution there are NO DUPLICATE TRANSLATION UNITS CREATED/LOADED. This is an important limitation.
In order to create a new translation unit use the Create() function().
HISTORY
Before this class was created a translation unit was identified by the main_input_source as supplied by GCC. However this can be have the same name for different translation units that are linked together. So we created this to ensure that every translation unit encountered is considered unique and so there is no consideration that we can load a single translation unit twice in a single execution of EDoc.
Definition at line 59 of file TranslationUnit.h.
Public Member Functions | |
TranslationUnit () | |
NOT TO BE USED. | |
const std::string & | GetName () const |
Returns the name of the main code file used to compile this translation unit. | |
uint32_t | GetID () const |
Returns the unique identified for this translation unit. | |
std::ostream & | Print (std::ostream &out, std::string prefix="") const |
Print the current object to the given stream in a user readable manner. | |
std::string | ToString (std::string prefix="") const |
Returns a string representing the current object in a user readable manner. | |
Static Public Member Functions | |
static TranslationUnit * | GetUnknown () |
returns the TranslationUnit instance for the special "unknown" translation unit. | |
static TranslationUnit * | Create (std::string name_in) |
Create a new translation unit. | |
Private Member Functions | |
TranslationUnit (std::string name_in, uint32_t id_in) | |
Constructor. | |
Private Attributes | |
uint32_t | id |
The unique id of this translation unit. | |
std::string | name |
The not-necessarily unique name given to this translation unit. | |
Static Private Attributes | |
static uint32_t | next_id |
The id that will be used for the next translation units unique id. | |
static std::list< TranslationUnit > | translation_units |
A list of all translation units created during this program execution. | |
static TranslationUnit * | UNKNOWN |
The unknown translation unit instance. |
EDoc::TranslationUnit::TranslationUnit | ( | ) |
NOT TO BE USED.
This was created specifically because I have yet to find out how to get SWIG to work when there is no default constructor for a class.
Definition at line 33 of file TranslationUnit.cpp.
Referenced by Create(), and GetUnknown().
EDoc::TranslationUnit::TranslationUnit | ( | std::string | name_in, | |
uint32_t | id_in | |||
) | [private] |
Constructor.
Private so onlt Create() can be used to create translation unit instances.
Definition at line 37 of file TranslationUnit.cpp.
EDoc::TranslationUnit::GetUnknown | ( | ) | [static] |
returns the TranslationUnit instance for the special "unknown" translation unit.
This is primarily used whena translation unit instance is required for hand crafted special objects like Dictionary::SUBSTITUTION_EXCEPTION_TYPE
Definition at line 44 of file TranslationUnit.cpp.
References next_id, translation_units, TranslationUnit(), and UNKNOWN.
Referenced by Create(), EDoc::Dictionary::GeneratePredefined(), EDoc::Dictionary::GetIndexedTranslationUnit(), and EDoc::Dictionary::GetTranslationUnitIndex().
EDoc::TranslationUnit::Create | ( | std::string | name_in | ) | [static] |
Create a new translation unit.
name_in | Is a string that identifies the translation unit but is not necessarily unique. This is usually the .c or .cpp file name that was used to compile the translation unit. |
Definition at line 55 of file TranslationUnit.cpp.
References GetUnknown(), next_id, translation_units, and TranslationUnit().
Referenced by EDoc::Dictionary::Read().
EDoc::TranslationUnit::GetName | ( | ) | const |
Returns the name of the main code file used to compile this translation unit.
Definition at line 65 of file TranslationUnit.cpp.
References name.
Referenced by EDoc::Type::GetNameInternal(), EDoc::Type::Merge(), EDoc::Function::Read(), EDoc::Type::Write(), and EDoc::Function::Write().
EDoc::TranslationUnit::GetID | ( | ) | const |
Returns the unique identified for this translation unit.
Unique within a single execution of EDoc. A translation unit will not necessarily have the same identifier between EDoc executions.
Definition at line 70 of file TranslationUnit.cpp.
References id.
Referenced by EDoc::Type::GetNameInternal(), EDoc::Type::Merge(), EDoc::Type::operator==(), and EDoc::Function::Read().
EDoc::TranslationUnit::Print | ( | std::ostream & | out, | |
std::string | prefix = "" | |||
) | const |
Print the current object to the given stream in a user readable manner.
out | The stream to print to. | |
prefix | A string prefix to display at the start of every line. As an example this can be used in order to indent the print by passing "\t" as the string. |
Definition at line 75 of file TranslationUnit.cpp.
References name.
Referenced by std::operator<<(), and ToString().
EDoc::TranslationUnit::ToString | ( | std::string | prefix = "" |
) | const |
Returns a string representing the current object in a user readable manner.
This will return as a string exactly what Print() would display. This is primarily here for use from within python and for debugging.
Definition at line 83 of file TranslationUnit.cpp.
References Print().
uint32_t EDoc::TranslationUnit::next_id [static, private] |
The id that will be used for the next translation units unique id.
Definition at line 133 of file TranslationUnit.h.
Referenced by Create(), and GetUnknown().
std::list< TranslationUnit > EDoc::TranslationUnit::translation_units [static, private] |
A list of all translation units created during this program execution.
Definition at line 139 of file TranslationUnit.h.
Referenced by Create(), and GetUnknown().
TranslationUnit * EDoc::TranslationUnit::UNKNOWN [static, private] |
The unknown translation unit instance.
Definition at line 144 of file TranslationUnit.h.
Referenced by GetUnknown().
uint32_t EDoc::TranslationUnit::id [private] |
The unique id of this translation unit.
Definition at line 157 of file TranslationUnit.h.
Referenced by GetID().
std::string EDoc::TranslationUnit::name [private] |
The not-necessarily unique name given to this translation unit.
Definition at line 162 of file TranslationUnit.h.