2525
2626static PySTEntryObject *
2727ste_new (struct symtable * st , identifier name , _Py_block_ty block ,
28- void * key , int lineno )
28+ void * key , int lineno , int col_offset )
2929{
3030 PySTEntryObject * ste = NULL ;
3131 PyObject * k ;
@@ -65,7 +65,9 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
6565 ste -> ste_varargs = 0 ;
6666 ste -> ste_varkeywords = 0 ;
6767 ste -> ste_opt_lineno = 0 ;
68+ ste -> ste_opt_col_offset = 0 ;
6869 ste -> ste_lineno = lineno ;
70+ ste -> ste_col_offset = col_offset ;
6971
7072 if (st -> st_cur != NULL &&
7173 (st -> st_cur -> ste_nested ||
@@ -163,7 +165,8 @@ PyTypeObject PySTEntry_Type = {
163165static int symtable_analyze (struct symtable * st );
164166static int symtable_warn (struct symtable * st , char * msg , int lineno );
165167static 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 );
167170static int symtable_exit_block (struct symtable * st , void * ast );
168171static int symtable_visit_stmt (struct symtable * st , stmt_ty s );
169172static int symtable_visit_expr (struct symtable * st , expr_ty s );
@@ -230,7 +233,7 @@ PySymtable_Build(mod_ty mod, const char *filename, PyFutureFeatures *future)
230233 st -> st_future = future ;
231234 /* Make the initial symbol information gathering pass */
232235 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 )) {
234237 PySymtable_Free (st );
235238 return NULL ;
236239 }
@@ -390,8 +393,8 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
390393 PyErr_Format (PyExc_SyntaxError ,
391394 "name '%U' is parameter and global" ,
392395 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 );
395398
396399 return 0 ;
397400 }
@@ -534,8 +537,8 @@ check_unoptimized(const PySTEntryObject* ste) {
534537 break ;
535538 }
536539
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 );
539542 return 0 ;
540543}
541544
@@ -873,8 +876,8 @@ symtable_warn(struct symtable *st, char *msg, int lineno)
873876 lineno , NULL , NULL ) < 0 ) {
874877 if (PyErr_ExceptionMatches (PyExc_SyntaxWarning )) {
875878 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 );
878881 }
879882 return 0 ;
880883 }
@@ -907,7 +910,7 @@ symtable_exit_block(struct symtable *st, void *ast)
907910
908911static int
909912symtable_enter_block (struct symtable * st , identifier name , _Py_block_ty block ,
910- void * ast , int lineno )
913+ void * ast , int lineno , int col_offset )
911914{
912915 PySTEntryObject * prev = NULL ;
913916
@@ -918,7 +921,7 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
918921 }
919922 Py_DECREF (st -> st_cur );
920923 }
921- st -> st_cur = ste_new (st , name , block , ast , lineno );
924+ st -> st_cur = ste_new (st , name , block , ast , lineno , col_offset );
922925 if (st -> st_cur == NULL )
923926 return 0 ;
924927 if (name == GET_IDENTIFIER (top ))
@@ -963,8 +966,9 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag)
963966 if ((flag & DEF_PARAM ) && (val & DEF_PARAM )) {
964967 /* Is it better to use 'mangled' or 'name' here? */
965968 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 );
968972 goto error ;
969973 }
970974 val |= flag ;
@@ -1114,7 +1118,8 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
11141118 if (s -> v .FunctionDef .decorator_list )
11151119 VISIT_SEQ (st , expr , s -> v .FunctionDef .decorator_list );
11161120 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 ))
11181123 return 0 ;
11191124 VISIT_IN_BLOCK (st , arguments , s -> v .FunctionDef .args , s );
11201125 VISIT_SEQ_IN_BLOCK (st , stmt , s -> v .FunctionDef .body , s );
@@ -1134,7 +1139,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
11341139 if (s -> v .ClassDef .decorator_list )
11351140 VISIT_SEQ (st , expr , s -> v .ClassDef .decorator_list );
11361141 if (!symtable_enter_block (st , s -> v .ClassDef .name , ClassBlock ,
1137- (void * )s , s -> lineno ))
1142+ (void * )s , s -> lineno , s -> col_offset ))
11381143 return 0 ;
11391144 if (!GET_IDENTIFIER (__class__ ) ||
11401145 !symtable_add_def (st , __class__ , DEF_LOCAL ) ||
@@ -1158,8 +1163,9 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
11581163 if (st -> st_cur -> ste_generator ) {
11591164 PyErr_SetString (PyExc_SyntaxError ,
11601165 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 );
11631169 return 0 ;
11641170 }
11651171 }
@@ -1221,15 +1227,19 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
12211227 VISIT_SEQ (st , alias , s -> v .Import .names );
12221228 /* XXX Don't have the lineno available inside
12231229 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 ) {
12251231 st -> st_cur -> ste_opt_lineno = s -> lineno ;
1232+ st -> st_cur -> ste_opt_col_offset = s -> col_offset ;
1233+ }
12261234 break ;
12271235 case ImportFrom_kind :
12281236 VISIT_SEQ (st , alias , s -> v .ImportFrom .names );
12291237 /* XXX Don't have the lineno available inside
12301238 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 ) {
12321240 st -> st_cur -> ste_opt_lineno = s -> lineno ;
1241+ st -> st_cur -> ste_opt_col_offset = s -> col_offset ;
1242+ }
12331243 break ;
12341244 case Global_kind : {
12351245 int i ;
@@ -1324,7 +1334,8 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
13241334 if (e -> v .Lambda .args -> defaults )
13251335 VISIT_SEQ (st , expr , e -> v .Lambda .args -> defaults );
13261336 if (!symtable_enter_block (st , lambda ,
1327- FunctionBlock , (void * )e , e -> lineno ))
1337+ FunctionBlock , (void * )e , e -> lineno ,
1338+ e -> col_offset ))
13281339 return 0 ;
13291340 VISIT_IN_BLOCK (st , arguments , e -> v .Lambda .args , (void * )e );
13301341 VISIT_IN_BLOCK (st , expr , e -> v .Lambda .body , (void * )e );
@@ -1367,8 +1378,8 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
13671378 if (st -> st_cur -> ste_returns_value ) {
13681379 PyErr_SetString (PyExc_SyntaxError ,
13691380 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 );
13721383 return 0 ;
13731384 }
13741385 break ;
@@ -1557,8 +1568,9 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
15571568 else {
15581569 if (st -> st_cur -> ste_type != ModuleBlock ) {
15591570 int lineno = st -> st_cur -> ste_lineno ;
1571+ int col_offset = st -> st_cur -> ste_col_offset ;
15601572 PyErr_SetString (PyExc_SyntaxError , IMPORT_STAR_WARNING );
1561- PyErr_SyntaxLocation (st -> st_filename , lineno );
1573+ PyErr_SyntaxLocationEx (st -> st_filename , lineno , col_offset );
15621574 Py_DECREF (store_name );
15631575 return 0 ;
15641576 }
@@ -1622,7 +1634,8 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
16221634 VISIT (st , expr , outermost -> iter );
16231635 /* Create comprehension scope for the rest */
16241636 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 )) {
16261639 return 0 ;
16271640 }
16281641 st -> st_cur -> ste_generator = is_generator ;
0 commit comments