Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse type vars (work in progress).
Browse files Browse the repository at this point in the history
fabioz committed Oct 19, 2024
1 parent 58d774c commit bd37aa5
Showing 40 changed files with 5,885 additions and 2,250 deletions.
Original file line number Diff line number Diff line change
@@ -14,12 +14,12 @@
* Contributors:
* Fabio Zadrozny <[email protected]> - 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;
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;
@@ -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
@@ -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);
@@ -316,6 +319,9 @@ public Object visitFunctionDef(FunctionDef node) throws Exception {
@Override
public Object visitClassDef(ClassDef node) throws Exception {
visit(node.name);
if (node.type_params != null) {
node.type_params.accept(this);
}
visit(node.bases);
visit(node.body);
extendLast(node);
Original file line number Diff line number Diff line change
@@ -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;

Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);

This file was deleted.

Loading

0 comments on commit bd37aa5

Please sign in to comment.