A set of tools have been developed in order to easier the work with the intermediate representation.
Table of Contents
Tree manipulation tools
Provide some tools for manage the source code files that have to be stored
Represents a generic file type. It should be inherited to create a specific file type:
FileType
|
----- -----
| |
C_FileType H_FileType
Method that returns always the same instance of the class. Is a design pattern called singleton
Warning
This way of implementing singleton is not thread-safe.
Return a pretty representation of the file :param text: The original text to be pretty printed
Storage of project files. It has tree attributes
base_dir = The path to the directory where will be the files
dir_name = The name of the directory
_files = A dictionary where all the files are stored.
An example of this dictionary that contains two files:
{
'main.c' : [object of C_FileType, "#include <stdio.h>..."],
'main.h' : [object of H_FileType, "#ifndef MAIN_H..."],
}
Usage example:
cFile = C_FileType()
s1 = SourceStorage.Storage (config.WORKDIR,'/prueba')
s1.addFile ('prueba', cFile)
s1.append('prueba', cFile, '#include "<stdio.h>"\nint main(){\n return 0;\n}')
Add a new file to the storage
Parameters: |
|
---|
Add a string to the specified file
Parameters: |
|
---|
Close the storage and write the files
Make a proper copy of a Storage object
Parameters: | element – The object to be copied from |
---|
Defrost the object from a json file
Parameters: |
|
---|
Return true if exists the specified element
Parameters: | name – The name of the stored file |
---|
Freeze the object in a json file
Parameters: |
|
---|
Get the name of all the stored elements
Get the specified file
Parameters: | name – The name of the stored file |
---|---|
Returns: | A list with two objects:
|
Get the number of elements
Compare two source storages. If are equals the function returns true and a blank line. If are different the function returns false and a line with the differences in a format like the diff from Linux
Parameters: | sourceStorage – The other object to be compared with |
---|---|
Returns: | An array with this structure[False, []]
[True, [[name_of_the_file, differences]]]
|
Overwrite the specified file
Parameters: |
|
---|
Provide functionality to look for declarations on the AST
DotDebugTool allows developers to show the Intermediate Representation during translation. This is useful for debugging or learning pourposes.
This module uses the xdot visualization tool based on graphviz and pygtk, thus, this two packages are required to visualize the subtrees.