Package builder

Class FunctionsGenerator

java.lang.Object
builder.FunctionsGenerator

public class FunctionsGenerator extends Object
Class used to generate the functions from the MEOS library. Run with directly with java through the main class
Since:
27/06/2023
Author:
Killian Monnier and Nidhal Mareghni
  • Field Details

    • C_functionsPath

      private final Path C_functionsPath
      Path of the file generated by FunctionsExtractor. Contains a list of functions signature.
    • C_typesPath

      private final Path C_typesPath
      Path of the file generated by FunctionsExtractor. Contains a list of types definition.
    • functionsFilePath

      private final Path functionsFilePath
      Path of the file generated by this class.
    • equivalentTypes

      private final HashMap<String,String> equivalentTypes
      Types dictionary. Contains the C types and there equivalent in Java
    • conversionTypes

      private final HashMap<String,String> conversionTypes
    • conversionTypedefs

      private final HashMap<String,String> conversionTypedefs
    • unsupportedEquivalentTypes

      private final ArrayList<String> unsupportedEquivalentTypes
    • unsupportedConversionTypedefs

      private final ArrayList<String> unsupportedConversionTypedefs
    • unsupportedConversionTypes

      private final ArrayList<String> unsupportedConversionTypes
  • Constructor Details

  • Method Details

    • getFunctionTypes

      private static ArrayList<String> getFunctionTypes(String signature)
      Gives the types of the function's parameters and return from a line corresponding to the format of a function.
      Parameters:
      signature - function signature
      Returns:
      types list
    • main

      public static void main(String[] args) throws URISyntaxException
      Launch process of extraction.
      Parameters:
      args - arguments
      Throws:
      URISyntaxException - thrown when resources not found
    • performTypeConversion

      private static String performTypeConversion(String line)
      Processes the rows to generate the functions.
      Parameters:
      line - the line corresponding to a function
      Returns:
      the processed line
    • buildEquivalentTypes

      private static HashMap<String,String> buildEquivalentTypes()
      Builds the type modification array.
       Key: old type in C or modified
       Value: new type in Java
       
      Returns:
      type dictionary
    • buildConversionTypes

      private static HashMap<String,String> buildConversionTypes()
      Build the dictionary of conversion types.
       Key: old type in C or modified
       Value: new type in Java
       
      Returns:
      types dictionary
    • getUnsupportedTypes

      private static List<String> getUnsupportedTypes(String signature, Map<String,String> types)
      Check unsupported types.
      Parameters:
      signature - function signature
    • buildConversionTypedefs

      private HashMap<String,String> buildConversionTypedefs(String filePath)
      Build the dictionary of typedef conversion.
       Key: old type in C or modified
       Value: new type in Java
       
      Parameters:
      filePath - file path of C typedefs
      Returns:
      types dictionary
    • generateConversionProcess

      private List<Pair<Pair<String,String>,List<String>>> generateConversionProcess(String signature)
      Produce the process of adding code to handle conversion of certain types for a function.
      Parameters:
      signature - function signature
      Returns:
      list of Pair defined as follows :
      • Key : Pair defined as follows :
        • Key : old type name
        • Value : new type name
      • Value : list of lines for the conversion process
    • countOccurrences

      public static int countOccurrences(String text, String pattern)
      utility function to count the number if occurences of pointer, pointer[] and pointer[][]
    • generateReturnProcess

      private List<String> generateReturnProcess(String signature, List<Pair<String,String>> typesNamesList)
      Produce the returning process for a function
      Parameters:
      signature - function signature
      typesNamesList - list of types names to change it in the calling of the equivalent interface function
      Returns:
      the returning process
    • generateClass

      private StringBuilder generateClass(StringBuilder functionsBuilder, StringBuilder interfaceBuilder)
      Used to generate the class of functions.
      Parameters:
      functionsBuilder - builder of functions
      interfaceBuilder - interface builder
      Returns:
      the class builder
    • generateInterface

      private StringBuilder generateInterface(StringBuilder functionsBuilder)
      Generation of the interface.
      Parameters:
      functionsBuilder - builder of functions
      Returns:
      the interface builder
    • generateFunctions

      private StringBuilder generateFunctions(String filePath, boolean performTypesConversion)
      Generation of functions with their conversion types, typedef conversion types and equivalent types.
      Parameters:
      filePath - file path of C functions
      performTypesConversion - true if it needs to perform a types conversion using conversionTypes
      Returns:
      the function builder