Topic
  • 5 replies
  • Latest Post - ‏2013-03-01T15:23:40Z by markevans
SystemAdmin
SystemAdmin
6195 Posts

Pinned topic Finding functions in egl file

‏2013-02-25T08:29:20Z |
Hi, I've a java program that finds program, function, record names in EGL file. But the problem is, I couldn't get function names, if the function is defined in block of "program". But I can get the function name if it is defined, out of program block. Any help would be greatly appreciated.
Updated on 2013-03-01T15:23:40Z at 2013-03-01T15:23:40Z by markevans
  • dan_darnell
    dan_darnell
    973 Posts

    Re: Finding functions in egl file

    ‏2013-02-25T21:39:25Z  
    What sort of help are you looking for, exactly? Without knowing how you went about the task of creating your Java program and without any code to reference, I'm not sure how anyone can help you.

    --Dan
  • SystemAdmin
    SystemAdmin
    6195 Posts

    Re: Finding functions in egl file

    ‏2013-02-27T13:50:39Z  
    What sort of help are you looking for, exactly? Without knowing how you went about the task of creating your Java program and without any code to reference, I'm not sure how anyone can help you.

    --Dan
    This function takes the EGL file. Then sends it to "analyseStmts" function to recognize the statements of function,record etc names in the EGL file.

    /***************************************************************************************************/
    public static eglFile analyseEGLFile(File sourceFile) throws FileNotFoundException
    {
    String fileNameIdentifier = sourceFile.getName();
    com.ibm.etools.edt.core.ast.File localFile = getEGLFile(sourceFile);

    PackageDeclaration packageDeclaration = localFile.getPackageDeclaration();
    String packageDeclarationIdentifier = packageDeclaration.getName().toString();

    eglFile eglFile = new eglFile(fileNameIdentifier,packageDeclarationIdentifier);
    eglFile.setSyntaxErrorsCount(checkSyntax(sourceFile, localFile));

    eglFile.setPackageDeclaration(packageDeclarationIdentifier);

    for(Object importDeclarationObj:localFile.getImportDeclarations())
    {
    ImportDeclaration importDeclaration = (ImportDeclaration)importDeclarationObj;
    String importDeclarationIdentifier = importDeclaration.getName().toString();

    eglFile.addImportedPackage(importDeclarationIdentifier);
    }

    for(Object partObj:localFile.getParts())
    {
    Part part = (Part)partObj;

    String nameIdentifier = getPartName(part);
    int typeIdentifierNo = part.getPartType();
    String typeIdentifier = part.getPartTypeName();

    eglPart eglPart = new eglPart(nameIdentifier, typeIdentifierNo, typeIdentifier);

    if(part.isPrivate())
    {
    eglPart.isPrivate(true);
    }

    if(typeIdentifier.equals("program"))
    {
    Program program = (Program)part;
    List programParameters = program.getParameters();
    for(Object programParameterObj:programParameters)
    {
    ProgramParameter programParameter = (ProgramParameter)programParameterObj;
    if(!programParameter.getType().isPrimitiveType())
    {
    String parameterIdentifier = programParameter.getType().getCanonicalName();

    partRelation partRelation = new partRelation(parameterIdentifier);
    partRelation.setRelationType(partRelation.programParameter);
    partRelation.setParent(eglPart);
    eglPart.addPartRelation(partRelation);
    }

    }
    }
    else if(typeIdentifier.equals("function"))
    {
    TopLevelFunction topLevelFunction = (TopLevelFunction)part;

    List functionParameters = topLevelFunction.getFunctionParameters();
    for(Object functionParameterObj:functionParameters)
    {
    FunctionParameter functionParameter = (FunctionParameter)functionParameterObj;
    if(!functionParameter.getType().isPrimitiveType())
    {
    String parameterIdentifier = functionParameter.getType().getCanonicalName();

    partRelation partRelation = new partRelation(parameterIdentifier);
    partRelation.setRelationType(partRelation.functionParameter);
    partRelation.setParent(eglPart);
    eglPart.addPartRelation(partRelation);
    }

    }
    }
    //here, the part contents goes to "analyseStmts" function
    eglPart = analyseStmts(part.getContents(), eglPart);
    eglPart.setParent(eglFile);
    System.out.println("Eglpart name: "+ eglPart.getPartName());
    eglFile.addEglPart(eglPart);
    }

    return eglFile;
    }

    /***************************************************************************************************/

    private static eglPart analyseStmts(List statements, eglPart eglPart)
    {
    for(Object statement:statements)
    {
    if(statement instanceof IfStatement)
    {
    eglPart = analyseStmts(getIfStatementSubStmts(statement), eglPart);
    }
    else if(statement instanceof ForStatement)
    {
    eglPart = analyseStmts(getForStatementSubStmts(statement), eglPart);
    }
    else if(statement instanceof NestedFunction)
    {
    eglPart = analyseStmts(getNestedFunctionStmts(statement), eglPart);
    }
    else if(statement instanceof FunctionInvocationStatement)
    {
    String targetNameIdentifier = getTargetFunctionName(statement);

    partRelation partRelation = new partRelation(targetNameIdentifier);
    partRelation.setRelationType(partRelation.functionCall);
    partRelation.setParent(eglPart);
    eglPart.addPartRelation(partRelation);
    }
    else if(statement instanceof ClassDataDeclaration)
    {
    String typeNameIdentifier = getClassDataDeclarationName(statement);
    if(!isClassDataDeclarationPrimitive(statement))
    {
    partRelation partRelation = new partRelation(typeNameIdentifier);
    partRelation.setRelationType(partRelation.dataDeclaration);
    partRelation.setParent(eglPart);
    eglPart.addPartRelation(partRelation);
    }
    }

    }

    return eglPart;
    }

    /***************************************************************************************************/

    While analyzing the egl file parts, if the function is defined in "program" block, the function recognized as nestedfunction, but if the function is defined outside of "program" block, it recognized the function as topLevelFunction.

    What my question is this, how can I take this nestedfunction and recognize it as topLevelFunction ? I can draw general structure of EGL file if it is needed.
  • markevans
    markevans
    2806 Posts

    Re: Finding functions in egl file

    ‏2013-02-27T14:26:41Z  
    This function takes the EGL file. Then sends it to "analyseStmts" function to recognize the statements of function,record etc names in the EGL file.

    /***************************************************************************************************/
    public static eglFile analyseEGLFile(File sourceFile) throws FileNotFoundException
    {
    String fileNameIdentifier = sourceFile.getName();
    com.ibm.etools.edt.core.ast.File localFile = getEGLFile(sourceFile);

    PackageDeclaration packageDeclaration = localFile.getPackageDeclaration();
    String packageDeclarationIdentifier = packageDeclaration.getName().toString();

    eglFile eglFile = new eglFile(fileNameIdentifier,packageDeclarationIdentifier);
    eglFile.setSyntaxErrorsCount(checkSyntax(sourceFile, localFile));

    eglFile.setPackageDeclaration(packageDeclarationIdentifier);

    for(Object importDeclarationObj:localFile.getImportDeclarations())
    {
    ImportDeclaration importDeclaration = (ImportDeclaration)importDeclarationObj;
    String importDeclarationIdentifier = importDeclaration.getName().toString();

    eglFile.addImportedPackage(importDeclarationIdentifier);
    }

    for(Object partObj:localFile.getParts())
    {
    Part part = (Part)partObj;

    String nameIdentifier = getPartName(part);
    int typeIdentifierNo = part.getPartType();
    String typeIdentifier = part.getPartTypeName();

    eglPart eglPart = new eglPart(nameIdentifier, typeIdentifierNo, typeIdentifier);

    if(part.isPrivate())
    {
    eglPart.isPrivate(true);
    }

    if(typeIdentifier.equals("program"))
    {
    Program program = (Program)part;
    List programParameters = program.getParameters();
    for(Object programParameterObj:programParameters)
    {
    ProgramParameter programParameter = (ProgramParameter)programParameterObj;
    if(!programParameter.getType().isPrimitiveType())
    {
    String parameterIdentifier = programParameter.getType().getCanonicalName();

    partRelation partRelation = new partRelation(parameterIdentifier);
    partRelation.setRelationType(partRelation.programParameter);
    partRelation.setParent(eglPart);
    eglPart.addPartRelation(partRelation);
    }

    }
    }
    else if(typeIdentifier.equals("function"))
    {
    TopLevelFunction topLevelFunction = (TopLevelFunction)part;

    List functionParameters = topLevelFunction.getFunctionParameters();
    for(Object functionParameterObj:functionParameters)
    {
    FunctionParameter functionParameter = (FunctionParameter)functionParameterObj;
    if(!functionParameter.getType().isPrimitiveType())
    {
    String parameterIdentifier = functionParameter.getType().getCanonicalName();

    partRelation partRelation = new partRelation(parameterIdentifier);
    partRelation.setRelationType(partRelation.functionParameter);
    partRelation.setParent(eglPart);
    eglPart.addPartRelation(partRelation);
    }

    }
    }
    //here, the part contents goes to "analyseStmts" function
    eglPart = analyseStmts(part.getContents(), eglPart);
    eglPart.setParent(eglFile);
    System.out.println("Eglpart name: "+ eglPart.getPartName());
    eglFile.addEglPart(eglPart);
    }

    return eglFile;
    }

    /***************************************************************************************************/

    private static eglPart analyseStmts(List statements, eglPart eglPart)
    {
    for(Object statement:statements)
    {
    if(statement instanceof IfStatement)
    {
    eglPart = analyseStmts(getIfStatementSubStmts(statement), eglPart);
    }
    else if(statement instanceof ForStatement)
    {
    eglPart = analyseStmts(getForStatementSubStmts(statement), eglPart);
    }
    else if(statement instanceof NestedFunction)
    {
    eglPart = analyseStmts(getNestedFunctionStmts(statement), eglPart);
    }
    else if(statement instanceof FunctionInvocationStatement)
    {
    String targetNameIdentifier = getTargetFunctionName(statement);

    partRelation partRelation = new partRelation(targetNameIdentifier);
    partRelation.setRelationType(partRelation.functionCall);
    partRelation.setParent(eglPart);
    eglPart.addPartRelation(partRelation);
    }
    else if(statement instanceof ClassDataDeclaration)
    {
    String typeNameIdentifier = getClassDataDeclarationName(statement);
    if(!isClassDataDeclarationPrimitive(statement))
    {
    partRelation partRelation = new partRelation(typeNameIdentifier);
    partRelation.setRelationType(partRelation.dataDeclaration);
    partRelation.setParent(eglPart);
    eglPart.addPartRelation(partRelation);
    }
    }

    }

    return eglPart;
    }

    /***************************************************************************************************/

    While analyzing the egl file parts, if the function is defined in "program" block, the function recognized as nestedfunction, but if the function is defined outside of "program" block, it recognized the function as topLevelFunction.

    What my question is this, how can I take this nestedfunction and recognize it as topLevelFunction ? I can draw general structure of EGL file if it is needed.
    Hi,

    The only way to make a nested function into a top-level function is to move it outside the scope of the program (i.e. outside the "end" for the program. That is how the language is defined.

    What are you trying to accomplish by parsing the egl files? What is your end goal?
  • SystemAdmin
    SystemAdmin
    6195 Posts

    Re: Finding functions in egl file

    ‏2013-02-27T15:24:54Z  
    • markevans
    • ‏2013-02-27T14:26:41Z
    Hi,

    The only way to make a nested function into a top-level function is to move it outside the scope of the program (i.e. outside the "end" for the program. That is how the language is defined.

    What are you trying to accomplish by parsing the egl files? What is your end goal?
    Hi Mark,

    I know it is possible by moving function codes outside of program block as you said. but I can't do it, we have lots of sources. so, I need to handle it somehow.

    My aim is analyze egl files and get relations between them and save it to database and use it for which function affected by which function and used in which file etc.. Only this part left to do.

    At the end of analyze (after scan all files), when I am trying to get part names, I only see partNames (I'm talking about functions, records are fine.) which are defined outside of program block. But I can see all partnames in partrelation table (doesn't matter if it is inside or outside of program block). So I have nestedFunction(s) in partrelations but not as a part itself. Any idea ?
  • markevans
    markevans
    2806 Posts

    Re: Finding functions in egl file

    ‏2013-03-01T15:23:40Z  
    Hi Mark,

    I know it is possible by moving function codes outside of program block as you said. but I can't do it, we have lots of sources. so, I need to handle it somehow.

    My aim is analyze egl files and get relations between them and save it to database and use it for which function affected by which function and used in which file etc.. Only this part left to do.

    At the end of analyze (after scan all files), when I am trying to get part names, I only see partNames (I'm talking about functions, records are fine.) which are defined outside of program block. But I can see all partnames in partrelation table (doesn't matter if it is inside or outside of program block). So I have nestedFunction(s) in partrelations but not as a part itself. Any idea ?
    Hi,
    I am not sure how you could get that info based on the tool you have written.

    You may want to look at using the APIs that are available within the tool to get similar information. Instead of just parsing a file, these APIs basically allow you to get info about a generatable part ..for example... "a program and what parts are associated with it". The APIs then allow you to extract the source for any of the associated parts from the file (whether nested or top-level).

    Attached is a zip file with a short description of the APIs, the java classes you can use, and an example of how to invoke them.

    You can also get some information in the EGL helps at:

    http://publib.boulder.ibm.com/infocenter/rbdhelp/v8r0m0/topic/com.ibm.egl.pg.doc/topics/pegl_rep_part_reference_stats_tsk.html