Skip to content

Commit

Permalink
Parse type vars (work in progress).
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Oct 19, 2024
1 parent 58d774c commit 7f33e47
Show file tree
Hide file tree
Showing 40 changed files with 5,793 additions and 2,223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* Contributors:
* Fabio Zadrozny <fabiofz@gmail.com> - initial implementation
******************************************************************************/
/*
/*
* Copyright (C) 2006, 2007 Dennis Hunziker, Ueli Kistler
* Copyright (C) 2007 Reto Schuettel, Robin Stocker
*
* IFS Institute for Software, HSR Rapperswil, Switzerland
*
*
*/

package org.python.pydev.ast.adapters.context;
Expand Down Expand Up @@ -162,6 +162,9 @@ public void traverse(FunctionDef node) throws Exception {
visit(node.decs);
}
visit(node.name);
if (node.type_params != null) {
visit(node.type_params);
}
visit(node.args);
visit(node.body);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.python.pydev.parser.jython.ast.NamedExpr;
import org.python.pydev.parser.jython.ast.NonLocal;
import org.python.pydev.parser.jython.ast.Num;
import org.python.pydev.parser.jython.ast.ParamSpec;
import org.python.pydev.parser.jython.ast.Pass;
import org.python.pydev.parser.jython.ast.Print;
import org.python.pydev.parser.jython.ast.Raise;
Expand All @@ -76,6 +77,9 @@
import org.python.pydev.parser.jython.ast.Suite;
import org.python.pydev.parser.jython.ast.TryExcept;
import org.python.pydev.parser.jython.ast.TryFinally;
import org.python.pydev.parser.jython.ast.TypeParamsSuite;
import org.python.pydev.parser.jython.ast.TypeVar;
import org.python.pydev.parser.jython.ast.TypeVarTuple;
import org.python.pydev.parser.jython.ast.UnaryOp;
import org.python.pydev.parser.jython.ast.VisitorIF;
import org.python.pydev.parser.jython.ast.While;
Expand Down Expand Up @@ -846,4 +850,40 @@ public Object visitMatchKeyVal(MatchKeyVal node) throws Exception {
}
return null;
}

@Override
public Object visitTypeVar(TypeVar node) throws Exception {
boolean ret = unhandled_node(node);
if (ret) {
traverse(node);
}
return null;
}

@Override
public Object visitParamSpec(ParamSpec node) throws Exception {
boolean ret = unhandled_node(node);
if (ret) {
traverse(node);
}
return null;
}

@Override
public Object visitTypeVarTuple(TypeVarTuple node) throws Exception {
boolean ret = unhandled_node(node);
if (ret) {
traverse(node);
}
return null;
}

@Override
public Object visitTypeParamsSuite(TypeParamsSuite node) throws Exception {
boolean ret = unhandled_node(node);
if (ret) {
traverse(node);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ private Object visitAliasType(aliasType node) throws Exception {
@Override
public Object visitFunctionDef(FunctionDef node) throws Exception {
visit(node.name);
if (node.type_params != null) {
visit(node.type_params);
}
visit(node.args);
visit(node.body);
extendLast(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ private void startClass(String name, int startClassRow, int startClassCol, int n
nameTok.beginLine = startClassRow;
nameTok.beginColumn = nameCol;

ClassDef classDef = new ClassDef(nameTok, null, null, null, null, null, null);
ClassDef classDef = new ClassDef(nameTok, null, null, null, null, null, null,
null);
classDef.beginLine = startClassRow;
classDef.beginColumn = startClassCol;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ private FunctionDef createFunctionDef(int lastReturnedLine, NameTok nameTok, int
}

private ClassDef createClassDef(int lastReturnedLine, NameTok nameTok, int matchedCol) {
ClassDef classDef = new ClassDef(nameTok, PyAstFactory.EMPTY_EXPR_TYPE, PyAstFactory.EMPTY_STMT_TYPE, null,
ClassDef classDef = new ClassDef(nameTok, null, PyAstFactory.EMPTY_EXPR_TYPE,
PyAstFactory.EMPTY_STMT_TYPE, null,
null, null,
null);
classDef.beginLine = lastReturnedLine + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public final SimpleNode onCloseNode(SimpleNode n, int arity) throws Exception {
exprType[] bases = makeExprs(nodeArity);
nameTok = makeNameTok(NameTok.ClassName);
//decorator is always null at this point... it's decorated later on
ClassDef classDef = new ClassDef(nameTok, bases, body, null,
ClassDef classDef = new ClassDef(nameTok, null, bases, body, null,
classDefKeywords.toArray(new keywordType[classDefKeywords.size()]), starargs, kwargs);

addSpecialsAndClearOriginal(suite, classDef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public final SimpleNode onCloseNode(SimpleNode n, int arity) throws Exception {
exprType[] bases = makeExprs(nodeArity);
nameTok = makeNameTok(NameTok.ClassName);
//decorator is always null at this point... it's decorated later on
ClassDef classDef = new ClassDef(nameTok, bases, body, null,
ClassDef classDef = new ClassDef(nameTok, null, bases, body, null,
classDefKeywords.toArray(new keywordType[classDefKeywords.size()]), starargs, kwargs);

addSpecialsAndClearOriginal(suite, classDef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public final SimpleNode onCloseNode(SimpleNode n, int arity) throws Exception {
exprType[] bases = makeExprs(nodeArity);
nameTok = makeNameTok(NameTok.ClassName);
//decorator is always null at this point... it's decorated later on
ClassDef classDef = new ClassDef(nameTok, bases, body, null,
ClassDef classDef = new ClassDef(nameTok, null, bases, body, null,
classDefKeywords.toArray(new keywordType[classDefKeywords.size()]), starargs, kwargs);

addSpecialsAndClearOriginal(suite, classDef);
Expand Down

This file was deleted.

Loading

0 comments on commit 7f33e47

Please sign in to comment.