hack/update-vendor.sh

This commit is contained in:
Jordan Liggitt
2019-11-05 14:11:10 -05:00
parent 9a5b7c24ad
commit 297570e06a
932 changed files with 77190 additions and 28219 deletions

View File

@@ -79,19 +79,41 @@ func (c *Comments) Comment() *Comments {
return c
}
// A File represents an entire BUILD file.
// stmtsEnd returns the end position of the last non-nil statement
func stmtsEnd(stmts []Expr) Position {
for i := len(stmts) - 1; i >= 0; i-- {
if stmts[i] != nil {
_, end := stmts[i].Span()
return end
}
}
return Position{}
}
// A File represents an entire BUILD or .bzl file.
type File struct {
Path string // file path, relative to workspace directory
Pkg string // optional; the package of the file
Type FileType
Comments
Stmt []Expr
}
// DisplayPath returns the filename if it's not empty, "<stdin>" otherwise
func (f *File) DisplayPath() string {
if f.Path == "" {
return "<stdin>"
}
return f.Path
}
func (f *File) Span() (start, end Position) {
if len(f.Stmt) == 0 {
return
p := Position{Line: 1, LineRune: 1}
return p, p
}
start, _ = f.Stmt[0].Span()
_, end = f.Stmt[len(f.Stmt)-1].Span()
start = Position{}
end = stmtsEnd(f.Stmt)
return start, end
}
@@ -106,18 +128,39 @@ func (x *CommentBlock) Span() (start, end Position) {
return x.Start, x.Start
}
// A PythonBlock represents a blob of Python code, typically a def or for loop.
type PythonBlock struct {
// An Ident represents an identifier.
type Ident struct {
Comments
Start Position
Token string // raw Python code, including final newline
NamePos Position
Name string
}
func (x *PythonBlock) Span() (start, end Position) {
return x.Start, x.Start.add(x.Token)
func (x *Ident) Span() (start, end Position) {
return x.NamePos, x.NamePos.add(x.Name)
}
// A LiteralExpr represents a literal identifier or number.
// BranchStmt represents a `pass`, `break`, or `continue` statement.
type BranchStmt struct {
Comments
Token string // pass, break, continue
TokenPos Position
}
func (x *BranchStmt) Span() (start, end Position) {
return x.TokenPos, x.TokenPos.add(x.Token)
}
func (x *Ident) asString() *StringExpr {
_, end := x.Span()
return &StringExpr{
Comments: x.Comments,
Start: x.NamePos,
Value: x.Name,
End: end,
}
}
// A LiteralExpr represents a literal number.
type LiteralExpr struct {
Comments
Start Position
@@ -188,32 +231,32 @@ func (x *DotExpr) Span() (start, end Position) {
return start, x.NamePos.add(x.Name)
}
// A ListForExpr represents a list comprehension expression: [X for ... if ...].
type ListForExpr struct {
// A Comprehension represents a list comprehension expression: [X for ... if ...].
type Comprehension struct {
Comments
Curly bool // curly braces (as opposed to square brackets)
Lbrack Position
Body Expr
Clauses []Expr // = *ForClause | *IfClause
ForceMultiLine bool // split expression across multiple lines
Brack string // "", "()", or "[]"
Start Position
X Expr
For []*ForClauseWithIfClausesOpt
End
}
func (x *ListForExpr) Span() (start, end Position) {
return x.Start, x.End.Pos.add("]")
func (x *Comprehension) Span() (start, end Position) {
return x.Lbrack, x.End.Pos.add("]")
}
// A ForClause represents a for clause in a list comprehension: for Var in Expr.
type ForClause struct {
Comments
For Position
Var []Expr
Vars Expr
In Position
Expr Expr
X Expr
}
func (x *ForClause) Span() (start, end Position) {
_, end = x.Expr.Span()
_, end = x.X.Span()
return x.For, end
}
@@ -229,23 +272,6 @@ func (x *IfClause) Span() (start, end Position) {
return x.If, end
}
// A ForClauseWithIfClausesOpt represents a for clause in a list comprehension followed by optional
// if expressions: for ... in ... [if ... if ...]
type ForClauseWithIfClausesOpt struct {
Comments
For *ForClause
Ifs []*IfClause
}
func (x *ForClauseWithIfClausesOpt) Span() (start, end Position) {
start, end = x.For.Span()
if len(x.Ifs) > 0 {
_, end = x.Ifs[len(x.Ifs)-1].Span()
}
return start, end
}
// A KeyValueExpr represents a dictionary entry: Key: Value.
type KeyValueExpr struct {
Comments
@@ -264,8 +290,7 @@ func (x *KeyValueExpr) Span() (start, end Position) {
type DictExpr struct {
Comments
Start Position
List []Expr // all *KeyValueExprs
Comma Position // position of trailing comma, if any
List []Expr // all *KeyValueExprs
End
ForceMultiLine bool // force multiline form when printing
}
@@ -279,7 +304,6 @@ type ListExpr struct {
Comments
Start Position
List []Expr
Comma Position // position of trailing comma, if any
End
ForceMultiLine bool // force multiline form when printing
}
@@ -293,7 +317,6 @@ type SetExpr struct {
Comments
Start Position
List []Expr
Comma Position // position of trailing comma, if any
End
ForceMultiLine bool // force multiline form when printing
}
@@ -305,16 +328,21 @@ func (x *SetExpr) Span() (start, end Position) {
// A TupleExpr represents a tuple literal: (List)
type TupleExpr struct {
Comments
Start Position
List []Expr
Comma Position // position of trailing comma, if any
NoBrackets bool // true if a tuple has no brackets, e.g. `a, b = x`
Start Position
List []Expr
End
ForceCompact bool // force compact (non-multiline) form when printing
ForceMultiLine bool // force multiline form when printing
}
func (x *TupleExpr) Span() (start, end Position) {
return x.Start, x.End.Pos.add(")")
if !x.NoBrackets {
return x.Start, x.End.Pos.add(")")
}
start, _ = x.List[0].Span()
_, end = x.List[len(x.List)-1].Span()
return start, end
}
// A UnaryExpr represents a unary expression: Op X.
@@ -326,6 +354,9 @@ type UnaryExpr struct {
}
func (x *UnaryExpr) Span() (start, end Position) {
if x.X == nil {
return x.OpStart, x.OpStart
}
_, end = x.X.Span()
return x.OpStart, end
}
@@ -346,6 +377,22 @@ func (x *BinaryExpr) Span() (start, end Position) {
return start, end
}
// An AssignExpr represents a binary expression with `=`: LHS = RHS.
type AssignExpr struct {
Comments
LHS Expr
OpPos Position
Op string
LineBreak bool // insert line break between Op and RHS
RHS Expr
}
func (x *AssignExpr) Span() (start, end Position) {
start, _ = x.LHS.Span()
_, end = x.RHS.Span()
return start, end
}
// A ParenExpr represents a parenthesized expression: (X).
type ParenExpr struct {
Comments
@@ -374,7 +421,7 @@ type SliceExpr struct {
func (x *SliceExpr) Span() (start, end Position) {
start, _ = x.X.Span()
return start, x.End
return start, x.End.add("]")
}
// An IndexExpr represents an index expression: X[Y].
@@ -388,21 +435,30 @@ type IndexExpr struct {
func (x *IndexExpr) Span() (start, end Position) {
start, _ = x.X.Span()
return start, x.End
return start, x.End.add("]")
}
// A Function represents the common parts of LambdaExpr and DefStmt
type Function struct {
Comments
StartPos Position // position of DEF or LAMBDA token
Params []Expr
Body []Expr
}
func (x *Function) Span() (start, end Position) {
_, end = x.Body[len(x.Body)-1].Span()
return x.StartPos, end
}
// A LambdaExpr represents a lambda expression: lambda Var: Expr.
type LambdaExpr struct {
Comments
Lambda Position
Var []Expr
Colon Position
Expr Expr
Function
}
func (x *LambdaExpr) Span() (start, end Position) {
_, end = x.Expr.Span()
return x.Lambda, end
return x.Function.Span()
}
// ConditionalExpr represents the conditional: X if TEST else ELSE.
@@ -423,73 +479,93 @@ func (x *ConditionalExpr) Span() (start, end Position) {
return start, end
}
// A CodeBlock represents an indented code block.
type CodeBlock struct {
Statements []Expr
Start Position
End
}
func (x *CodeBlock) Span() (start, end Position) {
return x.Start, x.End.Pos
}
// A FuncDef represents a function definition expression: def foo(List):.
type FuncDef struct {
// A LoadStmt loads another module and binds names from it:
// load(Module, "x", y="foo").
//
// The AST is slightly unfaithful to the concrete syntax here because
// Skylark's load statement, so that it can be implemented in Python,
// binds some names (like y above) with an identifier and some (like x)
// without. For consistency we create fake identifiers for all the
// strings.
type LoadStmt struct {
Comments
Start Position // position of def
Load Position
Module *StringExpr
From []*Ident // name defined in loading module
To []*Ident // name in loaded module
Rparen End
ForceCompact bool // force compact (non-multiline) form when printing
}
func (x *LoadStmt) Span() (start, end Position) {
return x.Load, x.Rparen.Pos.add(")")
}
// A DefStmt represents a function definition expression: def foo(List):.
type DefStmt struct {
Comments
Function
Name string
ListStart Position // position of (
Args []Expr
Body CodeBlock
End // position of the end
ForceCompact bool // force compact (non-multiline) form when printing
ForceMultiLine bool // force multiline form when printing
ColonPos Position // position of the ":"
ForceCompact bool // force compact (non-multiline) form when printing the arguments
ForceMultiLine bool // force multiline form when printing the arguments
}
func (x *FuncDef) Span() (start, end Position) {
return x.Start, x.End.Pos
func (x *DefStmt) Span() (start, end Position) {
return x.Function.Span()
}
// A ReturnExpr represents a return statement: return f(x).
type ReturnExpr struct {
// HeaderSpan returns the span of the function header `def f(...):`
func (x *DefStmt) HeaderSpan() (start, end Position) {
return x.Function.StartPos, x.ColonPos
}
// A ReturnStmt represents a return statement: return f(x).
type ReturnStmt struct {
Comments
Start Position
X Expr
End Position
Return Position
Result Expr // may be nil
}
func (x *ReturnExpr) Span() (start, end Position) {
return x.Start, x.End
func (x *ReturnStmt) Span() (start, end Position) {
if x.Result == nil {
return x.Return, x.Return.add("return")
}
_, end = x.Result.Span()
return x.Return, end
}
// A ForLoop represents a for loop block: for x in range(10):.
type ForLoop struct {
// A ForStmt represents a for loop block: for x in range(10):.
type ForStmt struct {
Comments
Start Position // position of for
LoopVars []Expr
Iterable Expr
Body CodeBlock
End // position of the end
Function
For Position // position of for
Vars Expr
X Expr
Body []Expr
}
func (x *ForLoop) Span() (start, end Position) {
return x.Start, x.End.Pos
func (x *ForStmt) Span() (start, end Position) {
end = stmtsEnd(x.Body)
return x.For, end
}
// An IfElse represents an if-else blocks sequence: if x: ... elif y: ... else: ... .
type IfElse struct {
// An IfStmt represents an if-else block: if x: ... else: ... .
// `elif`s are treated as a chain of `IfStmt`s.
type IfStmt struct {
Comments
Start Position // position of if
Conditions []Condition
End // position of the end
If Position // position of if
Cond Expr
True []Expr
ElsePos End // position of else or elif
False []Expr // optional
}
type Condition struct {
If Expr
Then CodeBlock
}
func (x *IfElse) Span() (start, end Position) {
return x.Start, x.End.Pos
func (x *IfStmt) Span() (start, end Position) {
body := x.False
if body == nil {
body = x.True
}
end = stmtsEnd(body)
return x.If, end
}