mib_generator.parsing package
These modules serve the purpose of parsing the inputted C/header files into a variety Python objects, that can be then easily accessed at the later construction stage of the process. The resulting product with parsed objects should contain all information in the input files, which requires the representation to be a bit convoluted from place to place, but still understandable I hope.
The submodules here are:
load- Module that allows for interaction between the parser and rest of the code.
parser_main- Module that initialises the parsing process for a given file and holds class that represents the result.
par_cfile- Module that holds the methods and classes for parsing.cfiles.
par_header- Module that holds the methods and classes for parsing header.hfiles.
par_header- Module holding various methods that are used by other modules throughout the parsing process.
Submodules
mib_generator.parsing.load module
Central location from which other modules can source data from the parsed C-files.
This module is initialised and its methods are called in the first step of the MIB construction process. At this point the C-files
are loaded from the defined paths, are parsed using the mib_generator.parsing.parser_main.main method and are
subsequently available for other scripts throughout the rest of the MIB construction process. The only other
method here is extr_values which serves the purpose creating a global evaluation dictionary holding
values from all header enums, macros, etc…
- mib_generator.parsing.load.TmH
Holds the Python parsed representation of the Tm-header C-files. Each of type
mib_generator.parsing.parser_main.file- Type:
list
- mib_generator.parsing.load.TcH
Holds the Python parsed representation of the Tc-header C-files. Each of type
mib_generator.parsing.parser_main.file- Type:
list
- mib_generator.parsing.load.TcTmH
Holds the Python parsed representation of the TcTm-header C-files. Each of type
mib_generator.parsing.parser_main.file- Type:
list
- mib_generator.parsing.load.TmC
Holds the Python parsed representation of the Tm (normal) C-files. Each of type
mib_generator.parsing.parser_main.file- Type:
list
- mib_generator.parsing.load.enumerations
A dictionary containing all possible usable evaluations/enumerations sourced form enums, macros, etc… found in all 3 of the parsed header files.
- Type:
dict
- mib_generator.parsing.load.enum_stuff()[source]
Create a dictionary that includes all the possible evaluations from the input files.
For each of the inputted (and processed) C-files, this method extracts an evaluation (dictionary including all possible variable substitutions, from e.g. enum objects.) and then joins all of these dictionaries to one and assigns it to a global variable so it can be easily accessed.
- mib_generator.parsing.load.extr_values(files)[source]
Create a dictionary from constants,
enumcorrespondences, etc… in the given files.Goes through all objects in the parsed files and for each
enumand macro, appends the name-value pairs present to a dictionary (which represents the “global” evaluation in the file).- Parameters:
files (list) – Files from which the evaluation dictionary is to be extracted. Each of type
mib_generator.parsing.parser_main.file- Returns:
A dictionary with all possible “global” evaluation found in the given file.
- Return type:
dict
- mib_generator.parsing.load.get_paths()[source]
Load paths from the temporary config files.
This method looks up paths to each of the input files in the config files in the runtime config directory. It then saves these paths as global attributes of the
mib_generator.parsing.loadmodule, so they can be easily accessed to other methods in the whole program.
- mib_generator.parsing.load.load_all()[source]
Run all initialisation and parsing methods.
This method (replacing previous simple initialisation of this module) runs other methods, which
Load the paths to input C-files.
2. Load the configuration settings. 2. Parse files at these paths. 3. Create evaluation dictionary from these parsed files.
- mib_generator.parsing.load.parse_all()[source]
Parse the inputted C-files and save the output.
This method uses the
mib_generator.parsing.parser_mainmodule to parse contents of the files specified at the paths given by global attributes of this module. It then assigns the outputs of the parsing process to various other global attributes of this module, so they can be easily accessed.
mib_generator.parsing.par_cfile module
Parsing and structural interpretation module for C files.
This module holds functions and classes serving the purpose of parsing C files containing information about the structure of packets and commands. The parsing in general happens mostly by recognising (a subset of) standard C-syntax and the system of Python representations of C-objects tries to include all possible information present in the C file, which makes it perhaps a bit too convoluted.
- class mib_generator.parsing.par_cfile.instance(typ, inds, inde, cont)[source]
Bases:
instance_ogClass of “first order” C structure/object found in the body of the file.
This class is a Python representation of an instance of a defined “top-level” object in the C-file. It does correspond to any specific type of such object (like
struct,uint8, …) unlike its child-classes, but rather holds general properties and methods that all of these classes need, like parsing into array of elements.All parameters are passed into the
instance_ogclass from which this structure also inherits all its attributes.- name
The name of the instance of a C-object.
- Type:
str
- array
Equals to “-1” if the object isn’t an array and otherwise denotes the number of elements found in the array. Either as an int number or some abstract expression to be evaluated later.
- Type:
str
- elements
List of elements present if the structure is an array. Each of the elements is either of class
struct_rormisc_r.- Type:
list
- reposition()[source]
Use classic ordering if no specific position of each element of a structure is declared.
The C-code at the level of instances of the structure in the array can contain information about a custom ordering inside this array. This is found while parsing the structure-instances, however if this information is not present, the default ordering has to be used instead which is what this function does by rewriting positions of the elements in the array in such case.
- str_parse(cont)[source]
Parse the content of the C-object into its syntactic/semantic components.
By first looking for whitespace characters and various types of brackets and then calling classes
struct_randmisc_r, this function parses the text of the C-object into its name, array size and entries present.- Parameters:
cont (str) – The raw text of the C-object as found in the C file.
- Returns:
A tuple containing:
- Return type:
tuple
- class mib_generator.parsing.par_cfile.instance_og(typ, inds, inde, cont)[source]
Bases:
objectParent class of all representations of the C-objects.
This class holds properties which are shared by all Python representations of C-objects found in the analysed file.
- Parameters:
typ (str) – The type of the C-object (e.g.
structorenum).inds (int) – Starting index of the C-object.
inde (int) – End index of the C-object.
cont (str) – Raw text of the C-object as in the source file.
- type
The type of the C-object (e.g.
structorenum).- Type:
str
- start
Starting index of the C-object.
- Type:
int
- end
End index of the C-object.
- Type:
int
- text
Raw text of the C-object as in the source file.
- Type:
str
- comment
List holding all found interpretable comments associated to this C-object.
- Type:
list
- class mib_generator.parsing.par_cfile.misc_r(typ, inds, inde, cont)[source]
Bases:
instance_ogClass of a singular instance of a constant within an array.
This class represents a specific instance of a constant (e.g.
unit32, …) inside a defined array. The contents of this instance are parsed (based on whitespace characters and “=”) such that the extracted information are the position of this instance inside the array and the defined value of this instance.All parameters are passed into the
instance_ogclass from which this structure also inherits all its attributes.- position
Position of the instance inside an array. Can be either a specific integer or an abstract expression to be interpreted later.
- Type:
str
- value
A value of this instance of the constant. Can be either a specific integer or an abstract expression to be interpreted later.
- Type:
str
- mis_parse(cont)[source]
Parse the information about the constant instance.
Based on the presence of “=” and whitespace characters this function recognises the presence of an identifier of the position of the constant instance (inside the array) and interprets the rest as the expression/value assigned to this instance.
- Parameters:
cont (str) – Raw text of the C-code defining the object instance.
- Returns:
A tuple containing:
- Return type:
tuple
- class mib_generator.parsing.par_cfile.miscal(typ, inds, inde, cont)[source]
Bases:
instanceClass of an instance of an array of constants.
This class represents an instance of definition of a constant (e.g.
unsigned integer,uint16, etc…) in the C-file. Being possibly an array of such objects, it inherits frominstance, which already does most of the parsing, so at creation of this child-class, only some already parsed information are rewritten and corrected rather than the parsing happening from scratch.All parameters are passed into the
instanceclass from which this structure also inherits all its attributes.- add_parse(name)[source]
Correct information about the object’s name.
Looks again at the string identified by
instanceas the object’s name, correct it (e.g. delete whitespace characters from it) and also save this name as a propertymisc_r.flavof each instance of the object in the array.- Parameters:
name (str) – The possibly wrong name of the structure as recognised by the parser in
instance- Returns:
The actual name of the structure.
- Return type:
str
- mib_generator.parsing.par_cfile.str_parse(stri)[source]
Parse the given string into blocks of “top-level” C-structures.
By going iteratively through the string and recognising the features of standard C-syntax, this function first marks the positions of all C-objects (including
#definemacro declaration) and then creates an appropriate Python representation-object of them, which then at its initialisation further parses the inner structure of these objects. After going through the whole string, this function then returns all found C-objects in a list.- Parameters:
stri (str) – A string to be parsed/analysed into the C-objects.
- Returns:
List of Python representations of found C-objects, each represented by an object of child-class of
instance- Return type:
list
- class mib_generator.parsing.par_cfile.struct(typ, inds, inde, cont)[source]
Bases:
instanceClass of an instance of an array of structs.
This class represents an instance of definition of a C-structure
structin the C-file. Being possibly an array of such structures, it inherits frominstance, which already does most of the parsing, so at creation of this child-class only, some already parsed information are rewritten and corrected rather than the parsing happening from scratch.All parameters are passed into the
instanceclass from which this structure also inherits all its attributes.- flav
The type of the
struct, i.e. name of thestructdeclared possibly in the header of which this structure/array of structures is an instance.- Type:
str
- class mib_generator.parsing.par_cfile.struct_r(typ, inds, inde, cont)[source]
Bases:
instance_ogClass of a singular instance of
structwithin an array.This class represents a specific instance of a C-structure inside a defined array. The contents of this instance are parsed (based on brackets and commas) such that the extracted information are the position of this instance inside the array and the contents of the defined array represented by a Python dictionary.
All parameters are passed into the
instance_ogclass from which this structure also inherits all its attributes.- position
Position of the instance inside an array. Can be either a specific integer or an abstract expression to be interpreted later.
- Type:
str
- entries
A dictionary representing the defined contents of the instance of the
struct.- Type:
dict
- srr_parse(cont)[source]
Parse the
structinstance into its entries.Based on the presence of “=”, brackets and commas, this function recognises the presence of an identifier of the position of the structure instance (inside the array) and each of the entries inside the structure definitions. It then further interprets the former and creates a dictionary from the latter.
- Parameters:
cont (str) – Raw text of the C-code defining the object.
- Returns:
A tuple containing:
str - Position of the instance. See
position.dict - A dictionary with the entries found in the
structinstance.
- Return type:
tuple
mib_generator.parsing.par_header module
Parsing and structural interpretation module for C-header files.
This module holds functions and classes serving the purpose of parsing C-header files containing information about the structure of packets and commands. The parsing in general happens mostly by recognising (a subset of) standard C-syntax and the system of Python representations of C-objects tries to include all possible information present in the C-header file, which makes it perhaps a bit too convoluted.
- class mib_generator.parsing.par_header.define(typ, inds, inde, cont)[source]
Bases:
structureClass of a
#definemakro.This class is a Python representation of an occurrence of
#definemacro in the C-header file. The inner structure of the macro is parsed and represented as a name and an expression.All parameters are passed into the
structureclass from which this structure also inherits all its attributes.- name
The name of the definition in the macro.
- Type:
str
- expression
A string with the expression or value that the macro points to.
- Type:
str
- def_parse(cont)[source]
Parse the
#definemacro into its syntactic/semantic components.By looking for whitespace characters, parses the text of the macro into its name and the expression it points to.
- Parameters:
cont (str) – The text of the macro.
- Returns:
A tuple containing:
str - The name of the macro.
str - The expression the macro points to.
- Return type:
tuple
- class mib_generator.parsing.par_header.enum(typ, inds, inde, cont)[source]
Bases:
structureClass of an
enumC-object.This class is a Python representation of an occurrence of
enumin the C-header file. The inner structure of theenumis parsed and represented as a Python dictionary.All parameters are passed into the
structureclass from which this structure also inherits all its attributes.- name
Name of the
enumobject.- Type:
str
- entries
Dictionary containing key-value pairs found in the
enum.- Type:
dict
- ele_parse(cont)[source]
Parse
enuminto its syntactic/semantic components.By recognising and parsing the inner syntax of
enumthis function identifies all elements in it and the values assigned to them (be it directly or implicitly by the order of the elementsenum). Subsequently it represents these key-value pairs by a Python dictionary.- Parameters:
cont (str) – Text of the whole
enumobject.- Returns:
A tuple containing:
str - The name of the
enum.dict - A dictionary representing the entries in the
enumand the values/expressions assigned to them.
- Return type:
tuple
- class mib_generator.parsing.par_header.enum_r(typ, inds, inde, cont)[source]
Bases:
structureClass of a reference to an
enuminside a C-structure.This class is used to represent occurrence of reference to
enuminside a C-structure (astructobject). It can be of two types:All parameters are passed into the
structureclass from which this structure also inherits all its attributes.- name
The name of the referenced
enum.- Type:
str
- form
Either name of the referenced
enumor directly the object of the referencedenum.- Type:
str or enum
- bites
Number of bites that the value of this
enumis represented by.- Type:
int
- array
An expression set to “-1” if the
enumreference is not an array and to its number of elements (either integer value or an text expression to be later evaluated) in case it is an array.- Type:
str
- enr_parse(cont)[source]
Parse the reference to its syntactic/semantic components.
By looking for “{” and “}” this function first decides whether the references includes a nested
enumor only and external reference. Depending on the result it either calls the classenumor leaves the reference as a text. It then continues by looking for the name, array and bites information, etc by looking at the whitespaces and brackets.- Parameters:
cont (str) – The text of the
enumreference to be analysed.- Returns:
A tuple consisting of:
- Return type:
tuple
- class mib_generator.parsing.par_header.extern(typ, inds, inde, cont)[source]
Bases:
structureClass of external declaration of a constant.
This class is a Python representation of an occurrence of external constant declaration in the C-header file. The inner structure of the expression is parsed and represented as its name, type (e.g.
uint8) and an information on whether it is an array.All parameters are passed into the
structureclass from which this structure also inherits all its attributes.- name
The name of the external declaration.
- Type:
str
- flav
The data type of the declaration (e.g.
"uint8")- Type:
str
- array
An expression set to “-1” if the declared constant is not an array and to its number of elements (either integer value or an text expression to be later evaluated) in case it is an array.
- Type:
str
- ext_parse(cont)[source]
Parse the external declaration of a constant into its syntactic/semantic components.
By looking for whitespace characters and square brackets, parses the text of the declaration into its name, data type and n information on whether it is an array.
- Parameters:
cont (str) – The text of the declaration to be parsed.
- Returns:
A tuple containing:
str - The data type of the declaration (e.g.
"unsigned integer").str - The name of the declaration.
str - The information on its array size (see above for more detail).
- Return type:
tuple
- class mib_generator.parsing.par_header.misc_r(typ, inds, inde, cont)[source]
Bases:
structureClass of a declaration of a constant inside a C-structure.
This class is a Python representation of an occurrence of constant value declaration (e.g.
uint8) inside of some C-structure . The inner structure of the expression is parsed and represented as its name, bite length and an information on whether it is an array.All parameters are passed into the
structureclass from which this structure also inherits all its attributes.- name
The name of the declared constant.
- Type:
str
- bites
Number of bites that the value of this constant is represented by.
- Type:
int
- array
An expression set to “-1” if the constant is not an array and to its number of elements (either integer value or an text expression to be later evaluated) in case it is an array.
- Type:
str
- mir_parse(cont)[source]
Parse the declaration into its syntactic/semantic components.
By looking at whitspaces and brackets in the string this function parses the text of the declaration into the name of the constant, and information about its bite-length and array-size.
- Parameters:
cont (str) – The text of the constant declaration.
- Returns:
A tuple containing:
str - The name of the constant.
int - The declared bite-length of the constant.
str - See the attribute
arrayabove.
- Return type:
tuple
- mib_generator.parsing.par_header.str_parse(stri)[source]
Parse the given string into blocks of “top-level” C-structures.
By going iteratively through the string and recognising the features of standard C-syntax, this function first marks the positions of all C-objects (including
#definemacro declaration) and then creates an appropriate Python representation-object of them, which then at its initialisation further parses the inner structure of these objects. After going through the whole string, this function then returns all found C-objects in a list.- Parameters:
stri (str) – A string to be parsed/analysed into the C-objects.
- Returns:
List of Python representations of found C-objects, each represented by an object of child-class of
structure- Return type:
list
- mib_generator.parsing.par_header.str_parse_r(offset, stri)[source]
Parse the given string into “2nd-order” blocks of C-structures.
Unlike for
str_parsethis time “second-order” strings (that is strings inside other already recognised C-objects; i.e. e.g. inner content ofstructdeclaration) are expected and the parsing itslef is recursive (in order to account e.g. for multiple nested occurences ofstruct).- Parameters:
offset (int) – Offset of this string from the start of the original file. I.e. original start index of its first character.
stri (str) – The string to be parsed/interpreted into its contents.
- Returns:
List of identified and interpreted C-object inside the original string. Each is represented by an object which is some child-class of the class
structure.- Return type:
list
- class mib_generator.parsing.par_header.struct(typ, inds, inde, cont)[source]
Bases:
structureClass of declaration of a C-structure
struct ....This class is a Python representation of an occurrence of
structstructure in the C-header file. The inner structure of this … structure is represented by its name, information on whether it is packed and its contents/elements (which are themselves other similar Python objects).All parameters are passed into the
structureclass from which this structure also inherits all its attributes.- name
The name of the structure.
- Type:
str
- packed
True if the structure is packed, false otherwise.
- Type:
bool
- elements
A list of elements inside this structure. Each is represented by a Python object which is some child-class of
structure- Type:
list
- stc_parse(cont)[source]
Parse the
structC-structure into its syntactic/semantic components.By first looking for whitespace characters and “{” and then calling
str_parse_r, this function parses the text of thestructobject into its name, entries, etc.- Parameters:
cont (str) – The raw text of the
structC-structure in the C-header file.- Returns:
A tuple containing:
str - The name of the C-structure.
bool -
Trueif the structure is packed,Falseotherwise.list - List of elements inside the structure. Each represented by an object of child-class of
structure.
- Return type:
tuple
- class mib_generator.parsing.par_header.struct_r(typ, inds, inde, cont)[source]
Bases:
structureClass of a reference to a C-structure
structinside another.This class is used to represent occurrence of declaration of one structure inside another. It can be of two types:
All parameters are passed into the
structureclass from which this structure also inherits all its attributes.- name
The name of the referenced C-structure.
- Type:
str
- form
Either name of the referenced structure or directly the object of the referenced structure.
- Type:
str or struct
- array
An expression set to “-1” if the
structreference is not an array and to its number of elements (either integer value or an text expression to be later evaluated) in case it is an array.- Type:
str
- str_parse(cont)[source]
Parse the reference to its syntactic/semantic components.
By looking for “{” and “}” this function first decides whether the references includes a nested structure or only and external reference. Depending on the result it either calls the class
structor leaves the reference as a text. It then continues by looking for the name, array information, etc by looking at the whitespaces and brackets.- Parameters:
cont (str) – The text of the structure reference to be analysed.
- Returns:
A tuple consisting of:
- Return type:
tuple
- class mib_generator.parsing.par_header.structure(typ, inds, inde, cont)[source]
Bases:
objectParent class of all representations of the C-objects.
This class holds properties which are shared by all Python representations of C-objects found in the analysed file.
- Parameters:
typ (str) – The type of the C-object (e.g.
structorenum).inds (int) – Starting index of the C-object.
inde (int) – End index of the C-object.
cont (str) – Raw text of the C-object as in the source file.
- type
The type of the C-object (e.g.
structorenum).- Type:
str
- start
Starting index of the C-object.
- Type:
int
- end
End index of the C-object.
- Type:
int
- text
Raw text of the C-object as in the source file.
- Type:
str
- comment
List holding all found interpretable comments associated to this C-object.
- Type:
list
mib_generator.parsing.par_methods module
Depository of parsing methods.
This module holds various methods used for parsing of the header and normal C files and their subsequent interpretation into corresponding python objects.
- mib_generator.parsing.par_methods.clean(stri, tokens)[source]
Replace tokens with spaces.
Takes a string and a list of tokens and replaces all occurences of the tokens in the string with an appropriate number of space so the absolute positions of unaffected parts of the string stay the same.
- Parameters:
stri (str) – A string to be “cleaned”.
tokens (set) – A set of tokens to be replaced.
- Returns:
The resulting “cleaned” string.
- Return type:
str
- mib_generator.parsing.par_methods.com_parse(comm)[source]
Parse the comments in the string into blocks corresponding to singular comments.
Looks at each passed comment and evaluates whether it should be interpreted or not. If yes, it then calls the class
commentfrom it and adds this object to the list of interpreted comments.- Parameters:
comm (list) – List of strings each representing the content of a single comment.
- Returns:
List of found interpreted comments, each represented by an object of the
commentclass.- Return type:
list
- class mib_generator.parsing.par_methods.comment(start, end, text)[source]
Bases:
objectClass representing an occurrence of an interpretable comment in the file, entries found in it, etc.
Saves the comment text and its start/end indexes and then it tries to interpret the comment as a dictionary represented in the json5 format.
- Parameters:
start (int) – Start index of the comment in the original file.
end (int) – End index of the comment in the original file.
text (str) – Original text of the comment.
- start
Start index of the comment in the original file.
- Type:
int
- end
End index of the comment in the original file.
- Type:
int
- text
Original text of the comment.
- Type:
str
- entries
Dictionary containing the content of the comment found in the json5 string.
- Type:
dict
- mib_generator.parsing.par_methods.erase_text(stri)[source]
Erase all text inside quotation marks in the given string.
Looks for first order quotation marks (that is, not inside another quotation marks) and replaces their content with matching amount of spaces so that the total length of the string remains the same.
- Parameters:
stri (str) – The string in which the quotation marks are to be replaced.
- Returns:
The string with the quotation marks contents replaced.
- Return type:
str
- mib_generator.parsing.par_methods.line_index(stri)[source]
Give list of indexes of line starts of the given string.
Based on the newline character, looks for indexes of new lines and adds them to a list.
- Parameters:
stri (str) – The string to be analysed.
- Returns:
List of indexes at which new lines start.
- Return type:
list
- mib_generator.parsing.par_methods.preproc_eval(variab)[source]
Evaluate whether a pre-processing condition holds.
Looks into config file whether the passed pre-processing condition holds. If the condition name does not occur in the config file, asks the user what boolean value it should assign to it.
- Parameters:
variab (str) – Name of the pre-processing variable/condition to be evaluated.
- Returns:
Truth-value of the condition.
- Return type:
bool
- mib_generator.parsing.par_methods.preproc_filter(stri_o, stri_c)[source]
Filter out what parts of the C-code should be further considered based on preprocessor directives.
First, this function looks for blocks pre-processor logic using the
preproc_parsefunction. It then evaluates the condition associated with this logic withpreproc_evaland depending on the result, decides what parts of the string should be deleted (replaced by equal number of spaces). Finally it performs this replacement.The preprocessor logic is determined based on the passed string with the code (
stri_o), but the deliting is applied also to the string with comment (stri_c).- Parameters:
stri_o (str) – The text with C-code to be filtered on the basis of pre-processor logic.
stri_c (str) – The text with comments to be filtered on the basis of pre-processor logic.
- Returns:
A tuple containing:
str - The string with C-code with the pre-processor logic applied.
str - The string with comments with the pre-processor logic applied.
- Return type:
tuple
- mib_generator.parsing.par_methods.preproc_parse(stri)[source]
Parse C-preprocessor conditional syntax into logic blocks.
Looks for logical C-preprocessor directives (specifically
#ifdef,#ifndef, etc.), and marks the start/end indices of the corresponding “logic blocks” (i.e. sections beween#ifdefand#else). Then returns these block indexes in a list. Also performs some checks along the way.- Parameters:
stri (str) – The string to be analysed/parsed.
- Returns:
List of list of indexes denoting start/end positions of the logic blocks.
- Return type:
list
- mib_generator.parsing.par_methods.split_comment(stri)[source]
Split the given string into a section with C comments and a section without them.
Goes iteratively through the string and based on single/multi-line C-comment syntax, recognised blocks of comments and marks their start/end positions. It then constructs versions of the passed string with the comment/code blocks ommited.
- Parameters:
stri (str) – The string to be split into comments/code.
- Returns:
- A tuple consisting of:
str - The original string with comments omitted.
str - The original string with C-code omitted.
- Return type:
tuple
mib_generator.parsing.parser_main module
The main parsing module.
This module is a starting point for parsing of C-files and holds class which plays the role of their interpretation.
- class mib_generator.parsing.parser_main.file(stri, header)[source]
Bases:
objectClass representing the file being analysed and its internal structure in an easily Python-accessible format.
During creation this class goes through multiple steps of parsing/interpretation using methods in
mib_generator.parsing.par_header,mib_generator.parsing.par_cfileandparsing.par_methods. The steps are as follows:Get general information about the file (length, line indexes)
Separate text in comment and the code (while keeping the absolute positions in the file).
Process any C-preprocessor logic that’s in the code.
Parse the resulting code into Python representations of the corresponding C-objects.
Parse the comments into intepretable sections (written in json5) and interpret their content.
Create links between the found C-objects and interterpretable comments
- Parameters:
stri (str) – The content of the file to be parsed/analysed.
header (bool) – Parameter denoting whether file is a header or normal C file.
- text
Text of the file.
- Type:
str
- max_position
Length of the file.
- Type:
int
- lines
List of positions of line starts.
- Type:
list
- text_o
File text with only code (without comments).
- Type:
str
- text_c
File text with only comments (without code).
- Type:
str
- text_of
File (with code) after sorting out the pre-processor logic.
- Type:
str
- text_cf
File (with comments) after sorting out the pre-processor logic.
- Type:
str
- structures
List of Python representations of C-objects found in the file.
The Python representations are child classes of either
mib_generator.parsing.par_cfile.instance_ogormib_generator.parsing.par_header.structure- Type:
list
- comments
List of found interpretable comments which are represented using
mib_generator.parsing.par_methods.comment- Type:
list
- link
List of pairs of comments and the Python representation of C-objects they belong to.
- Type:
list
- linker()[source]
Link each comment to a corresponding C-object in the file
Goes one by one through comments and searches for their corresponding structure. For the closes found match, creates link from the comment to the structure and from the structure to the comment (by generating attributes for their respectives classes) and returns them in a list of pairs.
- Returns:
Pairs of comments and their corresponding structures.
- Return type:
list of pairs
- mib_generator.parsing.parser_main.main(name='/home/vachaj11/Documents/MIB/start/src/PUS_TmDefs.h')[source]
Create a parsed python representation of a file.
Opens file, depending on its ending chooses correct parser and lets it run.
- Parameters:
name (str) – Path to file.
- Returns:
File object
- Return type: