25
25
26
26
static PySTEntryObject *
27
27
ste_new (struct symtable * st , identifier name , _Py_block_ty block ,
28
- void * key , int lineno )
28
+ void * key , int lineno , int col_offset )
29
29
{
30
30
PySTEntryObject * ste = NULL ;
31
31
PyObject * k ;
@@ -65,7 +65,9 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
65
65
ste -> ste_varargs = 0 ;
66
66
ste -> ste_varkeywords = 0 ;
67
67
ste -> ste_opt_lineno = 0 ;
68
+ ste -> ste_opt_col_offset = 0 ;
68
69
ste -> ste_lineno = lineno ;
70
+ ste -> ste_col_offset = col_offset ;
69
71
70
72
if (st -> st_cur != NULL &&
71
73
(st -> st_cur -> ste_nested ||
@@ -163,7 +165,8 @@ PyTypeObject PySTEntry_Type = {
163
165
static int symtable_analyze (struct symtable * st );
164
166
static int symtable_warn (struct symtable * st , char * msg , int lineno );
165
167
static int symtable_enter_block (struct symtable * st , identifier name ,
166
- _Py_block_ty block , void * ast , int lineno );
168
+ _Py_block_ty block , void * ast , int lineno ,
169
+ int col_offset );
167
170
static int symtable_exit_block (struct symtable * st , void * ast );
168
171
static int symtable_visit_stmt (struct symtable * st , stmt_ty s );
169
172
static int symtable_visit_expr (struct symtable * st , expr_ty s );
@@ -230,7 +233,7 @@ PySymtable_Build(mod_ty mod, const char *filename, PyFutureFeatures *future)
230
233
st -> st_future = future ;
231
234
/* Make the initial symbol information gathering pass */
232
235
if (!GET_IDENTIFIER (top ) ||
233
- !symtable_enter_block (st , top , ModuleBlock , (void * )mod , 0 )) {
236
+ !symtable_enter_block (st , top , ModuleBlock , (void * )mod , 0 , 0 )) {
234
237
PySymtable_Free (st );
235
238
return NULL ;
236
239
}
@@ -390,8 +393,8 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
390
393
PyErr_Format (PyExc_SyntaxError ,
391
394
"name '%U' is parameter and global" ,
392
395
name );
393
- PyErr_SyntaxLocation (ste -> ste_table -> st_filename ,
394
- ste -> ste_lineno );
396
+ PyErr_SyntaxLocationEx (ste -> ste_table -> st_filename ,
397
+ ste -> ste_lineno , ste -> ste_col_offset );
395
398
396
399
return 0 ;
397
400
}
@@ -534,8 +537,8 @@ check_unoptimized(const PySTEntryObject* ste) {
534
537
break ;
535
538
}
536
539
537
- PyErr_SyntaxLocation (ste -> ste_table -> st_filename ,
538
- ste -> ste_opt_lineno );
540
+ PyErr_SyntaxLocationEx (ste -> ste_table -> st_filename , ste -> ste_opt_lineno ,
541
+ ste -> ste_opt_col_offset );
539
542
return 0 ;
540
543
}
541
544
@@ -873,8 +876,8 @@ symtable_warn(struct symtable *st, char *msg, int lineno)
873
876
lineno , NULL , NULL ) < 0 ) {
874
877
if (PyErr_ExceptionMatches (PyExc_SyntaxWarning )) {
875
878
PyErr_SetString (PyExc_SyntaxError , msg );
876
- PyErr_SyntaxLocation (st -> st_filename ,
877
- st -> st_cur -> ste_lineno );
879
+ PyErr_SyntaxLocationEx (st -> st_filename , st -> st_cur -> ste_lineno ,
880
+ st -> st_cur -> ste_col_offset );
878
881
}
879
882
return 0 ;
880
883
}
@@ -907,7 +910,7 @@ symtable_exit_block(struct symtable *st, void *ast)
907
910
908
911
static int
909
912
symtable_enter_block (struct symtable * st , identifier name , _Py_block_ty block ,
910
- void * ast , int lineno )
913
+ void * ast , int lineno , int col_offset )
911
914
{
912
915
PySTEntryObject * prev = NULL ;
913
916
@@ -918,7 +921,7 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
918
921
}
919
922
Py_DECREF (st -> st_cur );
920
923
}
921
- st -> st_cur = ste_new (st , name , block , ast , lineno );
924
+ st -> st_cur = ste_new (st , name , block , ast , lineno , col_offset );
922
925
if (st -> st_cur == NULL )
923
926
return 0 ;
924
927
if (name == GET_IDENTIFIER (top ))
@@ -963,8 +966,9 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag)
963
966
if ((flag & DEF_PARAM ) && (val & DEF_PARAM )) {
964
967
/* Is it better to use 'mangled' or 'name' here? */
965
968
PyErr_Format (PyExc_SyntaxError , DUPLICATE_ARGUMENT , name );
966
- PyErr_SyntaxLocation (st -> st_filename ,
967
- st -> st_cur -> ste_lineno );
969
+ PyErr_SyntaxLocationEx (st -> st_filename ,
970
+ st -> st_cur -> ste_lineno ,
971
+ st -> st_cur -> ste_col_offset );
968
972
goto error ;
969
973
}
970
974
val |= flag ;
@@ -1114,7 +1118,8 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
1114
1118
if (s -> v .FunctionDef .decorator_list )
1115
1119
VISIT_SEQ (st , expr , s -> v .FunctionDef .decorator_list );
1116
1120
if (!symtable_enter_block (st , s -> v .FunctionDef .name ,
1117
- FunctionBlock , (void * )s , s -> lineno ))
1121
+ FunctionBlock , (void * )s , s -> lineno ,
1122
+ s -> col_offset ))
1118
1123
return 0 ;
1119
1124
VISIT_IN_BLOCK (st , arguments , s -> v .FunctionDef .args , s );
1120
1125
VISIT_SEQ_IN_BLOCK (st , stmt , s -> v .FunctionDef .body , s );
@@ -1134,7 +1139,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
1134
1139
if (s -> v .ClassDef .decorator_list )
1135
1140
VISIT_SEQ (st , expr , s -> v .ClassDef .decorator_list );
1136
1141
if (!symtable_enter_block (st , s -> v .ClassDef .name , ClassBlock ,
1137
- (void * )s , s -> lineno ))
1142
+ (void * )s , s -> lineno , s -> col_offset ))
1138
1143
return 0 ;
1139
1144
if (!GET_IDENTIFIER (__class__ ) ||
1140
1145
!symtable_add_def (st , __class__ , DEF_LOCAL ) ||
@@ -1158,8 +1163,9 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
1158
1163
if (st -> st_cur -> ste_generator ) {
1159
1164
PyErr_SetString (PyExc_SyntaxError ,
1160
1165
RETURN_VAL_IN_GENERATOR );
1161
- PyErr_SyntaxLocation (st -> st_filename ,
1162
- s -> lineno );
1166
+ PyErr_SyntaxLocationEx (st -> st_filename ,
1167
+ s -> lineno ,
1168
+ s -> col_offset );
1163
1169
return 0 ;
1164
1170
}
1165
1171
}
@@ -1221,15 +1227,19 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
1221
1227
VISIT_SEQ (st , alias , s -> v .Import .names );
1222
1228
/* XXX Don't have the lineno available inside
1223
1229
visit_alias */
1224
- if (st -> st_cur -> ste_unoptimized && !st -> st_cur -> ste_opt_lineno )
1230
+ if (st -> st_cur -> ste_unoptimized && !st -> st_cur -> ste_opt_lineno ) {
1225
1231
st -> st_cur -> ste_opt_lineno = s -> lineno ;
1232
+ st -> st_cur -> ste_opt_col_offset = s -> col_offset ;
1233
+ }
1226
1234
break ;
1227
1235
case ImportFrom_kind :
1228
1236
VISIT_SEQ (st , alias , s -> v .ImportFrom .names );
1229
1237
/* XXX Don't have the lineno available inside
1230
1238
visit_alias */
1231
- if (st -> st_cur -> ste_unoptimized && !st -> st_cur -> ste_opt_lineno )
1239
+ if (st -> st_cur -> ste_unoptimized && !st -> st_cur -> ste_opt_lineno ) {
1232
1240
st -> st_cur -> ste_opt_lineno = s -> lineno ;
1241
+ st -> st_cur -> ste_opt_col_offset = s -> col_offset ;
1242
+ }
1233
1243
break ;
1234
1244
case Global_kind : {
1235
1245
int i ;
@@ -1324,7 +1334,8 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
1324
1334
if (e -> v .Lambda .args -> defaults )
1325
1335
VISIT_SEQ (st , expr , e -> v .Lambda .args -> defaults );
1326
1336
if (!symtable_enter_block (st , lambda ,
1327
- FunctionBlock , (void * )e , e -> lineno ))
1337
+ FunctionBlock , (void * )e , e -> lineno ,
1338
+ e -> col_offset ))
1328
1339
return 0 ;
1329
1340
VISIT_IN_BLOCK (st , arguments , e -> v .Lambda .args , (void * )e );
1330
1341
VISIT_IN_BLOCK (st , expr , e -> v .Lambda .body , (void * )e );
@@ -1367,8 +1378,8 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
1367
1378
if (st -> st_cur -> ste_returns_value ) {
1368
1379
PyErr_SetString (PyExc_SyntaxError ,
1369
1380
RETURN_VAL_IN_GENERATOR );
1370
- PyErr_SyntaxLocation (st -> st_filename ,
1371
- e -> lineno );
1381
+ PyErr_SyntaxLocationEx (st -> st_filename ,
1382
+ e -> lineno , e -> col_offset );
1372
1383
return 0 ;
1373
1384
}
1374
1385
break ;
@@ -1557,8 +1568,9 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
1557
1568
else {
1558
1569
if (st -> st_cur -> ste_type != ModuleBlock ) {
1559
1570
int lineno = st -> st_cur -> ste_lineno ;
1571
+ int col_offset = st -> st_cur -> ste_col_offset ;
1560
1572
PyErr_SetString (PyExc_SyntaxError , IMPORT_STAR_WARNING );
1561
- PyErr_SyntaxLocation (st -> st_filename , lineno );
1573
+ PyErr_SyntaxLocationEx (st -> st_filename , lineno , col_offset );
1562
1574
Py_DECREF (store_name );
1563
1575
return 0 ;
1564
1576
}
@@ -1622,7 +1634,8 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
1622
1634
VISIT (st , expr , outermost -> iter );
1623
1635
/* Create comprehension scope for the rest */
1624
1636
if (!scope_name ||
1625
- !symtable_enter_block (st , scope_name , FunctionBlock , (void * )e , e -> lineno )) {
1637
+ !symtable_enter_block (st , scope_name , FunctionBlock , (void * )e ,
1638
+ e -> lineno , e -> col_offset )) {
1626
1639
return 0 ;
1627
1640
}
1628
1641
st -> st_cur -> ste_generator = is_generator ;
0 commit comments