// 19/May/2003 - 22:13 // 19/May/2003 - 21:42 // 19/May/2003 - 03:54a // 18/May/2003 - 23:33 // 18/May/2003 - 15:00 // 18/May/2003 - 1:24a // 17/May/2003 - 3:14a // 16/May/2003 - 20:43 // 15/May/2003 - 3:20a // 14/May/2003 - 21:10 // 13/May/2003 - 14:35 // 13/May/2003 - 1:32a // 01/Feb/2003 - 0:06a // 16/Feb/2003 - 9:14a // 18/Feb/2003 - 15:48 // VERIFY AND tree/IdpNode, javac/IdpConstants UPDATE /** * * AST class definition * * Produce a Database view of the Javac Abstract Syntax Tree * */ /////////////////////////////////////////////////////////////////////////////////////////////////// /// Current package/package /////////////////////////////////////////////////////////////////////////////////////////////////// //package Concept.Table; package sun.tools.tree; /////////////////////////////////////////////////////////////////////////////////////////////////// /// Standard Java stuff /////////////////////////////////////////////////////////////////////////////////////////////////// //import java.lang.Integer; import java.lang.String; import java.lang.NumberFormatException; import java.lang.Exception; import java.lang.Error; /////////////////////////////////////////////////////////////////////////////////////////////////// /// Standard Java utilities /////////////////////////////////////////////////////////////////////////////////////////////////// import java.util.Vector; import java.util.Iterator; /////////////////////////////////////////////////////////////////////////////////////////////////// /// Standard database related classes /////////////////////////////////////////////////////////////////////////////////////////////////// import java.sql.ResultSet; import java.sql.SQLException; import Concept.DB.Database; import Concept.DB.Cursor; import Concept.DB.Results; /////////////////////////////////////////////////////////////////////////////////////////////////// /// Object-oriented database table object handle - Generated by Perl script /////////////////////////////////////////////////////////////////////////////////////////////////// import Concept.Table.AST_Block; import Concept.Table.AST_Breakpoint; import Concept.Table.AST_Class; import Concept.Table.AST_Class_Inherit_Node; import Concept.Table.AST_Class_Used; import Concept.Table.AST_Data_Dependancy; import Concept.Table.AST_Expression; import Concept.Table.AST_File; import Concept.Table.AST_Function; import Concept.Table.AST_Function_Call; import Concept.Table.AST_Function_Call_Arguments; import Concept.Table.AST_Import; import Concept.Table.AST_Node; import Concept.Table.AST_Package; import Concept.Table.AST_Project; import Concept.Table.AST_Statement; import Concept.Table.AST_Type; import Concept.Table.AST_Variable; /////////////////////////////////////////////////////////////////////////////////////////////////// import sun.tools.javac.IdpConstants; import sun.tools.java.*; import sun.tools.javac.*; import sun.tools.tree.*; import java.util.*; import java.lang.reflect.Modifier; import java.io.*; import Concept.DB.Database; import Concept.Table.ParserDatabaseInterface; import java.sql.PreparedStatement; import Concept.DB.*; import Concept.Table.*; import java.sql.Connection; /////////////////////////////////////////////////////////////////////////////////////////////////// public class AST23 { public AST23() { } public static void main( String args[] ) { System.out.println( "-- Main --" ); } } /////////////////////////////////////////////////////////////////////////////////////////////////// class SuperKey { public int project_key; public int file_key; public int block_key; public int stat_key; public int expr_key; public int parent_package_node_key; public int parent_class_node_key; public int parent_function_node_key; public int parent_block_node_key; public int parent_node_key; public int node_key; public int value; public int depth; public SuperKey prev; public SuperKey() { this.project_key = AST.NULL; this.file_key = AST.NULL; this.block_key = AST.NULL; this.stat_key = AST.NULL; this.expr_key = AST.NULL; this.parent_package_node_key = AST.NULL; this.parent_class_node_key = AST.NULL; this.parent_function_node_key = AST.NULL; this.parent_block_node_key = AST.NULL; this.parent_node_key = AST.NULL; this.node_key = AST.NULL; this.value = AST.NULL; this.depth = 0; this.prev = null; } public SuperKey( int project_key, int file_key ) { this.project_key = project_key; this.file_key = file_key; this.block_key = AST.NULL; this.stat_key = AST.NULL; this.expr_key = AST.NULL; this.parent_package_node_key = AST.NULL; this.parent_class_node_key = AST.NULL; this.parent_function_node_key = AST.NULL; this.parent_block_node_key = AST.NULL; this.parent_node_key = AST.NULL; this.node_key = AST.NULL; this.value = AST.NULL; this.depth = 0; this.prev = null; } public SuperKey( int project_key, int file_key, int block_key, int stat_key, int expr_key, int parent_package_node_key, int parent_class_node_key, int parent_function_node_key, int parent_block_node_key, int parent_node_key, int node_key, int value ) { this.project_key = project_key; this.file_key = file_key; this.block_key = block_key; this.stat_key = stat_key; this.expr_key = expr_key; this.parent_package_node_key = parent_package_node_key; this.parent_class_node_key = parent_class_node_key; this.parent_function_node_key = parent_function_node_key; this.parent_block_node_key = parent_block_node_key; this.parent_node_key = parent_node_key; this.node_key = node_key; this.value = value; this.depth = depth; this.prev = null; } public SuperKey( SuperKey src, boolean new_block ) { this.project_key = src.project_key; this.file_key = src.file_key; this.block_key = src.block_key; this.stat_key = src.stat_key; this.expr_key = src.expr_key; this.parent_package_node_key = src.parent_package_node_key; this.parent_class_node_key = src.parent_class_node_key; this.parent_function_node_key = src.parent_function_node_key; this.parent_block_node_key = src.parent_block_node_key; this.parent_node_key = src.parent_node_key; this.node_key = src.node_key; this.value = src.value; this.depth = src.depth; this.prev = src; if ( new_block ) { this.depth++; } } } /////////////////////////////////////////////////////////////////////////////////////////////////// class AST implements sun.tools.javac.IdpConstants { // Missing - IdpConstants public static final int MEMBER_TYPE_METHOD = 1001; public static final int MEMBER_TYPE_INITIALIZER = 1002; public static final int MEMBER_TYPE_CONSTRUCTOR = 1003; public static final int MEMBER_TYPE_FIELD = 1004; public static final int MEMBER_TYPE_INNER = 1005; /////////////////////////////////////////////////////////////////////////////////////////////////// /// Static constant expressions /////////////////////////////////////////////////////////////////////////////////////////////////// public static final int NULL = -1; // Database default value for NULL public static final String NULL_STR = "X"; // Database default value for NULL attribute public static final String UNKNOWN_TYPE = ""; // Unknown Type tag public static final String NO_TYPE = ""; // No Type tag public static final String DEFAULT_PROJECT = ""; // Default project name /////////////////////////////////////////////////////////////////////////////////////////////////// /// Static Parser DBI singleton entry /////////////////////////////////////////////////////////////////////////////////////////////////// public static ParserDatabaseInterface dbi = ParserDatabaseInterface.getInstance(); public static Database hdb = Database.getInstance(); /////////////////////////////////////////////////////////////////////////////////////////////////// /// Project data stuff /////////////////////////////////////////////////////////////////////////////////////////////////// private String project_name; // Project name private String source_file_name; // Source file name private int project_key; // Given by main() or generated private int file_key; // Generated upon file.java source code addition private int node_key_counter; // Node counter private int block_key_counter; // Block counter for this (project_key, file_key) private int statement_key_counter; // Statement counter for this (project_key, file_key, block_key) private int expression_key_counter; // Expression counter for this (project_key, file_key, sk) /////////////////////////////////////////////////////////////////////////////////////////////////// /// Default constructor /////////////////////////////////////////////////////////////////////////////////////////////////// SourceClass src; BatchEnvironment env; static int initializerID = 1; Connection con = null; java.sql.Statement stmt = null; // This stmt will never closd until we return java.sql.ResultSet rs = null; // We should close this ResultSet as soon as possible public AST( BatchEnvironment env, String project ) { /** * Initialize class data */ this.project_name = AST.DEFAULT_PROJECT; this.project_key = AST.NULL; this.file_key = AST.NULL; this.block_key_counter = 0; this.node_key_counter = 0; this.expression_key_counter = 0; this.env = env; this.src = null; /** * From the given project string parameter * retrieve the project_key or create a new one */ retrieveProjectKey( project ); /** * Start the recursive XML parsing algorithm... */ // parseJava(); // // NEED A DAMN FOR..LOOP OF ALL CLASSES INSIDE THE PROGRAM!! // //IdpNode rootNode = walkFile( this.src ); // } /** * Waler stuff starting point * * Create root node * Create package, class, interface, end branch * * Calling: walkClass * */ public IdpNode walkFile( SourceClass src ) { this.src = src; Imports imports = src.getImports(); String fileName = src.getAbsoluteName(); String packageName = imports.getCurrentPackage().toString(); IdpNode rootNode = new IdpNode( null, fileName, SRC_ID, 0 ); int file_node_key = dbAddNode( rootNode ); file_key = getFileKey( fileName, packageName, imports.currentPackageWhere ); if ( file_key == AST.NULL ) { return null; } SuperKey sk = new SuperKey( project_key, file_key ); /** * Update Concept_SourceFile Table entry into the database */ { try { dbi.addFile( project_key, file_key, fileName, AST_File.PARSED, "F" ); } catch( Exception e ) { System.out.println( e.toString() ); } } /** * Add package definition - package head tag */ IdpNode pkgRootNode = rootNode.addChild( "package", PACKAGE_ST, 0 ); dbAddNode( pkgRootNode ); /** * Add package definition - package name tag */ IdpNode pkgChildNode = pkgRootNode.addChild( imports.getCurrentPackage(), PACKAGE_ID, imports.currentPackageWhere ); int package_node_key = dbAddNode( pkgChildNode ); dbAddPackage( sk, package_node_key, imports, pkgChildNode ); /** * Find all import statements */ IdpNode impRootNode = rootNode.addChild( "import", IMPORT_ST, 0 ); dbAddNode( impRootNode ); /** * Find all import package statements */ List impPkgs = imports.getImportedPackages(); for( int i = 0; i < impPkgs.size(); i++ ) { IdentifierToken impPkg = ( IdentifierToken )impPkgs.get( i ); String importName = impPkg.getName().toString(); /** * The default package java.lang.* is always imported */ if ( importName.equals( "java.lang" ) ) { continue; } /** * Package import add wildcard suffix */ IdpNode importChildNode = impRootNode.addChild( impPkg.getName(), IMPORT_ID, impPkg.getWhere() ); int import_node_key = dbAddNode( importChildNode ); dbAddImport( sk, import_node_key, importName + ".*", importName, "Y" ); } /** * Find all import class statements */ List impClasses = imports.getImportedClasses(); for( int i = 0; i < impClasses.size(); i++ ) { IdentifierToken impCls = ( IdentifierToken )impClasses.get( i ); String importName = impCls.getName().toString(); IdpNode importChildNode = impRootNode.addChild( impCls.getName(), IMPORT_ID, impCls.getWhere() ); int import_node_key = dbAddNode( importChildNode ); dbAddImport( sk, import_node_key, importName, importName, "N" ); } /** * Add class or interface definition * * NOTICE: This function will be called for all classes inside a given file: * package class, private class, private interface, package interface */ IdpNode clsRootNode = null; if ( src.isInterface() ) { clsRootNode = rootNode.addChild( "interface", INTERFACE_ST, 0 ); } else { clsRootNode = rootNode.addChild( "class", CLASS_ST, 0 ); } int node_key = dbAddNode( clsRootNode ); /** * Create a class tree */ int result = walkClass( sk, clsRootNode, src, AST.NULL ); /** * If walkClass returns AST.NULL then it is an outer class id, * since AST.NULL means it doesn't have it's own class id. */ if ( result == AST.NULL ) { return null; } /** * Print End Tag */ IdpNode clsEnd = rootNode.addChild( "end", CLASS_END_ID, src.getEndPosition() ); int end_node_key = dbAddNode( clsEnd ); return rootNode; } /////////////////////////////////////////////////////////////////////////////////////////////////// /** * Calling: getClassID, setTypeID * classID = dbInsertClass * * walkModifier * walkType * walkClassField * walkClassMethod * walkInnerClass */ public int walkClass( SuperKey sk0, IdpNode rootNode, ClassDefinition src, int outerClassID ) { SuperKey sk = new SuperKey( sk0, true ); // Add class name String className = getClassID( src ); int classType = setTypeID( src.getType() ); int mod = src.getModifiers(); SourceClass srcClass = ( SourceClass )src; ClassDeclaration extClass = src.getSuperClass(); int superType = setTypeID( extClass.getType() ); long superLocation = src.superClassId.getWhere(); long where = src.getWhere(); long end = srcClass.getEndPosition(); IdpNode clsIdNode = rootNode.addChild( className, CLASS_ID, src.getWhere() ); int class_node_key = dbAddNode( clsIdNode ); int mod_node_key = walkModifier( sk, clsIdNode, mod ); int class_type_node_key = walkType( sk, clsIdNode, src.getType() ); /////////////////////////////////////////////////////////////////////////////////////////////////// int classID = dbInsertClass( sk, src, class_type_node_key, className, class_node_key, classType, mod, where, superType, superLocation, end, outerClassID ); if ( classID == AST.NULL ) { return AST.NULL; } /////////////////////////////////////////////////////////////////////////////////////////////////// IdpNode clsUseRootNode = clsIdNode.addChild( "class used", CLASS_USECLASS_ST, 0 ); dbAddNode( clsUseRootNode ); if ( src instanceof SourceClass ) { Imports imp = ( (SourceClass)src ).getImports(); if ( imp.classes != null ) { for( java.util.Enumeration e = imp.classes.elements(); e.hasMoreElements(); ) { Identifier impCls = ( Identifier )e.nextElement(); /** * VERIFY: Remove the package.java - what is that??? */ String pkg_java = imp.getCurrentPackage() + ".java"; if ( !impCls.toString().equals( pkg_java ) ) { IdpNode child = clsUseRootNode.addChild( impCls, CLASS_USECLASS_ID, 0 ); int child_node_key = dbAddNode( child ); Type impType = Type.tClass( impCls ); if ( impType == null ) { continue; } // Let us add this type to database; int typeID = setTypeID( impType ); // VERIFY int node_key = child_node_key; String qualified_name = impCls.toString(); dbAddClassUsed( sk, classID, typeID, node_key, class_node_key, qualified_name ); } } } } /////////////////////////////////////////////////////////////////////////////////////////////////// /** * Add super class */ Type extType = extClass.getType(); IdpNode extNode = clsIdNode.addChild( "extends", CLASS_EXTEND_ST, 0 ); String extClassName = extClass.getName().toString(); dbAddNode( extNode ); if ( extClass.getClassDefinition() != null ) { extClassName = getClassID( extClass.getClassDefinition() ); } IdpNode extIdNode = extNode.addChild( extClassName, CLASS_EXTEND_ID, src.superClassId.getWhere() ); int ext_node_key = dbAddNode( extIdNode ); // VERIFY int extTypeID = setTypeID( extType ); String extend_qualified_class_name = extClassName; int extId_type_node_key = walkType( sk, extIdNode, extType ); dbAddInherit( sk, ext_node_key, class_node_key, extend_qualified_class_name, "N", classID, extTypeID, extId_type_node_key, where ); /////////////////////////////////////////////////////////////////////////////////////////////////// /** * Add super interface */ IdpNode impNode = clsIdNode.addChild( "implements", CLASS_IMPLEMENT_ST, 0 ); int imp_node_key = dbAddNode( impNode ); ClassDeclaration[] impInterfaces = src.getInterfaces(); for( int i = 0; i < impInterfaces.length; i++ ) { ClassDefinition aInf = impInterfaces[i].getClassDefinition(); String infName = getClassID( aInf ); long class_where = 0; if ( src.interfaceIds != null ) { for( int j = 0; j < src.interfaceIds.length; j++ ) { String s = src.interfaceIds[j].getName().toString(); if ( infName.endsWith( s ) ) { class_where = src.interfaceIds[j].getWhere(); } } } int impTypeID = setTypeID( aInf.getType() ); String inherit_qualified_class_name = infName; IdpNode aImpNode = impNode.addChild( infName, CLASS_IMPLEMENT_ID, class_where ); dbAddNode( aImpNode ); int imp_type_node_key = walkType( sk, aImpNode, aInf.getType() ); //dbAddClassInterface( classID, impTypeID, class_where ); dbAddInherit( sk, imp_node_key, class_node_key, inherit_qualified_class_name, "Y", classID, impTypeID, imp_type_node_key, class_where ); } /////////////////////////////////////////////////////////////////////////////////////////////////// IdpNode memberNode = clsIdNode.addChild( "member", MEMBER_ST, 0 ); dbAddNode( memberNode ); IdpNode fieldNode = memberNode.addChild( "field", FIELD_ST, 0 ); dbAddNode( fieldNode ); IdpNode constructorNode = memberNode.addChild( "constructor", CONSTRUCTOR_ID, 0 ); dbAddNode( constructorNode ); IdpNode methodNode = memberNode.addChild( "method", MEMBER_ST, 0 ); dbAddNode( methodNode ); IdpNode innerNode = memberNode.addChild( "inner class", INNER_ST, 0 ); dbAddNode( innerNode ); IdpNode initNode = memberNode.addChild( "initializers", INITIALIZER_ST, 0 ); dbAddNode( initNode ); /////////////////////////////////////////////////////////////////////////////////////////////////// for( MemberDefinition member = src.getFirstMember(); member != null; member = member.getNextMember() ) { if ( member.isVariable() ) { walkClassField( sk, fieldNode, member, classID ); } else if ( member.isConstructor() ) { walkClassMethod( sk, constructorNode, member, classID ); } else if ( member.isMethod() && !member.isConstructor() && !member.isInitializer() ) { walkClassMethod( sk, methodNode, member, classID ); } else if ( member.isInnerClass() ) { walkInnerClass( sk, innerNode, member, classID ); } else if ( member.isInitializer() ) { walkClassMethod( sk, initNode, member, classID ); } } return classID; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkInnerClass( SuperKey sk, IdpNode r, MemberDefinition m, int classID ) { IdpNode idNode = r.addChild( getMemberID( m ), INNER_ID, m.getWhere() ); int inner_class_node_key = dbAddNode( idNode ); int mod = m.getModifiers(); int typeID = setTypeID( m.getType() ); String memberName = getMemberID( m ); ClassDefinition inner = m.getInnerClass(); if ( inner == null ) { return AST.NULL; } IdpNode classNode = null; if ( inner.isInterface() ) { classNode = idNode.addChild( "interface", INTERFACE_ST, inner.getWhere() ); } else { classNode = idNode.addChild( "class", CLASS_ST, inner.getWhere() ); } dbAddNode( classNode ); // depth already incremented int innerClassID = walkClass( sk, classNode, inner, classID ); int memberID = dbAddInnerClass( sk, r, m, inner, classNode, inner_class_node_key, classID, memberName, typeID, mod, m.getWhere(), innerClassID ); return memberID; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkClassMethod( SuperKey sk, IdpNode r, MemberDefinition member, int classID ) { /** * @todo - I think we should treat the classs member and local member more consistence. */ int mod = member.getModifiers(); Type type = member.getType(); Type returnType = type; if ( type instanceof MethodType ) { returnType = ( ( MethodType )type ).getReturnType(); } int member_type_id = setTypeID( returnType ); String memberName = getMemberID( member ); int memberID = AST.NULL; int memberType = MEMBER_TYPE_METHOD; if ( member.isInitializer() ) { memberType = MEMBER_TYPE_INITIALIZER; } else if ( member.isConstructor() ) { memberType = MEMBER_TYPE_CONSTRUCTOR; } /** * Add method name */ IdpNode idNode = r.addChild( memberName, METHOD_ID, member.getWhere() ); int function_node_key = dbAddNode( idNode ); walkModifier( sk, idNode, mod ); int qualified_return_type_node_key = walkType( sk, idNode, type ); dbAddMethod( sk, member, function_node_key, qualified_return_type_node_key, classID, memberName, member_type_id, mod, member.getWhere(), memberType ); /** * Add parameter starting label node */ IdpNode parasNode = idNode.addChild( "parameter", METHOD_PARAMETER_ST, 0 ); dbAddNode( parasNode ); Vector paras = member.getArguments(); if ( paras != null ) { for( int i = 0; i < paras.size(); i++ ) { /** * Print local member info. */ LocalMember para = ( LocalMember )paras.get( i ); /** * To top-level, a this parameter will transfer to its method body, we will ignore it. * But for inner class, it seems the outer class, as this$0, * has been transfered to a method too, we just keep it. * Otherwise, the following should be .startWith("this") */ if ( para.getName().toString().equals( "this" ) ) { continue; } //if (para.getName() == idThis) continue; int function_param_node_key = walkLocalMember( sk, parasNode, para ); Type paraType = para.getType(); int paraTypeID = setTypeID( paraType ); String paraTypeName = getTypeID( paraType ); String paraName = this.getMemberID( para ); String qualified_argument_type = paraType.toString(); // VERIFY int qualified_argument_type_node_key = paraTypeID; dbAddMethodArgument( sk, function_node_key, function_param_node_key, para, memberID, paraTypeID, paraTypeName, para.getModifiers(), para.getWhere(), i, paraName, para.readcount, para.writecount, qualified_argument_type, qualified_argument_type_node_key ); } } // End of all Method Parameters ClassDeclaration[] exps = member.getExceptions( env ); IdpNode expsNode = idNode.addChild( "throws", METHOD_EXCEPTION_ST, 0 ); dbAddNode( expsNode ); for( int i = 0; i < exps.length; i++ ) { long where = 0; int expTypeID = setTypeID( exps[i].getType() ); String expName = exps[i].getName().toString(); if ( exps[i].getClassDefinition() != null ) { expName = getClassID( exps[i].getClassDefinition() ); } if ( member.expIds != null ) { for( int j = 0; j < member.expIds.length; j++ ) { String s = member.expIds[j].getName().toString(); if ( expName.endsWith( s ) ) { where = member.expIds[j].getWhere(); } } } IdpNode expNode = expsNode.addChild( expName, METHOD_EXCEPTION_ID, where ); int method_exception_node_key = dbAddNode( expNode ); Type expType = exps[i].getType(); String typeName = expType.toString(); int method_exception_type_node_key = walkType( sk, expNode, expType ); dbAddMethodException( sk, method_exception_node_key, method_exception_type_node_key, typeName, memberID, expTypeID, where ); } // End of all Method Exceptions /** * Add body */ IdpNode bodyNode = idNode.addChild( "body", METHOD_BODY_ST, 0 ); dbAddNode( bodyNode ); Node body = member.getValue(); int body_node_key = walkNode( sk, bodyNode, body ); /** * Dump the body, the body start from the idNode */ //idNode.setNumber( 0 ); dbDumpBody( ( IdpNode )bodyNode.getChildAt( 0 ), memberID ); return memberID; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkClassField( SuperKey sk, IdpNode r, MemberDefinition m, int classID ) { int mod = m.getModifiers(); Type type = m.getType(); int member_type_id = setTypeID( type ); Node init = m.getValue(); int memberID = AST.NULL; if ( m.getName().toString().equals( "this" ) ) { return AST.NULL; } String memberName = getMemberID( m ); IdpNode idNode = r.addChild( getMemberID( m ), FIELD_ID, m.getWhere() ); int node_key = dbAddNode( idNode ); int field_mod_node_key = walkModifier( sk, idNode, mod ); int field_type_node_key = walkType( sk, idNode, type ); // Variable dbAddClassFieldMember( sk, m, type, node_key, classID, memberName, member_type_id, mod, m.getWhere() ); //IdpNode accessNode = idNode.addChild("access peer", FIELD_ACCESSPEER_ST, 0 ); //if (m.accessPeer != null) //{ // accessNode.addChild( getMemberID(m.accessPeer), FIELD_ACCESSPEER_ID, 0 ); //} IdpNode initNode = idNode.addChild( "initializer", FIELD_INIT_ST, 0 ); dbAddNode( initNode ); int init_node_key = walkNode( sk, initNode, init ); // Verify this one //idNode.setNumber( 0 ); try { dbUpdateBody( ( IdpNode )initNode.getChildAt( 0 ), memberID ); } catch( Exception e ) { e.printStackTrace(); System.out.println( e ); } /* String bodyInsertSQL = "INSERT INTO idp_member_body " + "(member_id, value, tag, location, number, parent_number) VALUES (" + memberID + ", ?, ?, ?, ?, ?)"; java.sql.PreparedStatement prep = null; try { prep = con.prepareStatement(bodyInsertSQL); //dbInsertBody(idNode, prep, memberID); //stmt.executeBatch(); prep.close(); } catch(Exception e) { System.err.println(e); e.printStackTrace(); try { if (prep != null) prep.close(); } catch(Exception anye) {} } */ return memberID; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkNode( SuperKey sk, IdpNode root, Node node ) { if ( node == null ) { return AST.NULL; } else if ( node instanceof Statement ) { return walkStatement( sk, root, ( Statement )node ); } else if ( node instanceof Expression ) { return walkExpression( sk, root, ( Expression )node ); } return AST.NULL; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkStatement( SuperKey sk, IdpNode root, Statement stat ) { int stat_node_key = AST.NULL; if ( stat == null ) { return AST.NULL; } if ( stat.labels != null ) { for( int i = 0; i < stat.labels.length; i++ ) { IdpNode label = root.addChild( "label", LABEL_ST, 0 ); dbAddNode( label ); IdpNode label_id = label.addChild( stat.labels[i], LABEL_ID, stat.labelsWhere[i] ); int label_node_key = dbAddNode( label_id ); Identifier label_ident = stat.labels[i]; String label_name = label_ident.toString(); dbAddLabel( sk, label_node_key, sk.block_key, i, label_name ); stat_node_key = label_node_key; } } int op = stat.getOp(); long where = stat.getWhere(); IdpNode opNode = null; switch( op ) { case STAT: opNode = root.addChild( "{}", STAT_COMPOUND_ST, where ); dbAddNode( opNode ); stat_node_key = walkCompoundStatement( sk, opNode, ( Statement )stat ); break; case IF: opNode = root.addChild( opNames[IF ], STAT_IF_ST, where ); dbAddNode( opNode ); stat_node_key = walkIfStatement( sk, opNode, ( IfStatement )stat ); break; case SWITCH: opNode = root.addChild( opNames[SWITCH ], STAT_SWITCH_ST, where ); dbAddNode( opNode ); stat_node_key = walkSwitchStatement( sk, opNode, ( SwitchStatement )stat ); break; case CASE: if ( (( CaseStatement )stat).expr == null ) { opNode = root.addChild( opNames[DEFAULT ], STAT_DEFAULT_ST, where ); dbAddNode( opNode ); stat_node_key = walkCaseStatement( sk, opNode, ( CaseStatement )stat ); } else { opNode = root.addChild( opNames[CASE ], STAT_CASE_ST, where ); dbAddNode( opNode ); stat_node_key = walkCaseStatement( sk, opNode, ( CaseStatement )stat ); } break; case BREAK: opNode = root.addChild( opNames[BREAK ], STAT_BREAK_ST, where ); dbAddNode( opNode ); stat_node_key = walkBreakStatement( sk, opNode, ( BreakStatement )stat ); break; case FOR: opNode = root.addChild( opNames[FOR ], STAT_FOR_ST, where ); dbAddNode( opNode ); stat_node_key = walkForStatement( sk, opNode, ( ForStatement )stat ); break; case CONTINUE: opNode = root.addChild( opNames[CONTINUE ], STAT_CONTINUE_ST, where ); dbAddNode( opNode ); stat_node_key = walkContinueStatement( sk, opNode, ( ContinueStatement )stat ); break; case DO: opNode = root.addChild( opNames[DO ], STAT_DO_ST, where ); dbAddNode( opNode ); stat_node_key = walkDoStatement( sk, opNode, ( DoStatement )stat ); break; case WHILE: opNode = root.addChild( opNames[WHILE ], STAT_WHILE_ST, where ); dbAddNode( opNode ); stat_node_key = walkWhileStatement( sk, opNode, ( WhileStatement )stat ); break; case RETURN: opNode = root.addChild( opNames[RETURN ], STAT_RETURN_ST, where ); dbAddNode( opNode ); stat_node_key = walkReturnStatement( sk, opNode, ( ReturnStatement )stat ); break; case TRY: opNode = root.addChild( opNames[TRY ], STAT_TRY_ST, where ); dbAddNode( opNode ); stat_node_key = walkTryStatement( sk, opNode, ( TryStatement )stat ); break; case CATCH: opNode = root.addChild( opNames[CATCH ], STAT_CATCH_ST, where ); dbAddNode( opNode ); stat_node_key = walkCatchStatement( sk, opNode, ( CatchStatement )stat ); break; case FINALLY: opNode = root.addChild( opNames[FINALLY ], STAT_FINALLY_ST, where ); dbAddNode( opNode ); stat_node_key = walkFinallyStatement( sk, opNode, ( FinallyStatement )stat ); break; case THROW: opNode = root.addChild( opNames[THROW ], STAT_THROW_ST, where ); dbAddNode( opNode ); stat_node_key = walkThrowStatement( sk, opNode, ( ThrowStatement )stat ); break; case EXPRESSION: opNode = root.addChild( "expr stat", STAT_EXPRESSION_ST, where ); dbAddNode( opNode ); stat_node_key = walkExpressionStatement( sk, opNode, ( ExpressionStatement )stat ); break; case DECLARATION: opNode = root.addChild( opNames[DECLARATION ], STAT_DECLARATION_ST, where ); dbAddNode( opNode ); stat_node_key = walkDeclarationStatement( sk, opNode, ( DeclarationStatement )stat ); break; case VARDECLARATION: opNode = root.addChild( "var decl", STAT_VARDECLARATION_ST, where ); dbAddNode( opNode ); stat_node_key = walkVarDeclarationStatement( sk, opNode, ( VarDeclarationStatement )stat ); break; case SYNCHRONIZED: opNode = root.addChild( opNames[SYNCHRONIZED], STAT_SYNCHRONIZED_ST, where ); dbAddNode( opNode ); stat_node_key = walkSynchronizedStatement( sk, opNode, ( SynchronizedStatement )stat ); //break; case INLINERETURN: opNode = root.addChild( opNames[INLINERETURN], STAT_INLINE_RETURN_ST, where ); dbAddNode( opNode ); stat_node_key = walkInlineReturnStatement( sk, opNode, ( InlineReturnStatement )stat ); //break; default: opNode = root.addChild( "unknown statement", op, where ); dbAddNode( opNode ); break; } return stat_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkExpression( SuperKey sk, IdpNode root, Expression expr ) { int expr_node_key = AST.NULL; if ( expr == null ) { return AST.NULL; } int op = expr.getOp(); String value = null; switch( op ) { case BOOLEANVAL: case DOUBLEVAL: case FLOATVAL: case LONGVAL: case NULL: case STRINGVAL: case BYTEVAL: case CHARVAL: case SHORTVAL: case INTVAL: // They are all const expression // For const expression, we just put the value in the node. // No other interpretation. /** * @todo - const expressions need more considertion about the value * especially the String has null value and NullExpression * usually, a string const will never be null, so if this is the case * we don't need bother it. anyway, just leave this todo tag */ value = "null"; if ( expr.getValue() != null ) { value = expr.getValue().toString(); } IdpNode constNode = root.addChild( value, op, expr.getWhere() ); expr_node_key = dbAddNode( constNode ); break; case IDENT: // identifier expression expr_node_key = walkIdentifierExpression( sk, root, ( IdentifierExpression )expr ); break; case TYPE: expr_node_key = walkTypeExpression( sk, root, ( TypeExpression )expr ); break; case INLINEMETHOD: expr_node_key = walkInlineMethodExpression( sk, root, ( InlineMethodExpression )expr ); break; case INLINENEWINSTANCE: expr_node_key = walkInlineNewInstanceExpression( sk, root, ( InlineNewInstanceExpression )expr ); break; case THIS: expr_node_key = walkThisExpression( sk, root, ( ThisExpression )expr ); break; case SUPER: expr_node_key = walkSuperExpression( sk, root, ( SuperExpression )expr ); break; //case UNARY: case ARRAYACCESS: // a[b] expr_node_key = walkArrayAccessExpression( sk, root, ( ArrayAccessExpression )expr ); break; //case BINARY: //case BINARYARITHMETIC: case ADD: // + case DIV: // / case REM: // % case MUL: // * case SUB: // - expr_node_key = walkBinaryArithmeticExpression( sk, root, ( BinaryArithmeticExpression )expr ); break; //case BINARYASSIGN: case ASSIGN: // = //case ASSIGNOP: case ASGADD: // += case ASGDIV: // /= case ASGREM: // %= case ASGMUL: // *= case ASGSUB: // -= case ASGLSHIFT: // >>= case ASGRSHIFT: // <<= case ASGURSHIFT: // >>>= case ASGBITAND: // &= case ASGBITOR: // |= case ASGBITXOR: // ^= expr_node_key = walkBinaryAssignExpression( sk, root, ( BinaryAssignExpression )expr ); break; //case BINARYBIT: case BITAND: // & case BITOR: // | case BITXOR: // ^ expr_node_key = walkBinaryBitExpression( sk, root, ( BinaryBitExpression )expr ); break; //case BINARYCOMPARE: case GE: // > case LE: // < case GT: // >= case LT: // <= expr_node_key = walkBinaryCompareExpression( sk, root, ( BinaryCompareExpression )expr ); break; //case BINARYEQUALITY: case EQ: // == case NE: // != expr_node_key = walkBinaryEqualityExpression( sk, root, ( BinaryEqualityExpression )expr ); break; //case BINARYLOGICAL: case AND: // && case OR: // || expr_node_key = walkBinaryLogicalExpression( sk, root, ( BinaryLogicalExpression )expr ); break; //case BINARYSHIFT: case LSHIFT: // >> case RSHIFT: // << case URSHIFT: // >>> expr_node_key = walkBinaryShiftExpression( sk, root, ( BinaryShiftExpression )expr ); break; case CAST: // (x)y expr_node_key = walkCastExpression( sk, root, ( CastExpression )expr ); break; case COMMA: // , ?????????? expr_node_key = walkCommaExpression( sk, root, ( CommaExpression )expr ); break; case COND: // a?b:c expr_node_key = walkConditionalExpression( sk, root, ( ConditionalExpression )expr ); break; case INSTANCEOF: // x instanceof y expr_node_key = walkInstanceOfExpression( sk, root, ( InstanceOfExpression )expr ); break; case BITNOT: // ~ expr_node_key = walkBitNotExpression( sk, root, ( BitNotExpression )expr ); break; case CONVERT: // implicit conversion expr_node_key = walkConvertExpression( sk, root, ( ConvertExpression )expr ); break; case EXPR: // (x) expr_node_key = walkExprExpression( sk, root, ( ExprExpression )expr ); break; case FIELD: expr_node_key = walkFieldExpression( sk, root, ( FieldExpression )expr ); break; //case INCDEC: case POSTDEC: // x-- case POSTINC: // x++ case PREDEC: // --x case PREINC: // ++x expr_node_key = walkIncDecExpression( sk, root, ( IncDecExpression )expr ); break; case LENGTH: expr_node_key = walkLengthExpression( sk, root, ( LengthExpression )expr ); break; //case NARY: case ARRAY: // {x, y, ...} expr_node_key = walkArrayExpression( sk, root, ( ArrayExpression )expr ); break; case METHOD: expr_node_key = walkMethodExpression( sk, root, ( MethodExpression )expr ); break; case NEWARRAY: expr_node_key = walkNewArrayExpression( sk, root, ( NewArrayExpression )expr ); break; case NEWINSTANCE: expr_node_key = walkNewInstanceExpression( sk, root, ( NewInstanceExpression )expr ); break; case NEG: expr_node_key = walkNegativeExpression( sk, root, ( NegativeExpression )expr ); break; case POS: expr_node_key = walkPositiveExpression( sk, root, ( PositiveExpression )expr ); break; case NOT: expr_node_key = walkNotExpression( sk, root, ( NotExpression )expr ); break; default: IdpNode unknownNode = root.addChild( "unknown expression", op, expr.getWhere() ); dbAddNode( unknownNode ); expr_node_key = walkType( sk, unknownNode, expr.getType() ); } return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkNotExpression( SuperKey sk, IdpNode r, NotExpression e ) { IdpNode node = r.addChild( "!", EXPR_NOT_ST, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = node.addChild( "right", EXPR_NOT_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); /////////////////////////////////////////////////////////////////////////// dbAddExpression( sk, expr_node_key, getNewExpressionKey( sk ), AST_Expression.NOT, "!", AST.NULL, right_node_key ); /////////////////////////////////////////////////////////////////////////// return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkPositiveExpression( SuperKey sk, IdpNode r, PositiveExpression e ) { IdpNode node = r.addChild( "+", EXPR_POS_ST, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = node.addChild( "right", EXPR_POS_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); /////////////////////////////////////////////////////////////////////////// dbAddExpression( sk, expr_node_key, getNewExpressionKey( sk ), AST_Expression.PLUS, "+", AST.NULL, right_node_key ); /////////////////////////////////////////////////////////////////////////// return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkNegativeExpression( SuperKey sk, IdpNode r, NegativeExpression e ) { IdpNode node = r.addChild( "-", EXPR_NEG_ST, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = node.addChild( "right", EXPR_NEG_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); /////////////////////////////////////////////////////////////////////////// dbAddExpression( sk, expr_node_key, getNewExpressionKey( sk ), AST_Expression.NEG, "-", AST.NULL, right_node_key ); /////////////////////////////////////////////////////////////////////////// return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkNewInstanceExpression( SuperKey sk, IdpNode r, NewInstanceExpression e ) { IdpNode node = r.addChild( "new", EXPR_NEW_ST, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = node.addChild( "right", EXPR_NEW_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); /////////////////////////////////////////////////////////////////////////// dbAddExpression( sk, expr_node_key, getNewExpressionKey( sk ), AST_Expression.NEW, "new", AST.NULL, right_node_key ); /////////////////////////////////////////////////////////////////////////// IdpNode argNode = node.addChild( "argument", EXPR_NEW_ARG_ST, 0 ); dbAddNode( argNode ); if ( e.args != null ) { for( int i = 0; i < e.args.length; i++ ) { int arg_node_key = walkNode( sk, argNode, e.args[i] ); } } IdpNode refNode = node.addChild( "refer", EXPR_NEW_REF_ST, 0 ); dbAddNode( refNode ); if ( e.field != null ) { IdpNode refID = refNode.addChild( getMemberID( e.field ), EXPR_NEW_REF_ID, 0 ); dbAddNode( refID ); int refer_node_key = walkType( sk, refID, e.field.getType() ); } IdpNode outerNode = node.addChild( "outer args", EXPR_NEW_OUTERARG_ST, 0 ); dbAddNode( outerNode ); int outer_arg_node_key = walkNode( sk, outerNode, e.outerArg ); IdpNode bodyNode = node.addChild( "body", EXPR_NEW_BODY_ST, 0 ); dbAddNode( bodyNode ); if ( e.body != null ) { IdpNode bodyNodeID = bodyNode.addChild( getClassID( e.body ), EXPR_NEW_BODY_ID, 0 ); int body_node_key = dbAddNode( bodyNodeID ); } return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkNewArrayExpression( SuperKey sk, IdpNode r, NewArrayExpression e ) { IdpNode node = r.addChild( "new[]", EXPR_NEW_ARRAY_ST, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = node.addChild( "right", EXPR_NEW_ARRAY_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); /////////////////////////////////////////////////////////////////////////// dbAddExpression( sk, expr_node_key, getNewExpressionKey( sk ), AST_Expression.NEW_ARRAY, "new[]", AST.NULL, right_node_key ); /////////////////////////////////////////////////////////////////////////// IdpNode argNode = node.addChild( "size", EXPR_NEW_ARRAY_ARG_ST, 0 ); dbAddNode( argNode ); if ( e.args != null ) { for( int i = 0; i < e.args.length; i++ ) { int arg_node_key = walkNode( sk, argNode, e.args[i] ); } } IdpNode iniNode = node.addChild( "init", EXPR_NEW_ARRAY_INI_ST, 0 ); dbAddNode( iniNode ); int init_node_key = walkNode( sk, iniNode, e.init ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkArrayExpression( SuperKey sk, IdpNode r, ArrayExpression e ) { IdpNode node = r.addChild( "array", EXPR_ARRAY_ST, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = node.addChild( "right", EXPR_ARRAY_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); /////////////////////////////////////////////////////////////////////////// dbAddExpression( sk, expr_node_key, getNewExpressionKey( sk ), AST_Expression.ARRAY, "array", AST.NULL, right_node_key ); /////////////////////////////////////////////////////////////////////////// IdpNode argNode = node.addChild( "element", EXPR_ARRAY_ARG_ST, 0 ); dbAddNode( argNode ); if ( e.args == null ) { return AST.NULL; } for( int i = 0; i < e.args.length; i++ ) { int arg_node_key = walkNode( sk, argNode, e.args[i] ); } return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkMethodExpression( SuperKey sk, IdpNode r, MethodExpression e ) { IdpNode node = r.addChild( e.id, EXPR_METHOD_ID, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = node.addChild( "right", EXPR_METHOD_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); IdpNode argNode = node.addChild( "args", EXPR_METHOD_ARG_ST, 0 ); dbAddNode( argNode ); if ( e.args != null ) { for( int i = 0; i < e.args.length; i++ ) { int arg_node_key = walkNode( sk, argNode, e.args[i] ); } } IdpNode refNode = node.addChild( "refer", EXPR_METHOD_REF_ST, 0 ); dbAddNode( refNode ); if ( e.field != null ) { IdpNode refID = refNode.addChild( getMemberID( e.field ), EXPR_METHOD_REF_ID, 0 ); int refer_node_key = dbAddNode( refID ); int refer_type_node_key = walkType( sk, refID, e.field.getType() ); } IdpNode clsNode = node.addChild( "class", EXPR_METHOD_CLS_ST, 0 ); dbAddNode( clsNode ); if ( e.clazz != null ) { IdpNode clzNode = clsNode.addChild( getClassID( e.clazz ), EXPR_METHOD_CLS_ID, 0 ); int class_node_key = dbAddNode( clzNode ); } IdpNode impNode = node.addChild( "impl", EXPR_METHOD_IMP_ST, 0 ); dbAddNode( impNode ); int impl_node_key = walkNode( sk, impNode, e.implementation ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkLengthExpression( SuperKey sk, IdpNode r, LengthExpression e ) { IdpNode node = r.addChild( "length", EXPR_LENGTH_ST, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = node.addChild( "right", EXPR_LENGTH_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkIncDecExpression( SuperKey sk, IdpNode r, IncDecExpression e ) { int op = e.op; String opName = opNames[op]; IdpNode node = r.addChild( opName, op, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = node.addChild( "right", EXPR_UNARY_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkFieldExpression( SuperKey sk, IdpNode r, FieldExpression e ) { IdpNode node = r.addChild( e.id, EXPR_FIELD_ID, e.getWhere() ); int expr_node_key = dbAddNode( node ); IdpNode rightNode = node.addChild( "right", EXPR_FIELD_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); IdpNode memberNode = node.addChild( "refer", EXPR_FIELD_REF_ST, 0 ); dbAddNode( memberNode ); if ( e.field != null ) { IdpNode refID = memberNode.addChild( getMemberID( e.field ), EXPR_FIELD_REF_ID, 0 ); int refer_node_key = dbAddNode( refID ); int refer_type_node_key = walkType( sk, refID, e.field.getType() ); } IdpNode classNode = node.addChild( "class", EXPR_FIELD_CLS_ST, 0 ); dbAddNode( classNode ); if ( e.clazz != null ) { IdpNode clzNode = classNode.addChild( getClassID( e.clazz ), EXPR_FIELD_CLS_ID, 0 ); int class_node_key = dbAddNode( clzNode ); } IdpNode impNode = node.addChild( "impl", EXPR_FIELD_IMP_ST, 0 ); dbAddNode( impNode ); int impl_node_key = walkNode( sk, impNode, e.implementation ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkExprExpression( SuperKey sk, IdpNode r, ExprExpression e ) { IdpNode node = r.addChild( "()", EXPR_EXPR_ST, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = r.addChild( "right", EXPR_EXPR_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkConvertExpression( SuperKey sk, IdpNode r, ConvertExpression e ) { IdpNode node = r.addChild( "convert", EXPR_CONVERT_ST, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = node.addChild( "right", EXPR_CONVERT_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkBitNotExpression( SuperKey sk, IdpNode r, BitNotExpression e ) { IdpNode node = r.addChild( "~", EXPR_BIT_NOT_ST, e.getWhere() ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode rightNode = node.addChild( "right", EXPR_BIT_NOT_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkInstanceOfExpression( SuperKey sk, IdpNode r, InstanceOfExpression e ) { IdpNode node = r.addChild( "instanceof", EXPR_INSTANCEOF_ST, e.where ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode leftNode = node.addChild( "left", this.EXPR_INSTANCEOF_LEFT_ST, 0 ); dbAddNode( leftNode ); int left_node_key = walkNode( sk, leftNode, e.left ); IdpNode rightNode = node.addChild( "right", this.EXPR_INSTANCEOF_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkConditionalExpression( SuperKey sk, IdpNode r, ConditionalExpression e ) { IdpNode node = r.addChild( "?:", EXPR_COND_ST, e.where ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode condNode = node.addChild( "cond", EXPR_COND_COND_ST, 0 ); dbAddNode( condNode ); int cond_node_key = walkNode( sk, condNode, e.cond ); IdpNode leftNode = node.addChild( "left", this.EXPR_COND_TRUE_ST, 0 ); dbAddNode( leftNode ); int left_node_key = walkNode( sk, leftNode, e.left ); IdpNode rightNode = node.addChild( "right", this.EXPR_COND_TRUE_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkCommaExpression( SuperKey sk, IdpNode r, CommaExpression e ) { // what is this? IdpNode node = r.addChild( ",", EXPR_COMMA_ST, e.where ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode leftNode = node.addChild( "left", this.EXPR_COMMA_LEFT_ST, 0 ); dbAddNode( leftNode ); int left_node_key = walkNode( sk, leftNode, e.left ); IdpNode rightNode = node.addChild( "right", this.EXPR_COMMA_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkCastExpression( SuperKey sk, IdpNode r, CastExpression e ) { IdpNode node = r.addChild( "cast", EXPR_CAST_ST, e.where ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode leftNode = node.addChild( "left", this.EXPR_CAST_LEFT_ST, 0 ); dbAddNode( leftNode ); int left_node_key = walkNode( sk, leftNode, e.left ); IdpNode rightNode = node.addChild( "right", this.EXPR_CAST_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkBinaryShiftExpression( SuperKey sk, IdpNode r, BinaryShiftExpression e ) { int op = e.op; String opName = opNames[op]; IdpNode node = r.addChild( opName, op, e.where ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode leftNode = node.addChild( "left", this.EXPR_SHIFT_LEFT_ST, 0 ); dbAddNode( leftNode ); int left_node_key = walkNode( sk, leftNode, e.left ); IdpNode rightNode = node.addChild( "right", this.EXPR_SHIFT_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkBinaryLogicalExpression( SuperKey sk, IdpNode r, BinaryLogicalExpression e ) { int op = e.op; String opName = opNames[op]; IdpNode node = r.addChild( opName, op, e.where ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode leftNode = node.addChild( "left", this.EXPR_LOGIC_LEFT_ST, 0 ); dbAddNode( leftNode ); int left_node_key = walkNode( sk, leftNode, e.left ); IdpNode rightNode = node.addChild( "right", this.EXPR_LOGIC_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkBinaryEqualityExpression( SuperKey sk, IdpNode r, BinaryEqualityExpression e ) { int op = e.op; String opName = opNames[op]; IdpNode node = r.addChild( opName, op, e.where ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode leftNode = node.addChild( "left", this.EXPR_EQUALITY_LEFT_ST, 0 ); dbAddNode( leftNode ); int left_node_key = walkNode( sk, leftNode, e.left ); IdpNode rightNode = node.addChild( "right", this.EXPR_EQUALITY_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkBinaryCompareExpression( SuperKey sk, IdpNode r, BinaryCompareExpression e ) { int op = e.op; String opName = opNames[op]; IdpNode node = r.addChild( opName, op, e.where ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode leftNode = node.addChild( "left", this.EXPR_COMP_LEFT_ST, 0 ); dbAddNode( leftNode ); int left_node_key = walkNode( sk, leftNode, e.left ); IdpNode rightNode = node.addChild( "right", this.EXPR_COMP_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkBinaryBitExpression( SuperKey sk, IdpNode r, BinaryBitExpression e ) { int op = e.op; String opName = opNames[op]; IdpNode node = r.addChild( opName, op, e.where ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode leftNode = node.addChild( "left", this.EXPR_BIT_LEFT_ST, 0 ); dbAddNode( leftNode ); int left_node_key = walkNode( sk, leftNode, e.left ); IdpNode rightNode = node.addChild( "right", this.EXPR_BIT_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkBinaryArithmeticExpression( SuperKey sk, IdpNode r, BinaryArithmeticExpression e ) { int op = e.op; String opName = opNames[op]; IdpNode node = r.addChild( opName, op, e.where ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode leftNode = node.addChild( "left", this.EXPR_ARITHMETIC_LEFT_ST, 0 ); dbAddNode( leftNode ); int left_node_key = walkNode( sk, leftNode, e.left ); IdpNode rightNode = node.addChild( "right", this.EXPR_ARITHMETIC_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkBinaryAssignExpression( SuperKey sk, IdpNode r, BinaryAssignExpression e ) { int op = e.op; String opName = opNames[op]; IdpNode node = r.addChild( opName, op, e.where ); dbAddNode( node ); int expr_node_key = walkType( sk, node, e.getType() ); IdpNode leftNode = node.addChild( "left", this.EXPR_ASSIGN_LEFT_ST, 0 ); dbAddNode( leftNode ); int left_node_key = walkNode( sk, leftNode, e.left ); IdpNode rightNode = node.addChild( "right", this.EXPR_ASSIGN_RIGHT_ST, 0 ); dbAddNode( rightNode ); int right_node_key = walkNode( sk, rightNode, e.right ); IdpNode impNode = node.addChild( "impl", this.EXPR_ASSIGN_IMP_ST, 0 ); dbAddNode( impNode ); int impl_node_key = walkNode( sk, impNode, e.implementation ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkArrayAccessExpression( SuperKey sk, IdpNode r, ArrayAccessExpression e ) { IdpNode arrayNode = r.addChild( "[]", this.EXPR_ARRAY_ACCESS_ST, e.getWhere() ); dbAddNode( arrayNode ); int expr_node_key = walkType( sk, arrayNode, e.getType() ); IdpNode exprNode = arrayNode.addChild( "array", this.EXPR_ARRAY_ACCESS_EXPR_ST, 0 ); dbAddNode( exprNode ); int array_node_key = walkNode( sk, exprNode, e.right ); IdpNode indexNode = arrayNode.addChild( "index", this.EXPR_ARRAY_ACCESS_INDEX_ST, 0 ); dbAddNode( indexNode ); int index_node_key = walkNode( sk, indexNode, e.index ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkSuperExpression( SuperKey sk, IdpNode r, SuperExpression e ) { IdpNode superNode = r.addChild( "super", this.EXPR_SUPER_ST, e.getWhere() ); dbAddNode( superNode ); int expr_node_key = walkType( sk, superNode, e.getType() ); IdpNode superMemberNode = superNode.addChild( "refer", this.EXPR_SUPER_REF_ST, 0 ); dbAddNode( superMemberNode ); if ( e.field != null ) { IdpNode refID = superMemberNode.addChild( getMemberID( e.field ), this.EXPR_SUPER_REF_ID, 0 ); int refer_node_key = dbAddNode( refID ); int refer_type_node_key = walkType( sk, refID, e.field.getType() ); } IdpNode superImpNode = superNode.addChild( "impl", this.EXPR_SUPER_IMP_ST, 0 ); dbAddNode( superImpNode ); int impl_node_key = walkNode( sk, superImpNode, e.implementation ); IdpNode superOuterNode = superNode.addChild( "outer args", this.EXPR_SUPER_OUTERARG_ST, 0 ); dbAddNode( superOuterNode ); int outer_args_node_key = walkNode( sk, superOuterNode, e.outerArg ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkThisExpression( SuperKey sk, IdpNode r, ThisExpression e ) { IdpNode thisNode = r.addChild( "this", this.EXPR_THIS_ST, e.getWhere() ); dbAddNode( thisNode ); int expr_node_key = walkType( sk, thisNode, e.getType() ); IdpNode thisMemberNode = thisNode.addChild( "refer", this.EXPR_THIS_REF_ST, 0 ); dbAddNode( thisMemberNode ); if ( e.field != null ) { IdpNode refID = thisMemberNode.addChild( getMemberID( e.field ), this.EXPR_THIS_REF_ID, 0 ); int refer_node_key = dbAddNode( refID ); int refer_type_node_key = walkType( sk, refID, e.field.getType() ); } IdpNode thisImpNode = thisNode.addChild( "impl", this.EXPR_THIS_IMP_ST, 0 ); dbAddNode( thisImpNode ); int impl_node_key = walkNode( sk, thisImpNode, e.implementation ); IdpNode thisOuterNode = thisNode.addChild( "outer args", this.EXPR_THIS_OUTERARG_ST, 0 ); dbAddNode( thisOuterNode ); int outer_args_node_key = walkNode( sk, thisOuterNode, e.outerArg ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkInlineNewInstanceExpression( SuperKey sk, IdpNode r, InlineNewInstanceExpression e ) { IdpNode inNewNode = r.addChild( "inline new", this.EXPR_INLINE_NEWINSTANCE_ST, e.getWhere() ); dbAddNode( inNewNode ); int expr_node_key = walkType( sk, inNewNode, e.getType() ); IdpNode inNewMemberNode = inNewNode.addChild( "refer", this.EXPR_INLINE_NEWINSTANCE_REF_ST, 0 ); dbAddNode( inNewMemberNode ); if ( e.field != null ) { IdpNode refID = inNewMemberNode.addChild( getMemberID( e.field ), this.EXPR_INLINE_NEWINSTANCE_REF_ID, 0 ); int refer_node_key = dbAddNode( refID ); int refer_type_node_key = walkType( sk, refID, e.field.getType() ); } IdpNode inNewBodyNode = inNewNode.addChild( "body", this.EXPR_INLINE_NEWINSTANCE_BODY_ST, 0 ); dbAddNode( inNewBodyNode ); int body_node_key = walkNode( sk, inNewBodyNode, e.body ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkInlineMethodExpression( SuperKey sk, IdpNode r, InlineMethodExpression e ) { IdpNode inMethodNode = r.addChild( "inline method", this.EXPR_INLINE_METHOD_ST, e.getWhere() ); dbAddNode( inMethodNode ); int expr_node_key = walkType( sk, inMethodNode, e.getType() ); IdpNode inMethodMemberNode = inMethodNode.addChild( "refer", this.EXPR_INLINE_METHOD_REF_ST, 0 ); dbAddNode( inMethodMemberNode ); if ( e.field != null ) { IdpNode refID = inMethodMemberNode.addChild( getMemberID( e.field ), this.EXPR_INLINE_METHOD_REF_ID, 0 ); int refer_node_key = dbAddNode( refID ); int refer_type_node_key = walkType( sk, refID, e.field.getType() ); } IdpNode inMethodBodyNode = inMethodNode.addChild( "body", this.EXPR_INLINE_METHOD_BODY_ST, 0 ); dbAddNode( inMethodBodyNode ); int body_node_key = walkNode( sk, inMethodBodyNode, e.body ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkIdentifierExpression( SuperKey sk, IdpNode r, IdentifierExpression e ) { //if (e.getType().getTypeCode() == TC_ERROR) return; IdpNode idNode = r.addChild( e.id, EXPR_IDENT_ID, e.getWhere() ); dbAddNode( idNode ); int expr_node_key = walkType( sk, idNode, e.getType() ); IdpNode memberNode = idNode.addChild( "refer", this.EXPR_IDENT_REF_ST, 0 ); dbAddNode( memberNode ); if ( e.field != null ) { IdpNode refID = memberNode.addChild( this.getMemberID( e.field ), EXPR_IDENT_REF_ID, 0 ); int refer_node_key = dbAddNode( refID ); int refer_type_node_key = walkType( sk, refID, e.field.getType() ); } IdpNode impNode = idNode.addChild( "impl", this.EXPR_IDENT_IMP_ST, 0 ); dbAddNode( impNode ); int impl_node_key = walkNode( sk, impNode, e.implementation ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkTypeExpression( SuperKey sk, IdpNode r, TypeExpression e ) { IdpNode typeNode = r.addChild( "type expr", EXPR_TYPE_ST, e.getWhere() ); dbAddNode( typeNode ); int expr_node_key = walkType( sk, typeNode, e.getType() ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkVarDeclarationStatement( SuperKey sk, IdpNode r, VarDeclarationStatement t ) { int node_key = walkLocalMember( sk, r, t.field ); /** * @todo is the following initializer same to the variable initializer? */ //walkNode( sk, r, t.expr); return node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkDeclarationStatement( SuperKey sk, IdpNode r, DeclarationStatement t ) { int node_key = sk.node_key; int mod_node_key = walkModifier( sk, r, t.mod ); /** * @todo is the type info here useful? */ //walkNode( sk, r, t.type); for( int i = 0; i < t.args.length; i++ ) { int arg_node_key = walkNode( sk, r, t.args[i] ); if ( i == 0 ) { node_key = arg_node_key; } } return node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkInlineReturnStatement( SuperKey sk, IdpNode r, InlineReturnStatement t ) { int node_key = walkNode( sk, r, t.expr ); return node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkReturnStatement( SuperKey sk, IdpNode r, ReturnStatement t ) { int node_key = walkNode( sk, r, t.expr ); return node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkExpressionStatement( SuperKey sk, IdpNode r, ExpressionStatement t ) { int node_key = walkNode( sk, r, t.expr ); return node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkSynchronizedStatement( SuperKey sk, IdpNode r, SynchronizedStatement s ) { IdpNode exprNode = r.addChild( "expr", STAT_SYNCHRONIZED_EXPR_ST, 0 ); dbAddNode( exprNode ); int expr_node_key = walkNode( sk, exprNode, s.expr ); IdpNode bodyNode = r.addChild( "body", STAT_SYNCHRONIZED_BODY_ST, 0 ); dbAddNode( bodyNode ); int body_node_key = walkNode( sk, bodyNode, s.body ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkTryStatement( SuperKey sk, IdpNode r, TryStatement t ) { IdpNode bodyNode = r.addChild( "body", STAT_TRY_BODY_ST, 0 ); dbAddNode( bodyNode ); int body_node_key = walkNode( sk, bodyNode, t.body ); for( int i = 0; i < t.args.length; i++ ) { // a set of catch statement int catch_node_key = walkNode( sk, r, t.args[i] ); } return body_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkCatchStatement( SuperKey sk, IdpNode r, CatchStatement t ) { /** * @todo - make catch statement more meaningful */ IdpNode expNode = r.addChild( "expr", STAT_CATCH_EXPR_ST, 0 ); dbAddNode( expNode ); int expr_node_key = walkNode( sk, expNode, t.texpr ); IdpNode paraNode = r.addChild( "parameter", STAT_CATCH_FIELD_ST, 0 ); dbAddNode( paraNode ); if ( t.field != null ) { // should not be int param_node_key = walkLocalMember( sk, paraNode, t.field ); } IdpNode bodyNode = r.addChild( "body", STAT_CATCH_BODY_ST, 0 ); dbAddNode( bodyNode ); int body_node_key = walkNode( sk, bodyNode, t.body ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkFinallyStatement( SuperKey sk, IdpNode r, FinallyStatement t ) { IdpNode bodyNode = r.addChild( "body", STAT_FINALLY_BODY_ST, 0 ); dbAddNode( bodyNode ); IdpNode finalBodyNode = r.addChild( "final", STAT_FINALLY_FINAL_BODY_ST, 0 ); dbAddNode( finalBodyNode ); int body_node_key = walkNode( sk, bodyNode, t.body ); int final_node_key = walkNode( sk, finalBodyNode, t.finalbody ); return body_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkThrowStatement( SuperKey sk, IdpNode r, ThrowStatement t ) { int node_key = walkNode( sk, r, t.expr ); return node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkWhileStatement( SuperKey sk, IdpNode r, WhileStatement t ) { IdpNode condNode = r.addChild( "cond", STAT_WHILE_COND_ST, 0 ); dbAddNode( condNode ); IdpNode bodyNode = r.addChild( "body", STAT_WHILE_BODY_ST, 0 ); dbAddNode( bodyNode ); int cond_node_key = walkNode( sk, condNode, t.cond ); int body_node_key = walkNode( sk, bodyNode, t.body ); return cond_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkDoStatement( SuperKey sk, IdpNode r, DoStatement t ) { IdpNode condNode = r.addChild( "cond", STAT_DO_COND_ST, 0 ); dbAddNode( condNode ); IdpNode bodyNode = r.addChild( "body", STAT_DO_BODY_ST, 0 ); dbAddNode( bodyNode ); int cond_node_key = walkNode( sk, condNode, t.cond ); int body_node_key = walkNode( sk, bodyNode, t.body ); return cond_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkForStatement( SuperKey sk, IdpNode r, ForStatement t ) { IdpNode initNode = r.addChild( "init", STAT_FOR_INIT_ST, 0 ); dbAddNode( initNode ); IdpNode condNode = r.addChild( "cond", STAT_FOR_COND_ST, 0 ); dbAddNode( condNode ); IdpNode incNode = r.addChild( "inc", STAT_FOR_INC_ST, 0 ); dbAddNode( incNode ); IdpNode bodyNode = r.addChild( "body", STAT_FOR_BODY_ST, 0 ); dbAddNode( bodyNode ); int init_node_key = walkNode( sk, initNode, t.init ); int cond_node_key = walkNode( sk, condNode, t.cond ); int inc_node_key = walkNode( sk, incNode, t.inc ); int body_node_key = walkNode( sk, bodyNode, t.body ); return init_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkContinueStatement( SuperKey sk, IdpNode r, ContinueStatement t ) { if ( t.lbl == null ) { return AST.NULL; } IdpNode label = r.addChild( t.lbl, STAT_CONTINUE_LABEL_ID, 0 ); int expr_node_key = dbAddNode( label ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkSwitchStatement( SuperKey sk, IdpNode r, SwitchStatement t ) { IdpNode condNode = r.addChild( "expr", STAT_SWITCH_EXPR_ST, 0 ); dbAddNode( condNode ); int expr_node_key = walkNode( sk, condNode, t.expr ); IdpNode bodyNode = r.addChild( "body", STAT_SWITCH_BODY_ST, 0 ); dbAddNode( bodyNode ); for( int i = 0; i < t.args.length; i++ ) { int body_node_key = walkNode( sk, bodyNode, t.args[i] ); } return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkCaseStatement( SuperKey sk, IdpNode r, CaseStatement t ) { int node_key = walkNode( sk, r, t.expr ); return node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkBreakStatement( SuperKey sk, IdpNode r, BreakStatement t ) { if ( t.lbl == null ) { return AST.NULL; } IdpNode node = r.addChild( t.lbl, STAT_BREAK_LABEL_ID, 0 ); int expr_node_key = dbAddNode( node ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkIfStatement( SuperKey sk, IdpNode r, IfStatement t ) { IdpNode condNode = r.addChild( "cond", STAT_IF_COND_ST, 0 ); dbAddNode( condNode ); IdpNode trueNode = r.addChild( "if true", STAT_IF_TRUE_ST, 0 ); dbAddNode( trueNode ); IdpNode falseNode = r.addChild( "if false", STAT_IF_FALSE_ST, 0 ); dbAddNode( falseNode ); int expr_node_key = walkNode( sk, condNode, t.cond ); int true_node_key = walkNode( sk, trueNode, t.ifTrue ); int false_node_key = walkNode( sk, falseNode, t.ifFalse ); return expr_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int walkCompoundStatement( SuperKey sk, IdpNode r, Statement t ) { int node_key = sk.node_key; if ( t instanceof CompoundStatement ) { Statement[] stats = ( ( CompoundStatement )t ).args; for( int i = 0; i < stats.length; i++ ) { int arg_node_key = walkNode( sk, r, stats[i] ); if ( i == 0 ) { node_key = arg_node_key; } } } return node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public String getClassID( ClassDefinition c ) { Identifier cName = c.getName(); if ( cName.isInner() ) { cName = Type.mangleInnerType( cName ); } return cName.toString(); } /////////////////////////////////////////////////////////////////////////////////////////////////// /** * Get the member id which should unique its scop * to a local member, the member id is the member name and the hashcode of which the local member is defined * to a calss method, the member id is the quanlified class name + . + its name + (parameter type, ...) + return type * to a class field, the member id is the quanlified class + its name * * @param m the member * @return an unique string to the member's scope */ public String getMemberID( MemberDefinition m ) { StringBuffer s = new StringBuffer( "" ); String classID = getClassID( m.getClassDefinition() ); if ( m.isVariable() && m.isLocal() ) { s.append( m.getName() + "." + m.hashCode() ); } else if ( m.isMethod() && !m.isInitializer() ) { String methodName = classID + "." + m.getName(); s.append( m.getType().typeString( methodName ) ); } else if ( m.isInnerClass() ) { s.append( getClassID( m.getInnerClass() ) ); //s.append( m.getClassDeclaration().getName() + "$" + m.getName() ); } else if ( m.isInitializer() ) { String methodName = classID + "."; ; s.append( m.getType().typeString( methodName ) ); this.initializerID++; } else { // It should be a field s.append( getTypeID( m.getType() ) + " " + classID + "." + m.getName() ); } return s.toString(); } /////////////////////////////////////////////////////////////////////////////////////////////////// /** * Add the localmember info to the root node. * The localmember tree is a tree starts from its name * and its children are the modifier, type info, variable number, read count, write count, scope number * and a expression that initializes the variable. * @param root the root node which you want to add the local member info * @param m the local member */ public int walkLocalMember( SuperKey sk, IdpNode root, LocalMember m ) { IdpNode idNode = root.addChild( m.getName().toString() + "." + m.hashCode(), LOCAL_ID, m.getWhere() ); int node_key = dbAddNode( idNode ); int mod_node_key = walkModifier( sk, idNode, m.getModifiers() ); int type_node_key = walkType( sk, idNode, m.getType() ); IdpNode numberNode = idNode.addChild( "number", LOCAL_NUMBER_ST, 0 ); dbAddNode( numberNode ); IdpNode numberNodeNo = numberNode.addChild( Integer.toString( m.number ), LOCAL_NUMBER_NO, 0 ); dbAddNode( numberNodeNo ); IdpNode readNode = idNode.addChild( "read", LOCAL_READ_ST, 0 ); dbAddNode( readNode ); IdpNode readNodeNo = readNode.addChild( Integer.toString( m.readcount ), LOCAL_READ_NO, 0 ); dbAddNode( readNodeNo ); IdpNode writeNode = idNode.addChild( "write", LOCAL_WRITE_ST, 0 ); dbAddNode( writeNode ); IdpNode writeNodeNo = writeNode.addChild( Integer.toString( m.writecount ), LOCAL_WRITE_NO, 0 ); dbAddNode( writeNodeNo ); IdpNode scopeNode = idNode.addChild( "scope", LOCAL_SCOPE_ST, 0 ); dbAddNode( scopeNode ); IdpNode scopeNodeNo = scopeNode.addChild( Integer.toString( m.scopeNumber ), LOCAL_SCOPE_NO, 0 ); dbAddNode( scopeNodeNo ); IdpNode initNode = idNode.addChild( "init", LOCAL_INIT_ST, 0 ); dbAddNode( initNode ); walkNode( sk, initNode, m.getValue() ); return node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public Type getArrayElement( ArrayType t ) { if ( t.getElementType().getTypeCode() == TC_ARRAY ) { return getArrayElement( ( ArrayType )t.getElementType() ); } else { return t.getElementType(); } } /////////////////////////////////////////////////////////////////////////////////////////////////// /** * Get an typeid, which is unique to all the program including the system classes like java.lang, java.util, etc. * @param type the type * @return and string value that is unique to the global view */ public String getTypeID( Type type ) { if ( type == null ) { return null; } StringBuffer id = new StringBuffer( type.typeString( "", false, true ) ); if ( type.getTypeCode() == TC_ARRAY ) { Type element = getArrayElement( ( ArrayType )type ); id = new StringBuffer( getTypeID( element ) ); for( int i = 0; i < ( ( ArrayType )type ).getArrayDimension(); i++ ) { id.append( "[]" ); } } else if ( type.getTypeCode() == TC_CLASS ) { if ( type.getClassName().isInner() ) { id = new StringBuffer( Type.mangleInnerType( type.getClassName() ).toString() ); } } return id.toString(); } /////////////////////////////////////////////////////////////////////////////////////////////////// /** * Add the type info to the rootNode. * Currently we only a "Type" node to the root and * add the typeid to "Type" node. * @param root the root node to add type info * @param type the type */ public int walkType( SuperKey sk, IdpNode root, Type type ) { //IdpNode typeNode = root.addChild("type", TYPE_ST, 0); if ( type == null ) { IdpNode node = root.addChild( "?", TYPE_ID, 12 ); // if the type is null, we add a error type. dbAddNode( node ); } Identifier typeID = Identifier.lookup( getTypeID( type ) ); IdpNode code = root.addChild( typeID, TYPE_ID, type.getTypeCode() ); int type_node_key = dbAddNode( code ); return type_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// /** * Add modifier info the the root node * Currently, only an integer type string is added to the "Modifier" node, * any string descriptions are remitted. * @param root the root node * @param mod the int modifier */ public int walkModifier( SuperKey sk, IdpNode root, int mod ) { IdpNode node = root.addChild( Integer.toString( mod ), MOD_ID, 0 ); int modifier_node_key = dbAddNode( node ); return modifier_node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// /** * given a node, this will trace the route from this node to the top most parent * @param node the node you want to know the whole parent route */ public static void printRoute( IdpNode node ) { if ( node == null ) { return; } System.out.println( node ); printRoute( ( IdpNode )node.getParent() ); } /////////////////////////////////////////////////////////////////////////////////////////////////// private int parseInt( String s ) { int i = -1; try { i = Integer.parseInt( s, 10 ); } catch( NumberFormatException nfe ) { i = -1; } return i; // return (int)new Long( s ).int Value(); } /////////////////////////////////////////////////////////////////////////////////////////////////// /// Database Interface call /////////////////////////////////////////////////////////////////////////////////////////////////// /** * From the given project string parameter * retrieve the project_key or create a new one */ private void retrieveProjectKey( String project ) { if ( project == null ) { project = "-1"; } project_key = parseInt( project ); if ( project_key < 0 ) { if ( project.length() > 0 && project != "-1" ) { /** * Try to use project as a project_name */ try { String selectSQL = "SELECT MAX( project_key ) FROM Concept_Project " + "WHERE project_name = '" + hdb.addSlashes( project ) + "'" ; Database hdb = Database.getInstance(); Results r = hdb.Query( selectSQL ); if ( r.RecordCount() > 0 ) { project_key = r.GetFieldInteger( 0 ); } } catch( SQLException se ) { /** * Could not execute query */ System.out.println( se.toString() ); } catch( Exception ex ) { /** * Other exception */ System.out.println( ex.toString() ); } } } else { try { if ( !dbi.ifExistProject( project_key ) ) { project_name = "Project" + new Integer( project_key ).toString(); dbi.addProject( project_key, project_name ); } } catch( SQLException se ) { /** * Could not execute query */ System.out.println( se.toString() ); } catch( Exception ex ) { /** * Other exception */ System.out.println( ex.toString() ); } } /** * Sorry: No valid project found... * Create a new project_key */ if ( project_key < 0 ) { try { // project_key = dbi.addProject( project_key, project ); } catch( SQLException se ) { /** * Could not execute query */ System.out.println( se.toString() ); } catch( Exception ex ) { /** * Other exception */ System.out.println( ex.toString() ); } } } /////////////////////////////////////////////////////////////////////////////////////////////////// private String getVarName( String variable_name ) { return variable_name; } /////////////////////////////////////////////////////////////////////////////////////////////////// private String getVarType( String variable_type ) { return variable_type; } /////////////////////////////////////////////////////////////////////////////////////////////////// private int getVarArray( String variable_name ) { int nb_array = 0; for( int i = 0; i < variable_name.length(); i++ ) { if ( variable_name.charAt( i ) == '[' ) { nb_array++; } } return nb_array; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int getJavaFileID( String fileName, String packageName, long packageWhere ) { String selectSQL = "SELECT idp_javafile.id, idp_javafile.last_modified FROM idp_javafile " + "WHERE idp_javafile.name = ? AND idp_javafile.project_id = ?"; String insertSQL = "INSERT INTO idp_javafile " + "(project_id, name, content, last_modified, package_name, package_location) " + "VALUES (?, ?, ?, ?, ?, ?)"; int id = AST.NULL; boolean needAdd = true; java.sql.PreparedStatement prep = null; try { java.io.File file = new java.io.File( fileName ); java.sql.Timestamp fileDate = new java.sql.Timestamp( file.lastModified() ); prep = con.prepareStatement( selectSQL ); prep.setString( 1, fileName ); prep.setInt( 2, project_key ); rs = prep.executeQuery(); if ( rs.next() ) { // File exist java.sql.Timestamp modified = rs.getTimestamp( 2 ); if ( fileDate.after( modified ) ) { // The file in database is older than the current one, rs.deleteRow(); needAdd = true; } else { id = rs.getInt( 1 ); if ( prep != null ) { prep.close(); } if ( rs != null ) { rs.close(); } // If the file is newer than the submit one, we will ignore this file; return id; } } if ( prep != null ) { prep.close(); } if ( needAdd ) { prep = con.prepareStatement( insertSQL ); prep.setInt( 1, project_key ); prep.setString( 2, fileName ); String content = ""; try { FileInputStream ff = new FileInputStream( file ); byte[] b = new byte[ ( int )file.length() ]; ff.read( b ); content = new String( b ); } catch( Exception e ) { } prep.setString( 3, content ); prep.setTimestamp( 4, fileDate ); prep.setString( 5, packageName ); prep.setLong( 6, packageWhere ); prep.execute(); if ( prep != null ) { prep.close(); } prep = con.prepareStatement( selectSQL ); prep.setString( 1, fileName ); prep.setInt( 2, project_key ); rs = prep.executeQuery(); if ( rs.next() ) { id = rs.getInt( 1 ); } } if ( prep != null ) { prep.close(); } if ( rs != null ) { rs.close(); } return id; } catch( SQLException sqle ) { try { if ( prep != null ) { prep.close(); } if ( rs != null ) { rs.close(); } } catch( Exception e ) { System.out.println( e.toString() ); } return AST.NULL; } } /////////////////////////////////////////////////////////////////////////////////////////////////// public int setTypeID( Type type ) { if ( type.idpTypeID != AST.NULL ) { return type.idpTypeID; } int typeCode = type.getTypeCode(); String typeString = getTypeID( type ); int id = AST.NULL; try { String selectSQL = "SELECT idp_type.id FROM idp_type WHERE idp_type.code = " + typeCode + " AND idp_type.string = '" + typeString + "'"; String insertSQL = "INSERT INTO idp_type (code, string) VALUES (" + typeCode + ", " + "'" + typeString + "')"; stmt.execute( selectSQL ); ResultSet rs = stmt.getResultSet(); if ( rs.next() ) { id = rs.getInt( 1 ); type.idpTypeID = id; rs.close(); return id; } rs.close(); //ops, no type, let us add it stmt.execute( insertSQL ); stmt.execute( selectSQL ); rs = stmt.getResultSet(); id = AST.NULL; if ( rs.next() ) { id = rs.getInt( 1 ); } type.idpTypeID = id; rs.close(); return id; } catch( Exception e ) { e.printStackTrace(); id = AST.NULL; } return id; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int dbInsertClass( SuperKey sk, ClassDefinition src, int class_type_node_key, String className, int class_node_key, int classType, int mod, long where, int superType, long superLocation, long end, int outerClassID ) { String selectSQL = "SELECT idp_class.id WHERE idp_class.javafile_id = " + file_key + "AND idp_class.type_id = " + classType; String deleteSQL = "DELETE FROM idp_class WHERE idp_class.javafile_id = " + file_key + "AND idp_class.type_id = " + classType; String insertSQL = "INSERT INTO idp_class " + "(javafile_id, type_id, modifier, location, super_type_id, super_location, end_location) VALUES (" + file_key + ", " + classType + ", " + mod + ", " + where + ", " + superType + ", " + superLocation + ", " + end + ")"; if ( outerClassID != AST.NULL ) { insertSQL = "INSERT INTO idp_class " + "(javafile_id, type_id, modifier, location, super_type_id, super_location, end_location, outer_class_id) VALUES (" + file_key + ", " + classType + ", " + mod + ", " + where + ", " + superType + ", " + superLocation + ", " + end + ", " + outerClassID + ")"; } int classID = AST.NULL; try { stmt.execute( deleteSQL ); // ok, let us start insert; stmt.execute( insertSQL ); rs = stmt.executeQuery( selectSQL ); if ( rs.next() ) { classID = rs.getInt( 1 ); } rs.close(); } catch( Exception e ) { System.out.println( e.toString() ); classID = AST.NULL; } int block_key = getNewBlockKey( sk ); int block_type = AST_Block.CLASS; // VERIFY - MODIFY THIS... sk.parent_class_node_key = outerClassID; int node_key = class_node_key; String qualified_class_name = className; String is_interface = ( src.isInterface() ? "Y" : "N" ); String is_static = ( src.isStatic() ? "Y" : "N" ); String is_anonymous = ( src.isAnonymous() ? "Y" : "N" ); String is_final = ( src.isFinal() ? "Y" : "N" ); String is_abstract = ( src.isAbstract() ? "Y" : "N" ); String is_deprecated = ( src.isDeprecated() ? "Y" : "N" ); /** * Tell if the class is inner. * This predicate also returns true for top-level nested types. * To test for a true inner class as seen by the programmer, * use !isTopLevel(). */ String is_inner_class = ( src.isInnerClass() ? "Y" : "N" ); /** * Tell if the class is a member of another class. * This is false for package members and for block-local classes. */ String is_member = ( src.isMember() ? "Y" : "N" ); /** * Tell if the class is "top-level", which is either a package member, * or a static member of another top-level class. */ String is_top_level = ( src.isTopLevel() ? "Y" : "N" ); /** * Tell if the class is local or or anonymous class, or inside * such a class, which means it cannot be mentioned outside of its file. */ String is_inside_local_or_anonymous = ( src.isInsideLocalOrAnonymous() ? "Y" : "N" ); String is_synthetic = ( src.isSynthetic() ? "Y" : "N" ); String is_local = ( src.isLocal() ? "Y" : "N" ); String has_constructor = ( src.hasConstructor() ? "Y" : "N" ); /** * Retrieve the protection scheme for such class */ String class_protection = "package"; if ( src.isAnonymous() ) { class_protection = "anonymous"; } else if ( src.isPublic() ) { class_protection = "public"; } else if ( src.isPrivate() ) { class_protection = "private"; } else if ( src.isProtected() ) { class_protection = "protected"; } else if ( src.isPackagePrivate() ) { class_protection = "package"; } /** * Add-on stuff */ int class_type = classType; int class_modifier = mod; int super_type = superType; int super_start_line = getLine( superLocation ); int super_file_pos_offset = getOffset( superLocation ); int end_line = getLine( end ); int end_file_pos_offset = getOffset( end ); int class_id = classID; int outer_class_id = outerClassID; /** * Add a AST_Class entry into the database */ try { AST_Class c = AST_Class.createClass( block_key, block_type, sk.parent_package_node_key, sk.parent_class_node_key, sk.parent_function_node_key, sk.parent_block_node_key, sk.depth, node_key, class_type_node_key, qualified_class_name, is_interface, is_static, is_anonymous, is_final, is_abstract, is_deprecated, is_inner_class, is_member, is_top_level, is_inside_local_or_anonymous, is_synthetic, is_local, has_constructor, class_protection, class_type, class_modifier, super_type, super_start_line, super_file_pos_offset, end_line, end_file_pos_offset, class_id, outer_class_id ); } catch ( Exception e ) { System.out.println( e.toString() ); } sk.parent_class_node_key = class_node_key; sk.parent_block_node_key = class_node_key; return classID; } /////////////////////////////////////////////////////////////////////////////////////////////////// public void dbAddClassUsed( SuperKey sk, int class_id, int type_id, int node_key, int class_node_key, String qualified_name ) { try { String insertSQL = "INSERT INTO idp_class_used " + "(class_id, type_id) VALUES (" + class_id + ", " + type_id + ")" ; stmt.addBatch( insertSQL ); } catch( Exception e ) { System.out.println( e.toString() ); } /** * Add a AST_Class_Used entry into the database */ try { AST_Class_Used data = new AST_Class_Used( node_key, this.file_key, class_id, type_id, class_node_key, qualified_name ); } catch ( Exception e ) { System.out.println( e.toString() ); } } /////////////////////////////////////////////////////////////////////////////////////////////////// public int dbAddInnerClass( SuperKey sk, IdpNode root, MemberDefinition member, ClassDefinition inner, IdpNode classNode, int inner_class_node_key, int classID, String memberName, int typeID, int mod, long where, int innerClassID ) { int memberID = AST.NULL; String insertSQL = "INSERT INTO idp_member " + "(class_id, name, type_id, modifier, location, inner_class_id, member_type) VALUES (" + classID + ", '" + memberName + "', " + typeID + ", " + mod + ", " + where + ", " + innerClassID + ", " + MEMBER_TYPE_INNER + ")"; String selectSQL = "SELECT idp_member.id WHERE idp_member.class_id = " + classID + " AND idp_member.name = '" + memberName + "'"; try { stmt.execute( insertSQL ); stmt.executeQuery( selectSQL ); rs.close(); rs = stmt.getResultSet(); if ( rs.next() ) { memberID = rs.getInt( 1 ); rs.close(); } else { rs.close(); memberID = AST.NULL; } } catch( Exception e ) { try { if ( rs != null ) { rs.close(); } } catch ( Exception fe ) { System.out.println( fe.toString() ); } } return memberID; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int getFileKey( String fileName, String packageName, long packageWhere ) { // Query database... return 1; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int getNewNodeKey() { try { node_key_counter = dbi.getNewNodeKey(); } catch( Exception e ) { node_key_counter++; System.out.println( e.toString() ); } return node_key_counter; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int getNewBlockKey( SuperKey sk ) { block_key_counter++; try { // Depends on project_key, file_key, block_key //block_key_counter = dbi.getNewBlockKey(); } catch( Exception e ) { System.out.println( e.toString() ); } return block_key_counter; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int getNewStatementKey( SuperKey sk ) { statement_key_counter++; try { // Depends on project_key, file_key, block_key //statement_key_counter = dbi.getNewStatementKey(); } catch( Exception e ) { System.out.println( e.toString() ); } return statement_key_counter; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int getNewExpressionKey( SuperKey sk ) { expression_key_counter++; try { // Depends on project_key, file_key, block_key, statement_key //expression_key_counter = dbi.getNewBlockKey(); } catch( Exception e ) { System.out.println( e.toString() ); } return expression_key_counter; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int getLine( long where ) { return (int)( where >> 32 ); } /////////////////////////////////////////////////////////////////////////////////////////////////// public int getOffset( long where ) { return (int)( where ); } /////////////////////////////////////////////////////////////////////////////////////////////////// public int dbAddNode( IdpNode current_node ) { node_key_counter = getNewNodeKey(); current_node.setNodeNo( node_key_counter ); int parent_no = AST.NULL; IdpNode parent = (IdpNode) current_node.getParent(); if ( parent != null ) { parent_no = parent.getNodeNo(); } /////////////////////////////////////////////////////////////////////////////////////////////// /** * Setup variables for the auto-generated dynamic function */ int project_key = this.project_key; int file_key = this.file_key; int node_key = current_node.getNodeNo(); String node_name = current_node.getValue(); int node_type = current_node.getTag(); int parent_node_key = parent_no; int start_line = current_node.getLine(); int file_pos_offset = current_node.getOffset(); /////////////////////////////////////////////////////////////////////////////////////////////// /** * Add a AST_Node entry into the database */ try { AST_Node n = AST_Node.createNode( project_key, file_key, node_key, node_name, node_type, parent_node_key, start_line, file_pos_offset ); } catch( java.lang.Exception e ) { } return node_key; } /////////////////////////////////////////////////////////////////////////////////////////////////// public int dbAddMethod( SuperKey sk, MemberDefinition member, int method_node_key, int qualified_return_type_node_key, int class_id, String memberName, int member_type_id, int mod, long where, int memberType ) { int memberID = AST.NULL; String insertSQL = "INSERT INTO idp_member " + "(class_id, name, type_id, modifier, location, member_type) VALUES (" + class_id + ", '" + memberName + "', " + member_type_id + ", " + mod + ", " + where + ", " + memberType + ")"; String selectSQL = "SELECT idp_member.id WHERE idp_member.class_id = " + class_id + " AND idp_member.name = '" + memberName + "'"; /////////////////////////////////////////////////////////////////////////////////////////////// try { stmt.execute( insertSQL ); stmt.executeQuery( selectSQL ); rs.close(); rs = stmt.getResultSet(); if ( rs.next() ) { memberID = rs.getInt( 1 ); rs.close(); } else { rs.close(); memberID = AST.NULL; } } catch( Exception e ) { try { if ( rs != null ) { rs.close(); } } catch ( Exception fe ) { System.out.println( fe.toString() ); } } /////////////////////////////////////////////////////////////////////////////////////////////// /** * Setup variables for the auto-generated dynamic function */ int block_key = getNewBlockKey( sk ); int block_type = AST_Block.METHOD; // Cannot embed a function inside a function sk.parent_function_node_key = AST.NULL; int node_key = method_node_key; String qualified_function_name = memberName; String is_static = ( member.isStatic() ? "Y" : "N" ); String is_anonymous = "N"; String is_constructor = ( member.isConstructor() ? "Y" : "N" ); String is_initializer = ( member.isInitializer() ? "Y" : "N" ); String is_final = ( member.isFinal() ? "Y" : "N" ); String is_synchronized = ( member.isSynchronized() ? "Y" : "N" ); String is_abstract = ( member.isAbstract() ? "Y" : "N" ); String is_native = ( member.isNative() ? "Y" : "N" ); String is_volatile = ( member.isVolatile() ? "Y" : "N" ); String is_transient = ( member.isTransient() ? "Y" : "N" ); int method_start_line = getLine( where ); int method_file_pos_offset = getOffset( where ); String function_protection = "package"; if ( member.isPublic() ) { function_protection = "public"; } else if ( member.isPrivate() ) { function_protection = "private"; } else if ( member.isProtected()) { function_protection = "protected"; } /////////////////////////////////////////////////////////////////////////////////////////////// /** * Add a AST_Function entry into the database */ try { AST_Function data = AST_Function.createFunction( block_key, block_type, sk.parent_package_node_key, sk.parent_class_node_key, sk.parent_function_node_key, sk.parent_block_node_key, sk.depth, node_key, qualified_function_name, qualified_return_type_node_key, is_static, is_anonymous, is_constructor, is_initializer, is_final, is_synchronized, is_abstract, is_native, is_volatile, is_transient, function_protection, class_id, method_start_line, method_file_pos_offset ); sk.parent_function_node_key = node_key; } catch ( Exception e ) { System.out.println( e.toString() ); } return memberID; } /////////////////////////////////////////////////////////////////////////////////////////////////// public void dbAddMethodArgument( SuperKey sk, int function_node_key, int function_param_node_key, LocalMember member, int memberID, int paraTypeID, String paraTypeName, int paraModifiers, long paraWhere, int paraNumber, String paraName, int paraReadCount, int paraWriteCount, String qualified_argument_type, int qualified_argument_type_node_key ) { String insertSQL = "INSERT INTO idp_member_argument " + "(member_id, type_id, modifier, location, name, readcount, writecount) VALUES (" + memberID + ", " + paraTypeID + ", " + paraModifiers + ", " + paraWhere + ", '" + paraName + "', " + paraReadCount + ", " + paraWriteCount + ")" ; try { stmt.addBatch( insertSQL ); } catch( Exception e ) { System.out.println( e.toString() ); } /////////////////////////////////////////////////////////////////////////////////////////////// try { stmt.executeBatch(); } catch( Exception e ) { System.out.println( e ); e.printStackTrace(); } /////////////////////////////////////////////////////////////////////////////////////////////// /** * Setup variables for the auto-generated dynamic function */ String argument_name = paraName; int argument_number = paraNumber; /* String qualified_argument_type = paraTypeName; int qualified_argument_type_node_key = paraTypeID; */ int expresion_key = argument_number; int top_node_key = function_node_key; int left_node_key = AST.NULL; int right_node_key = AST.NULL; int expression_type = AST_Expression.FUNCTION_PARAMETER; String expression_content = argument_name; int node_key = function_param_node_key; int function_call_node_key = function_node_key; String is_used = ( member.isUsed() ? "Y" : "N" ); String is_inlineable = ((member.getModifiers() & M_INLINEABLE) != 0 ? "Y" : "N" ); /** * Add a AST_Function_Call_Arguments entry into the database */ try { AST_Function_Call_Arguments data = AST_Function_Call_Arguments.createFunctionCallArguments( expresion_key, expression_type, expression_content, top_node_key, left_node_key, right_node_key, node_key, function_call_node_key, argument_number, argument_name, qualified_argument_type, qualified_argument_type_node_key, is_used, is_inlineable ); } catch ( Exception e ) { System.out.println( e.toString() ); } } /////////////////////////////////////////////////////////////////////////////////////////////////// public void dbAddMethodException( SuperKey sk, int node_key, int throw_node_key, String throw_qualified_class_name, int memberID, int expTypeID, long where ) { String insertSQL = "INSERT INTO idp_member_exception " + "(member_id, type_id, location) VALUES (" + memberID + ", " + expTypeID + ", " + where + ")" ; try { stmt.addBatch( insertSQL ); } catch( Exception e ) { System.out.println( e.toString() ); } /////////////////////////////////////////////////////////////////////////////////////////////// try { stmt.executeBatch(); } catch( Exception e ) { System.out.println( e ); e.printStackTrace(); } /////////////////////////////////////////////////////////////////////////////////////////////// /** * Setup variables for the auto-generated dynamic function */ int member_id = memberID; int exp_type_id = expTypeID; int throw_start_line = getLine( where ); int throw_file_pos_offset = getOffset( where ); /** * Add a AST_Function_Throw entry into the database */ try { AST_Function_Throw data = AST_Function_Throw.createFunctionThrow( node_key, throw_node_key, throw_qualified_class_name, member_id, exp_type_id, throw_start_line, throw_file_pos_offset ); } catch ( Exception e ) { System.out.println( e.toString() ); } } /////////////////////////////////////////////////////////////////////////////////////////////////// public int dbDumpBody( IdpNode root, int memberID ) { try { dbUpdateBody( root, memberID ); } catch( Exception e ) { e.printStackTrace(); System.out.println( e ); } return memberID; } /////////////////////////////////////////////////////////////////////////////////////////////////// public void dbUpdateBody( IdpNode root, int memberID ) throws Exception { if ( root == null ) { return; } String updateSQL = "UPDATE idp_member SET body = ? WHERE id = " + memberID; java.sql.PreparedStatement prep = con.prepareStatement( updateSQL ); /////////////////////////////////////////////////////////////////////////////////////////////// java.io.File file = java.io.File.createTempFile( Integer.toString( memberID ), "idp" ); FileOutputStream fo = new FileOutputStream( file ); ObjectOutputStream so = new ObjectOutputStream( fo ); /////////////////////////////////////////////////////////////////////////////////////////////// // VERIFY // so.writeObject( root.toASTNode() ); so.flush(); so.close(); FileInputStream fi = new FileInputStream( file ); prep.setBinaryStream( 1, fi, ( int )file.length() ); prep.executeUpdate(); fi.close(); file.delete(); } /////////////////////////////////////////////////////////////////////////////////////////////////// public void dbInsertBody( IdpNode root, PreparedStatement prep, int memberID ) throws SQLException { String value = root.getValue(); if ( value == null ) { value = ""; } prep.setString( 1, root.getValue() ); prep.setInt( 2, root.getTag() ); prep.setLong( 3, root.where ); // VERIFY /* prep.setInt( 4, root.thisNumber ); prep.setInt( 5, root.parentNumber ); */ prep.executeUpdate(); for( int i = 0; i < root.getChildCount(); i++ ) { IdpNode aChild = ( IdpNode )root.getChildAt( i ); dbInsertBody( aChild, prep, memberID ); } } /////////////////////////////////////////////////////////////////////////////////////////////////// public int dbAddClassFieldMember( SuperKey sk, MemberDefinition m, Type type, int node_key, int classID, String memberName, int member_type_id, int mod, long where ) { /** * Save to database */ int memberID = AST.NULL; String insertSQL = "INSERT INTO idp_member " + "(class_id, name, type_id, modifier, location, member_type) VALUES (" + classID + ", '" + memberName + "', " + member_type_id + ", " + mod + ", " + where + ", " + MEMBER_TYPE_FIELD + ")"; String selectSQL = "SELECT idp_member.id WHERE idp_member.class_id = " + classID + " AND idp_member.name = '" + memberName + "'"; /////////////////////////////////////////////////////////////////////////////////////////////// try { stmt.execute( insertSQL ); stmt.executeQuery( selectSQL ); rs.close(); rs = stmt.getResultSet(); if ( rs.next() ) { memberID = rs.getInt( 1 ); rs.close(); } else { rs.close(); memberID = AST.NULL; } } catch( Exception e ) { try { if ( rs != null ) { rs.close(); } } catch ( Exception fe ) { System.out.println( fe.toString() ); } } /////////////////////////////////////////////////////////////////////////////////////////////// /// Variable class member declaration /////////////////////////////////////////////////////////////////////////////////////////////// int expresion_key = 0; int expression_type = AST_Expression.CLASS_MEMBER; String expression_content = memberName; int left_node_key = AST.NULL; int right_node_key = AST.NULL; /* int refer_node_key = AST.NULL; int args_node_key, int outer_args_node_key, int impl_node_key, int body_node_key, int array_node_key, int index_node_key, int cond_node_key, int inc_node_key, int final_body_node_key, int true_node_key, int false_node_key, int node_key */ /* String qualified_variable_name, String qualified_variable_type, int qualified_variable_type_node_key, String is_class_field, String is_local, String is_arguments, String is_static, String is_primitive, String variable_protection, String is_declared, String is_defined, String is_used, int number, int read_count, int write_count, int scope, int init_node_key */ try { /* AST_Variable data = AST_Variable.createVariable( expresion_key, expression_type, expression_content, left_node_key, right_node_key, refer_node_key, args_node_key, outer_args_node_key, impl_node_key, body_node_key, array_node_key, index_node_key, cond_node_key, inc_node_key, final_body_node_key, true_node_key, false_node_key, node_key, qualified_variable_name, qualified_variable_type, qualified_variable_type_node_key, is_class_field, is_local, is_arguments, is_static, is_primitive, variable_protection, is_declared, is_defined, is_used, number, read_count, write_count, scope, init_node_key ); */ } catch ( Exception e ) { System.out.println( e.toString() ); } /////////////////////////////////////////////////////////////////////////////////////////////// return memberID; } /** * Add a Concept_package entry into the database */ public AST_Package dbAddPackage( SuperKey sk, int package_node_key, Imports imports, IdpNode pkgChildNode ) { int pkg_block_key = getNewBlockKey( sk ); Identifier pkg_ident = imports.getCurrentPackage(); long pkg_where = imports.currentPackageWhere; int pkg_type = pkg_ident.getType(); int node_key = package_node_key; /** * Setup variables for the auto-generated dynamic function */ sk.block_key = pkg_block_key; int block_type = AST_Block.PACKAGE; sk.parent_package_node_key = AST.NULL; sk.parent_class_node_key = AST.NULL; sk.parent_function_node_key = AST.NULL; sk.parent_block_node_key = AST.NULL; sk.depth = 0; String qualified_package_name = pkg_ident.toString(); String unqualified_package_name = pkg_ident.getFlatName().toString(); /** * Add a AST_Package entry into the database */ try { AST_Package data = AST_Package.createPackage( sk.block_key, block_type, sk.parent_package_node_key, sk.parent_class_node_key, sk.parent_function_node_key, sk.parent_block_node_key, sk.depth, node_key, qualified_package_name ); // sk.block_key = block_key; sk.node_key = node_key; sk.parent_package_node_key = node_key; sk.parent_block_node_key = node_key; return data; } catch ( java.lang.Exception e ) { System.out.println( e.toString() ); } return null; } /////////////////////////////////////////////////////////////////////////////////////////////////// public AST_Import dbAddImport( SuperKey sk, int node_key, String import_name, String package_name, String is_wildcard ) { /** * Setup variables for the auto-generated dynamic function */ int target_node_key = AST.NULL; /** * Add a AST_Import entry into the database */ try { AST_Import data = AST_Import.createImport( node_key, target_node_key, import_name, package_name, is_wildcard ); return data; } catch ( java.lang.Exception e ) { System.out.println( e.toString() ); } return null; } /////////////////////////////////////////////////////////////////////////////////////////////////// public AST_Statement dbAddLabel( SuperKey sk, int node_key, int block_key, int index, String labelName ) { int statement_key = getNewStatementKey( sk ); int statement_type = AST_Statement.LABEL; int statement_index = index; String statement_content = labelName; String is_inside_function_impl = "X"; String is_begin_of_impl = "X"; String is_complex_statement = "X"; try { AST_Statement data = AST_Statement.createStatement( node_key, block_key, statement_key, statement_type, statement_index, statement_content, is_inside_function_impl, is_begin_of_impl, is_complex_statement ); return data; } catch( Exception e ) { System.out.println( e.toString() ); } return null; } /////////////////////////////////////////////////////////////////////////////////////////////////// public AST_Class_Inherit_Node dbAddInherit( SuperKey sk, int node_key, int inherit_node_key, String inherit_qualified_class_name, String is_interface, int class_id, int type_id, int type_node_key, long where ) { if ( is_interface.equals( "Y" ) ) { String insertSQL = "INSERT INTO idp_class_interface " + "(class_id, type_id, location) VALUES (" + class_id + ", " + type_id + ", " + where + ")" ; try { stmt.addBatch( insertSQL ); } catch( Exception e ) {} } /////////////////////////////////////////////////////////////////////////////////////////////// /** * Add a AST_Class_Inherit_Node entry into the database */ try { AST_Class_Inherit_Node data = AST_Class_Inherit_Node.createClassInheritNode( node_key, inherit_node_key, inherit_qualified_class_name, is_interface, class_id, type_id, type_node_key, getLine( where ), getOffset( where ) ); return data; } catch( Exception e ) { System.out.println( e.toString() ); } /////////////////////////////////////////////////////////////////////////////////////////////// return null; } /////////////////////////////////////////////////////////////////////////////////////////////////// public AST_Expression dbAddExpression( SuperKey sk, int node_key, int expresion_key, int expression_type, String expression_content, int left_node_key, int right_node_key ) { int top_node_key = AST.NULL; try { AST_Expression data = AST_Expression.createExpression( node_key, expresion_key, expression_type, expression_content, top_node_key, left_node_key, right_node_key ); return data; } catch( Exception e ) { System.out.println( e.toString() ); } return null; } } // End of AST.java