ast, parser: add additional info for CallExpr, StructInit nodes (#9526)
							parent
							
								
									c5302bfcf5
								
							
						
					
					
						commit
						3ced970b17
					
				|  | @ -28,8 +28,8 @@ pub type Stmt = AsmStmt | AssertStmt | AssignStmt | Block | BranchStmt | CompFor | |||
| pub type ScopeObject = AsmRegister | ConstField | GlobalField | Var | ||||
| 
 | ||||
| // TOOD: replace table.Param
 | ||||
| pub type Node = ConstField | EnumField | Expr | Field | File | GlobalField | IfBranch | | ||||
| 	MatchBranch | ScopeObject | SelectBranch | Stmt | StructField | StructInitField | | ||||
| pub type Node = CallArg | ConstField | EnumField | Expr | Field | File | GlobalField | | ||||
| 	IfBranch | MatchBranch | ScopeObject | SelectBranch | Stmt | StructField | StructInitField | | ||||
| 	table.Param | ||||
| 
 | ||||
| pub struct Type { | ||||
|  | @ -242,6 +242,7 @@ pub struct StructInitField { | |||
| pub: | ||||
| 	expr          Expr | ||||
| 	pos           token.Position | ||||
| 	name_pos      token.Position | ||||
| 	comments      []Comment | ||||
| 	next_comments []Comment | ||||
| pub mut: | ||||
|  | @ -265,6 +266,7 @@ pub mut: | |||
| pub struct StructInit { | ||||
| pub: | ||||
| 	pos      token.Position | ||||
| 	name_pos token.Position | ||||
| 	is_short bool | ||||
| pub mut: | ||||
| 	unresolved           bool | ||||
|  | @ -366,8 +368,9 @@ pub: | |||
| // function or method call expr
 | ||||
| pub struct CallExpr { | ||||
| pub: | ||||
| 	pos token.Position | ||||
| 	mod string | ||||
| 	pos      token.Position | ||||
| 	name_pos token.Position | ||||
| 	mod      string | ||||
| pub mut: | ||||
| 	name               string // left.name()
 | ||||
| 	is_method          bool | ||||
|  | @ -1584,6 +1587,9 @@ pub fn (node Node) position() token.Position { | |||
| 			} | ||||
| 			return pos | ||||
| 		} | ||||
| 		CallArg { | ||||
| 			return node.pos | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | @ -1609,6 +1615,7 @@ pub fn (node Node) children() []Node { | |||
| 			} | ||||
| 			CallExpr { | ||||
| 				children << node.left | ||||
| 				children << node.args.map(Node(it)) | ||||
| 				children << Expr(node.or_block) | ||||
| 			} | ||||
| 			InfixExpr { | ||||
|  |  | |||
|  | @ -91,6 +91,7 @@ pub fn (mut p Parser) call_expr(language table.Language, mod string) ast.CallExp | |||
| 	pos.update_last_line(p.prev_tok.line_nr) | ||||
| 	return ast.CallExpr{ | ||||
| 		name: fn_name | ||||
| 		name_pos: first_pos | ||||
| 		args: args | ||||
| 		mod: p.mod | ||||
| 		pos: pos | ||||
|  |  | |||
|  | @ -359,6 +359,7 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit { | |||
| 		mut field_name := '' | ||||
| 		mut expr := ast.Expr{} | ||||
| 		mut field_pos := token.Position{} | ||||
| 		mut first_field_pos := token.Position{} | ||||
| 		mut comments := []ast.Comment{} | ||||
| 		mut nline_comments := []ast.Comment{} | ||||
| 		is_update_expr := fields.len == 0 && p.tok.kind == .ellipsis | ||||
|  | @ -366,6 +367,7 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit { | |||
| 			// name will be set later in checker
 | ||||
| 			expr = p.expr(0) | ||||
| 			field_pos = expr.position() | ||||
| 			first_field_pos = field_pos | ||||
| 			comments = p.eat_comments(same_line: true) | ||||
| 		} else if is_update_expr { | ||||
| 			// struct updating syntax; f2 := Foo{ ...f, name: 'f2' }
 | ||||
|  | @ -374,7 +376,7 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit { | |||
| 			update_expr_comments << p.eat_comments(same_line: true) | ||||
| 			has_update_expr = true | ||||
| 		} else { | ||||
| 			first_field_pos := p.tok.position() | ||||
| 			first_field_pos = p.tok.position() | ||||
| 			field_name = p.check_name() | ||||
| 			p.check(.colon) | ||||
| 			expr = p.expr(0) | ||||
|  | @ -403,6 +405,7 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit { | |||
| 				name: field_name | ||||
| 				expr: expr | ||||
| 				pos: field_pos | ||||
| 				name_pos: first_field_pos | ||||
| 				comments: comments | ||||
| 				next_comments: nline_comments | ||||
| 			} | ||||
|  | @ -419,6 +422,7 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit { | |||
| 		update_expr: update_expr | ||||
| 		update_expr_comments: update_expr_comments | ||||
| 		has_update_expr: has_update_expr | ||||
| 		name_pos: first_pos | ||||
| 		pos: first_pos.extend(p.prev_tok.position()) | ||||
| 		is_short: no_keys | ||||
| 		pre_comments: pre_comments | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue