[Pydev-cvs] org.python.pydev.parser/src/org/python/pydev/parser/fastparser FastDefinitionsParser.j
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-07-06 13:10:35
|
Update of /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/fastparser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2497/src/org/python/pydev/parser/fastparser Modified Files: FastDefinitionsParser.java Log Message: Improved attribute recognition. Index: FastDefinitionsParser.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.parser/src/org/python/pydev/parser/fastparser/FastDefinitionsParser.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FastDefinitionsParser.java 5 Jul 2008 21:53:01 -0000 1.4 --- FastDefinitionsParser.java 6 Jul 2008 13:10:42 -0000 1.5 *************** *** 113,116 **** --- 113,120 ---- handleNewLine(); } + //in the 1st attempt to handle the 1st line, if it had nothing we could actually go backward 1 char + if(currIndex < 0){ + currIndex=0; + } for (;currIndex < length; currIndex++, col++) { *************** *** 152,156 **** //after a comment, we'll always be in a new line - currIndex++; handleNewLine(); --- 156,159 ---- *************** *** 204,208 **** Assign assign = new Assign(targets, null); ! assign.beginColumn = this.col; assign.beginLine = this.row; addToPertinentScope(assign); --- 207,211 ---- Assign assign = new Assign(targets, null); ! assign.beginColumn = this.firstCharCol; assign.beginLine = this.row; addToPertinentScope(assign); *************** *** 213,217 **** exprType[] targets = new exprType[]{name}; Assign assign = new Assign(targets, null); ! assign.beginColumn = this.col; assign.beginLine = this.row; addToPertinentScope(assign); --- 216,220 ---- exprType[] targets = new exprType[]{name}; Assign assign = new Assign(targets, null); ! assign.beginColumn = this.firstCharCol; assign.beginLine = this.row; addToPertinentScope(assign); *************** *** 246,253 **** lineBuffer.clear(); char c = cs[currIndex]; - boolean walkedIndex = false; while(currIndex < length-1 && Character.isWhitespace(c) && c != '\r' && c != '\n'){ - walkedIndex = true; currIndex ++; col++; --- 249,254 ---- *************** *** 270,276 **** startMethod(getNextIdentifier(c), row, startMethodCol); } ! if(walkedIndex){ ! currIndex --; ! } firstCharCol = col; } --- 271,275 ---- startMethod(getNextIdentifier(c), row, startMethodCol); } ! currIndex --; firstCharCol = col; } *************** *** 377,380 **** --- 376,380 ---- }else if (newStmt instanceof Assign){ Assign assign = (Assign) newStmt; + exprType target = assign.targets[0]; //an assign could be in a method or in a class depending on where we're right now... *************** *** 382,387 **** if(size > 0){ stmtType existing = peek.get(size-1); ! if(existing.beginColumn < newStmt.beginColumn){ ! exprType target = assign.targets[0]; //add the assign to the correct place if(existing instanceof FunctionDef){ --- 382,386 ---- if(size > 0){ stmtType existing = peek.get(size-1); ! if(existing.beginColumn < assign.beginColumn){ //add the assign to the correct place if(existing instanceof FunctionDef){ *************** *** 389,412 **** if(target instanceof Attribute){ ! //if it's an attribute at this point, it'll always start with self! ! if(functionDef.body == null){ ! if(functionDef.specialsAfter == null){ ! functionDef.specialsAfter = new ArrayList<Object>(); ! } ! functionDef.body = new stmtType[10]; ! functionDef.body[0] = newStmt; ! functionDef.specialsAfter.add(1); //real len ! }else{ ! //already exists... let's add it... as it's an array, we may have to reallocate it ! Integer currLen = (Integer) functionDef.specialsAfter.get(0); ! currLen += 1; ! functionDef.specialsAfter.set(0, currLen); ! if(functionDef.body.length < currLen){ ! stmtType[] newBody = new stmtType[functionDef.body.length*2]; ! System.arraycopy(functionDef.body, 0, newBody, 0, functionDef.body.length); ! functionDef.body = newBody; ! } ! functionDef.body[currLen-1] = newStmt; ! } } return; --- 388,392 ---- if(target instanceof Attribute){ ! addAssignToFunctionDef(assign, functionDef); } return; *************** *** 415,418 **** --- 395,402 ---- } + //if it still hasn't returned and it's a name, add it to the global scope. + if(target instanceof Name){ + + } } peek.add(newStmt); *************** *** 425,428 **** --- 409,442 ---- this.body.add(newStmt); } + + + /** + * Adds an assign statement to the given function definition. + * + * @param assign the assign to be added + * @param functionDef the function definition where it should be added + */ + private void addAssignToFunctionDef(Assign assign, FunctionDef functionDef) { + //if it's an attribute at this point, it'll always start with self! + if(functionDef.body == null){ + if(functionDef.specialsAfter == null){ + functionDef.specialsAfter = new ArrayList<Object>(); + } + functionDef.body = new stmtType[10]; + functionDef.body[0] = assign; + functionDef.specialsAfter.add(1); //real len + }else{ + //already exists... let's add it... as it's an array, we may have to reallocate it + Integer currLen = (Integer) functionDef.specialsAfter.get(0); + currLen += 1; + functionDef.specialsAfter.set(0, currLen); + if(functionDef.body.length < currLen){ + stmtType[] newBody = new stmtType[functionDef.body.length*2]; + System.arraycopy(functionDef.body, 0, newBody, 0, functionDef.body.length); + functionDef.body = newBody; + } + functionDef.body[currLen-1] = assign; + } + } |