Tools

A set of tools have been developed in order to easier the work with the intermediate representation.

Tree Tools

Tree manipulation tools

File Management Tools

Provide some tools for manage the source code files that have to be stored

class Tools.SourceStorage.FileType(name, extension)

Represents a generic file type. It should be inherited to create a specific file type:

       FileType
           |
      ----- -----
      |         |
C_FileType   H_FileType     
instance = None

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.

pretty_print(text)

Return a pretty representation of the file :param text: The original text to be pretty printed

class Tools.SourceStorage.Storage(base_dir, dir_name)

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}')
addFile(name, file_type)

Add a new file to the storage

Parameters:
  • name – Name of the file
  • file_type – Instance of FileClass, specifying the type of the file
append(name, file_type, string)

Add a string to the specified file

Parameters:
  • name – Name of the file
  • file_type – FileType instance
  • string – String to be added
closeStorage()

Close the storage and write the files

copy(element)

Make a proper copy of a Storage object

Parameters:element – The object to be copied from
defrost(freeze_path, freeze_file)

Defrost the object from a json file

Parameters:
  • freeze_path – The path to the file
  • freeze_file – The file that contains the serialized objects
existsElement(name)

Return true if exists the specified element

Parameters:name – The name of the stored file
freeze(freeze_path, freeze_file)

Freeze the object in a json file

Parameters:
  • freeze_path – The path to the file
  • freeze_file – The file that will be contain the serialized objects
getAllNames()

Get the name of all the stored elements

getElement(name)

Get the specified file

Parameters:name – The name of the stored file
Returns:A list with two objects:
  1. An object that represents the type of the file
  2. The text of the element
getNumberOfElements()

Get the number of elements

isTheSame(sourceStorage)

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(name, file_type, string)

Overwrite the specified file

Parameters:
  • name – Name of the file
  • file_type – FileType instance
  • string – String to be added

Declarations Tools

Provide functionality to look for declarations on the AST

Debug Tools

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.

Table Of Contents

Previous topic

CUDA Backend

Next topic

yacf/llCoMP

This Page