TreeGen

public final class TreeGen

Tree regeneration from internal representation (CallGraph, Unit).

Methods

addHeader

public static void addHeader(Tree tree, int language, String versionString)

Place the comment “Generated by Tapenade” on top of tree.

addSymbolDeclStructs

public static TapList<DeclStruct> addSymbolDeclStructs(SymbolDecl symbolDecl, TapList<DeclStruct> declStructs, SymbolTable publicSymbolTable, Block insertInBlock, Tree generatedTree)

addUseDiffSizesAndUserHelp

public static void addUseDiffSizesAndUserHelp(Tree unitTree, TapList<Tree> unitUserHelpStrings, int language)

Inserts into unitTree the “USE” or “include” of the DIFFSIZE utility file, annotated with the hints that tell the user what to add into this file.

Parameters
  • unitTree – the op_blockStatement Tree that contains the code that must receive this “USE” or “include”.

cleanBeforeGenerate

public static void cleanBeforeGenerate(CallGraph callGraph)

Do some necessary cleanup in callGraph before regenerating a Tree for it. In particular, insert the new Blocks for the new declarations if necessary, change remaining “if”s that are indeed vectorial into “where”s, replace back Fortran style pointer notation.

generate

public static Tree generate(Unit unit, boolean forwardDeclaration, boolean isInterface, boolean skipSubUnits, TapList<TapTriplet<Tree, Tree, Integer>> toFutureIncludes, TapList<Tree> fileUserHelpStrings)

Regenerates the Tree corresponding to the given Unit.

Parameters
  • skipSubUnits – (used only for file Units) when true, sub-Unit definitions are not generated.

  • toFutureIncludes – a (hatted) list, initially empty, collecting the future contents of the future re-generated include files.

  • fileUserHelpStrings – a (hatted) list of Tree, initially empty, in which generate() will collect all variables that the user is required to define in DIFFSIZES.?. The calling function is then supposed to use this list to effectively build and place the “USE” or “include” of DIFFSIZES.? If on the other hand this argument is passed null, then this generate() takes care of building and placing this “USE” or “include”.

Returns

null or the regenerated Tree, always with head operator op_blockStatement.

generateGlobalDeclarations

public static boolean generateGlobalDeclarations(CallGraph callGraph, TapList<TapTriplet<Tree, Tree, Integer>> toFutureIncludes, TapList<Tree> fileUserHelpStrings, Tree fileTree, int lang, boolean addTranslationUnitDeclarations)

Regenerates into fileTree all global declarations found in callGraph. //[llh 20Jun2018 maybe no more?] This includes the C-style forward declarations of procedures.

Returns

true if some global declarations were effectively added (not counting include’s).

generateInclude

public static TapList<TapTriplet<Tree, Tree, Integer>> generateInclude(TapList<TapTriplet<Tree, Tree, Integer>> toFutureIncludes, String versionString)

Reorders the collected information about instructions that must be regenerated into include files.

Parameters
  • toFutureIncludes – the given info about instructions that go in include files, that has been collected during TreeGen.generate() and similar

Returns

the list of the contents of all include files that must be generated. This is a list, for each future generated include file, of triplets (Tree “includeFileCommand”, Tree “includeFileContents”, int “includeLanguage”).

generateMissingDeclarations

protected static TapList<TapPair<Tree, SymbolDecl>> generateMissingDeclarations(Unit forUnit, SymbolTable symbolTable, boolean globalDecls, boolean inPublicSymbolTable, Block insertInBlock, boolean traceThisUnit)

Regenerates a declaration for each SymbolDecl in the given “symbolTable” of “forUnit” that still has no associated declaration instruction in “forUnit”.

Returns

the list of regenerated missing declarations, each one paired with the SymbolDecl it declares.

generateReverseListOfTree

protected static TapList<Tree> generateReverseListOfTree(Block block, TapList<TapTriplet<Tree, Tree, Integer>> toFutureIncludes, TapList<Tree> fileUserHelpStrings, boolean addOnlyPublicDeclForInterface)

insertInstructionWatchingIncludes

public static TapList<Instruction> insertInstructionWatchingIncludes(Instruction instruction, TapList<Instruction> tlNewInsts, boolean onSourceUnit, TapList<TapPair<Instruction, TapList<Instruction>>> toIncludesBeingBuilt, TapList<TapTriplet<Tree, Tree, Integer>> toFutureIncludes)

Inserts the given instruction at the tail of the produced code. When the given instruction is not marked as belonging to an include file, instruction is added at the tail of the given tlNewInsts, and then method returns the new tail of tlNewInsts. Otherwise, when given instruction is inside an include file, adds it inside “toFutureIncludes”, as the tail of the contents of the corresponding include file. Takes care of adding the intermediate include statements when instruction is in a chain of nested includes. When the same include file is encountered twice, keeps only one copy of the include file contents, and sends a message when the two copies differ.

Parameters
  • instruction – the given instruction to be added. Pass null to force flush of pending #include commands.

  • toIncludesBeingBuilt – the hatted list of the include files currently being built, (i.e. those enclosing the given instruction), deepest include first, each one with its present contents as “being built”.

Returns

the new tail of the instructions of the future Block.