ujf.verimag.bip.codegen
Class C2BIPVisitor

java.lang.Object
  extended by CBasicVisitor
      extended by ujf.verimag.bip.codegen.CBipVisitor
          extended by ujf.verimag.bip.codegen.C2BIPVisitor

public class C2BIPVisitor
extends CBipVisitor

Visitor that generates BIP code as a ASG composed of BIP metamodel objects. It can use the result from the FindInteractionPoint visitor.

See Also:
FindInteractionPoint

Field Summary
protected  boolean activated
          if set to false, no BIP is created.
protected  PetriNet behav
           
protected  CGenerator cGeneratorForCGeneration
           
protected  java.util.Map<Statement,java.util.Set<InteractionPoint>> contains_interaction
          Contains all objects that contain interaction with one or many interface.
protected  AtomType ct
           
protected  StatementBlock current_block
           
protected  State current_state
           
protected  Transition current_transition
           
protected  java.lang.String entryFunction
          The function name considered as the root of the call graph (first transition in the automaton)
protected  boolean fold_code_block
          if set to true, the visitor tries to fold the C code when it does not contain any 'interaction'.
protected  StatementBlock header_block
           
protected  State init_state
          The initial state of the created automaton
protected  StatementBlock initialization_block
          This block contains the C code used at initialization
protected  PortDefinition internal_stepp
           
protected  java.util.logging.Logger logger
           
protected  Module model
          The BIP Model corresponding to the function 'entryFunction'.
protected  Variable return_data
           
protected  PortDefinition returnp
           
protected  int state_index
           
protected  boolean useContextForCGeneration
          When true, the generateCodeFromCodegen will always use the same visitor (preserving the context).
 
Fields inherited from class ujf.verimag.bip.codegen.CBipVisitor
interaction_method_names
 
Constructor Summary
C2BIPVisitor()
          Default constructor, to create a visitor that appends to model created by previous visitors.
C2BIPVisitor(boolean fold)
          Default constructor, to create a visitor that appends to model created by previous visitors.
C2BIPVisitor(java.lang.String entryFunctionName, java.lang.String topCompName, java.util.Map<java.lang.String,java.lang.String> dataAttributes, Module bipModule, boolean fold_code_block)
          Creates a new visitor.
C2BIPVisitor(java.lang.String entryFunctionName, java.lang.String topCompName, Module bipModule, boolean fold_code_block)
          Creates a new visitor.
C2BIPVisitor(java.lang.String entryFunctionName, java.lang.String topCompName, Module bipModule, java.util.Map<Statement,java.util.Set<InteractionPoint>> contains_interaction, boolean fold_code_block)
          Creates a new visitor.
C2BIPVisitor(java.lang.String entryFunctionName, java.lang.String topCompName, java.lang.String packageName)
          Creates a new visitor.
C2BIPVisitor(java.lang.String entryFunctionName, java.lang.String topCompName, java.lang.String packageName, java.util.Map<Statement,java.util.Set<InteractionPoint>> contains_interaction)
          Creates a new visitor and enables the code folding if possible.
C2BIPVisitor(java.lang.String entryFunctionName, java.lang.String topCompName, java.lang.String packageName, java.util.Map<Statement,java.util.Set<InteractionPoint>> contains_interaction, boolean fold_code_block)
          Creates a new visitor.
 
Method Summary
protected  void addActionToCurrentTransition(Action action)
          Adds an action to the current transition
protected  State createNextState(boolean update_current_state)
           
protected  State createNextState(java.lang.String prefix)
           
protected  void doWhileLoop( condition, CBlock cblock, ForIter foriter)
          Utility function to generate BIP from for(;;){} and while(){} loops.
protected  java.lang.String generateCodeFromCodegen(Statement s)
          Helper method to create a String from a Codegen Statement object
 Module getModel()
           
static
<SC extends CStatement>
java.lang.String
preprocessesFile(java.lang.String srcFileName, java.util.List<java.lang.String> preProcCommand, java.lang.String destFilePrefix, boolean debugCommand, java.io.File destFile, java.lang.String context)
           
protected  void purgeCurrentBlockToCurrentTransition(boolean close_transition)
          Puts all the statements gathered after last purge (or beginning) to the actions on the current transition.
protected  void purgeCurrentBlockToCurrentTransition(boolean close_transition, Transition[] extra_transitions)
          Puts all the statements gathered after last purge (or beginning) to the actions on the current transition.
 void setContainsInteraction(java.util.Map<Statement,java.util.Set<InteractionPoint>> contains_interaction)
           
protected  BinaryExpression translateBinaryCodegenToBIPBinaryExpression(CBinaryExpression cbe)
          Translate a simple CBinaryExpression codegen object to a BinaryExpression in the BIP metamodel
 void visit( b)
           
<RetTypeClass extends CType>
void
visit( s)
           
<TypeClass extends CType>
void
visit( d)
           
<TypeClass extends CType>
void
visit( e)
           
<TypeClass extends CType>
void
visit( d)
           
 void visit(For c)
           
 void visit(FunctionCall s)
           
 void visit(IfElse c)
           
 void visit(Return c)
           
 void visit(StatementBlock b)
           
 void visit(WhileDo c)
           
 
Methods inherited from class ujf.verimag.bip.codegen.CBipVisitor
addInteractionMethod, addInteractionMethod, clearInteractionMethods, getMatchForFunctionCall, matchAnyFunctionCall
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected java.util.logging.Logger logger

useContextForCGeneration

protected boolean useContextForCGeneration
When true, the generateCodeFromCodegen will always use the same visitor (preserving the context). If false, a new visitor is created for every calls.


cGeneratorForCGeneration

protected CGenerator cGeneratorForCGeneration

entryFunction

protected java.lang.String entryFunction
The function name considered as the root of the call graph (first transition in the automaton)


activated

protected boolean activated
if set to false, no BIP is created. It should be set to true when the visitor enters the function definition corresponding to the 'entryFunction' function.


model

protected Module model
The BIP Model corresponding to the function 'entryFunction'.


init_state

protected State init_state
The initial state of the created automaton


behav

protected PetriNet behav

ct

protected AtomType ct

current_state

protected State current_state

current_transition

protected Transition current_transition

current_block

protected StatementBlock current_block

header_block

protected final StatementBlock header_block

internal_stepp

protected PortDefinition internal_stepp

returnp

protected PortDefinition returnp

return_data

protected Variable return_data

state_index

protected int state_index

initialization_block

protected StatementBlock initialization_block
This block contains the C code used at initialization


contains_interaction

protected java.util.Map<Statement,java.util.Set<InteractionPoint>> contains_interaction
Contains all objects that contain interaction with one or many interface. Comes from the FindInteractionPoint visitor.


fold_code_block

protected final boolean fold_code_block
if set to true, the visitor tries to fold the C code when it does not contain any 'interaction'. The 'contains_interaction' attribute must be non-null.

Constructor Detail

C2BIPVisitor

public C2BIPVisitor(java.lang.String entryFunctionName,
                    java.lang.String topCompName,
                    Module bipModule,
                    java.util.Map<Statement,java.util.Set<InteractionPoint>> contains_interaction,
                    boolean fold_code_block)
Creates a new visitor.

Parameters:
entryFunctionName - the C function name to look for during the visit
topCompName - the name of the newly created component (corresponding to the C function)
bipModule - existing BIP package
contains_interaction - a map associating Statement to set of interactions.
fold_code_block - if true, the visitor tries to reduce automaton size.

C2BIPVisitor

public C2BIPVisitor(java.lang.String entryFunctionName,
                    java.lang.String topCompName,
                    Module bipModule,
                    boolean fold_code_block)
Creates a new visitor.

Parameters:
entryFunctionName - the C function name to look for during the visit
topCompName - the name of the newly created component (corresponding to the C function)
bipModule - existing BIP package
fold_code_block - if true, the visitor tries to reduce automaton size.

C2BIPVisitor

public C2BIPVisitor(java.lang.String entryFunctionName,
                    java.lang.String topCompName,
                    java.util.Map<java.lang.String,java.lang.String> dataAttributes,
                    Module bipModule,
                    boolean fold_code_block)
Creates a new visitor.

Parameters:
entryFunctionName - the C function name to look for during the visit
topCompName - the name of the newly created component (corresponding to the C function)
dataAttributes - a map of extra data attributes to include in the new Atom
bipModule - existing BIP package
fold_code_block - if true, the visitor tries to reduce automaton size.

C2BIPVisitor

public C2BIPVisitor(java.lang.String entryFunctionName,
                    java.lang.String topCompName,
                    java.lang.String packageName,
                    java.util.Map<Statement,java.util.Set<InteractionPoint>> contains_interaction,
                    boolean fold_code_block)
Creates a new visitor.

Parameters:
entryFunctionName - the C function name to look for during the visit
topCompName - the name of the newly created component (corresponding to the C function)
packageName - the name for the newly created package
contains_interaction - a map associating Statement to set of interactions.
fold_code_block - if true, the visitor tries to reduce automaton size.

C2BIPVisitor

public C2BIPVisitor(java.lang.String entryFunctionName,
                    java.lang.String topCompName,
                    java.lang.String packageName)
Creates a new visitor.

Parameters:
entryFunctionName - the C function name to look for during the visit
topCompName - the name of the newly created component (corresponding to the C function)
packageName - the name for the newly created package

C2BIPVisitor

public C2BIPVisitor(java.lang.String entryFunctionName,
                    java.lang.String topCompName,
                    java.lang.String packageName,
                    java.util.Map<Statement,java.util.Set<InteractionPoint>> contains_interaction)
Creates a new visitor and enables the code folding if possible.

Parameters:
entryFunctionName - the C function name to look for during the visit
topCompName - the name of the newly created component (corresponding to the C function)
packageName - the name for the newly created package
contains_interaction - a map associating Statement to set of interactions.

C2BIPVisitor

public C2BIPVisitor()
Default constructor, to create a visitor that appends to model created by previous visitors.


C2BIPVisitor

public C2BIPVisitor(boolean fold)
Default constructor, to create a visitor that appends to model created by previous visitors.

Parameters:
fold - if true, the visitor tries to reduce automaton size.
Method Detail

setContainsInteraction

public void setContainsInteraction(java.util.Map<Statement,java.util.Set<InteractionPoint>> contains_interaction)

preprocessesFile

public static <SC extends CStatement> java.lang.String preprocessesFile(java.lang.String srcFileName,
                                                                        java.util.List<java.lang.String> preProcCommand,
                                                                        java.lang.String destFilePrefix,
                                                                        boolean debugCommand,
                                                                        java.io.File destFile,
                                                                        java.lang.String context)
                                         throws java.lang.Exception
Throws:
java.lang.Exception

generateCodeFromCodegen

protected java.lang.String generateCodeFromCodegen(Statement s)
Helper method to create a String from a Codegen Statement object

Parameters:
s - a C statement
Returns:
a String representation of the statement

getModel

public Module getModel()
Returns:
the model corresponding to the function 'entryFunction'

purgeCurrentBlockToCurrentTransition

protected void purgeCurrentBlockToCurrentTransition(boolean close_transition)
Puts all the statements gathered after last purge (or beginning) to the actions on the current transition. Empties the statement block.

Parameters:
close_transition - if true, also closes the current transition with a new state

addActionToCurrentTransition

protected void addActionToCurrentTransition(Action action)
Adds an action to the current transition

Parameters:
action - the action to add

purgeCurrentBlockToCurrentTransition

protected void purgeCurrentBlockToCurrentTransition(boolean close_transition,
                                                    Transition[] extra_transitions)
Puts all the statements gathered after last purge (or beginning) to the actions on the current transition. If extra_transitions not empty, the transitions are closed to the newly created state. Empties the statement block.

Parameters:
close_transition - if true, also closes the current transition with a new state

createNextState

protected State createNextState(boolean update_current_state)

createNextState

protected State createNextState(java.lang.String prefix)

translateBinaryCodegenToBIPBinaryExpression

protected BinaryExpression translateBinaryCodegenToBIPBinaryExpression(CBinaryExpression cbe)
Translate a simple CBinaryExpression codegen object to a BinaryExpression in the BIP metamodel

Parameters:
cbe - the binary expression in codegen
Returns:
the corresponding binary expression in BIP metamodel

doWhileLoop

protected void doWhileLoop( condition,
                           CBlock cblock,
                           ForIter foriter)
Utility function to generate BIP from for(;;){} and while(){} loops. for(x;y;z){toto;} <=> x; while(y){toto; z;}

Parameters:
condition - the condition for looping before each iteration
cblock - the code block to execute during each iteration
foriter - the code to be executed between all iterations

visit

public void visit(StatementBlock b)

visit

public void visit(Return c)

visit

public <TypeClass extends CType> void visit( d)

visit

public void visit(WhileDo c)

visit

public void visit(For c)

visit

public void visit(IfElse c)

visit

public <RetTypeClass extends CType> void visit( s)

visit

public void visit(FunctionCall s)

visit

public <TypeClass extends CType> void visit( e)

visit

public <TypeClass extends CType> void visit( d)

visit

public void visit( b)