Skip to content

Commit c397f70

Browse files
committed
Python: Add automatically generated files
For these, I opted for a placement that would cause as few changes to the dbscheme as possible. This puts the new `type_parameters` fields as the last field on function and class definitions.
1 parent 4b9430d commit c397f70

File tree

2 files changed

+139
-4
lines changed

2 files changed

+139
-4
lines changed

python/ql/lib/semmle/python/AstGenerated.qll

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,15 @@ class ClassExpr_ extends @py_ClassExpr, Expr {
285285
/** Gets the class scope of this class definition. */
286286
Class getInnerScope() { py_Classes(result, this) }
287287

288+
/** Gets the type parameters of this class definition. */
289+
TypeParameterList getTypeParameters() { py_type_parameter_lists(result, this) }
290+
291+
/** Gets the nth type parameter of this class definition. */
292+
TypeParameter getTypeParameter(int index) { result = this.getTypeParameters().getItem(index) }
293+
294+
/** Gets a type parameter of this class definition. */
295+
TypeParameter getATypeParameter() { result = this.getTypeParameters().getAnItem() }
296+
288297
override string toString() { result = "ClassExpr" }
289298
}
290299

@@ -554,6 +563,15 @@ class Function_ extends @py_Function {
554563
/** Whether the async property of this function is true. */
555564
predicate isAsync() { py_bools(this, 6) }
556565

566+
/** Gets the type parameters of this function. */
567+
TypeParameterList getTypeParameters() { py_type_parameter_lists(result, this) }
568+
569+
/** Gets the nth type parameter of this function. */
570+
TypeParameter getTypeParameter(int index) { result = this.getTypeParameters().getItem(index) }
571+
572+
/** Gets a type parameter of this function. */
573+
TypeParameter getATypeParameter() { result = this.getTypeParameters().getAnItem() }
574+
557575
/** Gets a parent of this function */
558576
FunctionParent getParent() { py_Functions(this, result) }
559577

@@ -1103,6 +1121,14 @@ class Param_ extends @py_Param, ExprContext {
11031121
override string toString() { result = "Param" }
11041122
}
11051123

1124+
/** INTERNAL: See the class `ParamSpec` for further information. */
1125+
class ParamSpec_ extends @py_ParamSpec, TypeParameter {
1126+
/** Gets the name of this parameter spec. */
1127+
Expr getName() { py_exprs(result, _, this, 1) }
1128+
1129+
override string toString() { result = "ParamSpec" }
1130+
}
1131+
11061132
/** INTERNAL: See the class `Pass` for further information. */
11071133
class Pass_ extends @py_Pass, Stmt {
11081134
override string toString() { result = "Pass" }
@@ -1412,6 +1438,45 @@ class Tuple_ extends @py_Tuple, Expr {
14121438
override string toString() { result = "Tuple" }
14131439
}
14141440

1441+
/** INTERNAL: See the class `TypeAlias` for further information. */
1442+
class TypeAlias_ extends @py_TypeAlias, Stmt {
1443+
/** Gets the name of this type alias. */
1444+
Expr getName() { py_exprs(result, _, this, 1) }
1445+
1446+
/** Gets the type_parameters of this type alias. */
1447+
TypeParameterList getTypeParameters() { py_type_parameter_lists(result, this) }
1448+
1449+
/** Gets the nth type_parameter of this type alias. */
1450+
TypeParameter getTypeParameter(int index) { result = this.getTypeParameters().getItem(index) }
1451+
1452+
/** Gets a type_parameter of this type alias. */
1453+
TypeParameter getATypeParameter() { result = this.getTypeParameters().getAnItem() }
1454+
1455+
/** Gets the value of this type alias. */
1456+
Expr getValue() { py_exprs(result, _, this, 3) }
1457+
1458+
override string toString() { result = "TypeAlias" }
1459+
}
1460+
1461+
/** INTERNAL: See the class `TypeVar` for further information. */
1462+
class TypeVar_ extends @py_TypeVar, TypeParameter {
1463+
/** Gets the name of this type variable. */
1464+
Expr getName() { py_exprs(result, _, this, 1) }
1465+
1466+
/** Gets the bound of this type variable. */
1467+
Expr getBound() { py_exprs(result, _, this, 2) }
1468+
1469+
override string toString() { result = "TypeVar" }
1470+
}
1471+
1472+
/** INTERNAL: See the class `TypeVarTuple` for further information. */
1473+
class TypeVarTuple_ extends @py_TypeVarTuple, TypeParameter {
1474+
/** Gets the name of this type variable tuple. */
1475+
Expr getName() { py_exprs(result, _, this, 1) }
1476+
1477+
override string toString() { result = "TypeVarTuple" }
1478+
}
1479+
14151480
/** INTERNAL: See the class `UAdd` for further information. */
14161481
class UAdd_ extends @py_UAdd, Unaryop {
14171482
override string toString() { result = "UAdd" }
@@ -1908,6 +1973,39 @@ class StrParent_ extends @py_str_parent {
19081973
string toString() { result = "StrParent" }
19091974
}
19101975

1976+
/** INTERNAL: See the class `TypeParameter` for further information. */
1977+
class TypeParameter_ extends @py_type_parameter {
1978+
/** Gets the location of this type parameter. */
1979+
Location getLocation() { py_locations(result, this) }
1980+
1981+
/** Gets a parent of this type parameter */
1982+
TypeParameterList getParent() { py_type_parameters(this, _, result, _) }
1983+
1984+
/** Gets a textual representation of this element. */
1985+
string toString() { result = "TypeParameter" }
1986+
}
1987+
1988+
/** INTERNAL: See the class `TypeParameterList` for further information. */
1989+
class TypeParameterList_ extends @py_type_parameter_list {
1990+
/** Gets a parent of this type parameter list */
1991+
TypeParameterListParent getParent() { py_type_parameter_lists(this, result) }
1992+
1993+
/** Gets an item of this type parameter list */
1994+
TypeParameter getAnItem() { py_type_parameters(result, _, this, _) }
1995+
1996+
/** Gets the nth item of this type parameter list */
1997+
TypeParameter getItem(int index) { py_type_parameters(result, _, this, index) }
1998+
1999+
/** Gets a textual representation of this element. */
2000+
string toString() { result = "TypeParameterList" }
2001+
}
2002+
2003+
/** INTERNAL: See the class `TypeParameterListParent` for further information. */
2004+
class TypeParameterListParent_ extends @py_type_parameter_list_parent {
2005+
/** Gets a textual representation of this element. */
2006+
string toString() { result = "TypeParameterListParent" }
2007+
}
2008+
19112009
/** INTERNAL: See the class `Unaryop` for further information. */
19122010
class Unaryop_ extends @py_unaryop {
19132011
/** Gets a parent of this unary operation */

python/ql/lib/semmlecode.python.dbscheme

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ py_extracted_version(int module : @py_Module ref,
388388
/* <Field> ClassExpr.bases = 3, expr_list */
389389
/* <Field> ClassExpr.keywords = 4, dict_item_list */
390390
/* <Field> ClassExpr.inner_scope = 5, Class */
391+
/* <Field> ClassExpr.type_parameters = 6, type_parameter_list */
391392

392393
/* <Field> Compare.location = 0, location */
393394
/* <Field> Compare.parenthesised = 1, bool */
@@ -458,6 +459,7 @@ py_extracted_version(int module : @py_Module ref,
458459
/* <Field> Function.kwarg = 4, expr */
459460
/* <Field> Function.body = 5, stmt_list */
460461
/* <Field> Function.is_async = 6, bool */
462+
/* <Field> Function.type_parameters = 7, type_parameter_list */
461463
/* <Parent> Function = FunctionParent */
462464

463465
/* <Field> FunctionExpr.location = 0, location */
@@ -613,6 +615,9 @@ py_extracted_version(int module : @py_Module ref,
613615
/* <Field> Num.n = 2, number */
614616
/* <Field> Num.text = 3, number */
615617

618+
/* <Field> ParamSpec.location = 0, location */
619+
/* <Field> ParamSpec.name = 1, expr */
620+
616621
/* <Field> Pass.location = 0, location */
617622

618623
/* <Field> PlaceHolder.location = 0, location */
@@ -702,6 +707,18 @@ py_extracted_version(int module : @py_Module ref,
702707
/* <Field> Tuple.ctx = 3, expr_context */
703708
/* <Parent> Tuple = ParameterList */
704709

710+
/* <Field> TypeAlias.location = 0, location */
711+
/* <Field> TypeAlias.name = 1, expr */
712+
/* <Field> TypeAlias.type_parameters = 2, type_parameter_list */
713+
/* <Field> TypeAlias.value = 3, expr */
714+
715+
/* <Field> TypeVar.location = 0, location */
716+
/* <Field> TypeVar.name = 1, expr */
717+
/* <Field> TypeVar.bound = 2, expr */
718+
719+
/* <Field> TypeVarTuple.location = 0, location */
720+
/* <Field> TypeVarTuple.name = 1, expr */
721+
705722
/* <Field> UnaryExpr.location = 0, location */
706723
/* <Field> UnaryExpr.parenthesised = 1, bool */
707724
/* <Field> UnaryExpr.op = 2, unaryop */
@@ -778,6 +795,10 @@ py_extracted_version(int module : @py_Module ref,
778795
/* <Parent> StmtList = StmtListParent */
779796
/* <Parent> string = StrParent */
780797
/* <Parent> StringList = StrListParent */
798+
799+
/* <Field> TypeParameter.location = 0, location */
800+
/* <Parent> TypeParameter = TypeParameterList */
801+
/* <Parent> TypeParameterList = TypeParameterListParent */
781802
/* <Parent> Unaryop = UnaryExpr */
782803
/* <Parent> Variable = VariableParent */
783804
py_Classes(unique int id : @py_Class,
@@ -894,6 +915,14 @@ py_strs(varchar(1) id : string ref,
894915
py_str_lists(unique int id : @py_str_list,
895916
unique int parent : @py_str_list_parent ref);
896917

918+
py_type_parameters(unique int id : @py_type_parameter,
919+
int kind: int ref,
920+
int parent : @py_type_parameter_list ref,
921+
int idx : int ref);
922+
923+
py_type_parameter_lists(unique int id : @py_type_parameter_list,
924+
unique int parent : @py_type_parameter_list_parent ref);
925+
897926
py_unaryops(unique int id : @py_unaryop,
898927
int kind: int ref,
899928
unique int parent : @py_UnaryExpr ref);
@@ -1029,7 +1058,13 @@ case @py_stmt.kind of
10291058
| 23 = @py_While
10301059
| 24 = @py_With
10311060
| 25 = @py_TemplateWrite
1032-
| 26 = @py_AnnAssign;
1061+
| 26 = @py_AnnAssign
1062+
| 27 = @py_TypeAlias;
1063+
1064+
case @py_type_parameter.kind of
1065+
0 = @py_ParamSpec
1066+
| 1 = @py_TypeVar
1067+
| 2 = @py_TypeVarTuple;
10331068

10341069
case @py_unaryop.kind of
10351070
0 = @py_Invert
@@ -1043,7 +1078,7 @@ case @py_unaryop.kind of
10431078

10441079
@py_arguments_parent = @py_FunctionExpr | @py_Lambda;
10451080

1046-
@py_ast_node = @py_Class | @py_Function | @py_Module | @py_StringPart | @py_comprehension | @py_dict_item | @py_expr | @py_pattern | @py_stmt;
1081+
@py_ast_node = @py_Class | @py_Function | @py_Module | @py_StringPart | @py_comprehension | @py_dict_item | @py_expr | @py_pattern | @py_stmt | @py_type_parameter;
10471082

10481083
@py_bool_parent = @py_For | @py_Function | @py_Print | @py_With | @py_expr | @py_pattern;
10491084

@@ -1055,9 +1090,9 @@ case @py_unaryop.kind of
10551090

10561091
@py_expr_or_stmt = @py_expr | @py_stmt;
10571092

1058-
@py_expr_parent = @py_AnnAssign | @py_Assert | @py_Assign | @py_AssignExpr | @py_Attribute | @py_AugAssign | @py_Await | @py_BinaryExpr | @py_Call | @py_Case | @py_Compare | @py_DictComp | @py_DictUnpacking | @py_ExceptGroupStmt | @py_ExceptStmt | @py_Exec | @py_Expr_stmt | @py_Filter | @py_For | @py_FormattedValue | @py_Function | @py_FunctionExpr | @py_GeneratorExp | @py_Guard | @py_If | @py_IfExp | @py_ImportMember | @py_ImportStar | @py_KeyValuePair | @py_ListComp | @py_MatchAsPattern | @py_MatchCapturePattern | @py_MatchClassPattern | @py_MatchKeywordPattern | @py_MatchLiteralPattern | @py_MatchStmt | @py_MatchValuePattern | @py_Print | @py_Raise | @py_Repr | @py_Return | @py_SetComp | @py_Slice | @py_Starred | @py_Subscript | @py_TemplateDottedNotation | @py_TemplateWrite | @py_UnaryExpr | @py_While | @py_With | @py_Yield | @py_YieldFrom | @py_alias | @py_arguments | @py_comprehension | @py_expr_list | @py_keyword | @py_parameter_list;
1093+
@py_expr_parent = @py_AnnAssign | @py_Assert | @py_Assign | @py_AssignExpr | @py_Attribute | @py_AugAssign | @py_Await | @py_BinaryExpr | @py_Call | @py_Case | @py_Compare | @py_DictComp | @py_DictUnpacking | @py_ExceptGroupStmt | @py_ExceptStmt | @py_Exec | @py_Expr_stmt | @py_Filter | @py_For | @py_FormattedValue | @py_Function | @py_FunctionExpr | @py_GeneratorExp | @py_Guard | @py_If | @py_IfExp | @py_ImportMember | @py_ImportStar | @py_KeyValuePair | @py_ListComp | @py_MatchAsPattern | @py_MatchCapturePattern | @py_MatchClassPattern | @py_MatchKeywordPattern | @py_MatchLiteralPattern | @py_MatchStmt | @py_MatchValuePattern | @py_ParamSpec | @py_Print | @py_Raise | @py_Repr | @py_Return | @py_SetComp | @py_Slice | @py_Starred | @py_Subscript | @py_TemplateDottedNotation | @py_TemplateWrite | @py_TypeAlias | @py_TypeVar | @py_TypeVarTuple | @py_UnaryExpr | @py_While | @py_With | @py_Yield | @py_YieldFrom | @py_alias | @py_arguments | @py_comprehension | @py_expr_list | @py_keyword | @py_parameter_list;
10591094

1060-
@py_location_parent = @py_DictUnpacking | @py_KeyValuePair | @py_StringPart | @py_comprehension | @py_expr | @py_keyword | @py_pattern | @py_stmt;
1095+
@py_location_parent = @py_DictUnpacking | @py_KeyValuePair | @py_StringPart | @py_comprehension | @py_expr | @py_keyword | @py_pattern | @py_stmt | @py_type_parameter;
10611096

10621097
@py_parameter = @py_Name | @py_Tuple;
10631098

@@ -1073,6 +1108,8 @@ case @py_unaryop.kind of
10731108

10741109
@py_str_parent = @py_Attribute | @py_Class | @py_ClassExpr | @py_FormattedValue | @py_Function | @py_FunctionExpr | @py_ImportExpr | @py_ImportMember | @py_Module | @py_SpecialOperation | @py_Str | @py_StringPart | @py_TemplateDottedNotation | @py_keyword | @py_str_list;
10751110

1111+
@py_type_parameter_list_parent = @py_ClassExpr | @py_Function | @py_TypeAlias;
1112+
10761113
@py_variable_parent = @py_Name | @py_PlaceHolder;
10771114

10781115

0 commit comments

Comments
 (0)