lang: Move the Arg type into the common interface package
This lets it get used in multiple places.
This commit is contained in:
@@ -438,6 +438,22 @@ func (obj *Scope) PullIndexes() ([]Expr, bool) {
|
||||
return indexes, exists
|
||||
}
|
||||
|
||||
// Arg represents a name identifier for a func or class argument declaration and
|
||||
// is sometimes accompanied by a type. This does not satisfy the Expr interface.
|
||||
type Arg struct {
|
||||
Name string
|
||||
Type *types.Type // nil if unspecified (needs to be solved for)
|
||||
}
|
||||
|
||||
// String returns a short representation of this arg.
|
||||
func (obj *Arg) String() string {
|
||||
s := obj.Name
|
||||
if obj.Type != nil {
|
||||
s += fmt.Sprintf(" %s", obj.Type.String())
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Edge is the data structure representing a compiled edge that is used in the
|
||||
// lang to express a dependency between two resources and optionally send/recv.
|
||||
type Edge struct {
|
||||
|
||||
@@ -1416,14 +1416,14 @@ func TestLexParse0(t *testing.T) {
|
||||
Prog: []interfaces.Stmt{
|
||||
&StmtClass{
|
||||
Name: "x",
|
||||
Args: []*Arg{},
|
||||
Args: []*interfaces.Arg{},
|
||||
Body: &StmtProg{
|
||||
Prog: []interfaces.Stmt{},
|
||||
},
|
||||
},
|
||||
&StmtClass{
|
||||
Name: "y1",
|
||||
Args: []*Arg{},
|
||||
Args: []*interfaces.Arg{},
|
||||
Body: &StmtProg{
|
||||
Prog: []interfaces.Stmt{},
|
||||
},
|
||||
@@ -1462,7 +1462,7 @@ func TestLexParse0(t *testing.T) {
|
||||
Prog: []interfaces.Stmt{
|
||||
&StmtClass{
|
||||
Name: "c1",
|
||||
Args: []*Arg{
|
||||
Args: []*interfaces.Arg{
|
||||
{
|
||||
Name: "a",
|
||||
//Type: &types.Type{},
|
||||
@@ -1535,7 +1535,7 @@ func TestLexParse0(t *testing.T) {
|
||||
Prog: []interfaces.Stmt{
|
||||
&StmtClass{
|
||||
Name: "c1",
|
||||
Args: []*Arg{
|
||||
Args: []*interfaces.Arg{
|
||||
{
|
||||
Name: "a",
|
||||
Type: types.TypeStr,
|
||||
@@ -1727,7 +1727,7 @@ func TestLexParse0(t *testing.T) {
|
||||
&StmtFunc{
|
||||
Name: "f1",
|
||||
Func: &ExprFunc{
|
||||
Args: []*Arg{},
|
||||
Args: []*interfaces.Arg{},
|
||||
Body: &ExprInt{
|
||||
V: 42,
|
||||
},
|
||||
@@ -1748,7 +1748,7 @@ func TestLexParse0(t *testing.T) {
|
||||
}
|
||||
{
|
||||
fn := &ExprFunc{
|
||||
Args: []*Arg{},
|
||||
Args: []*interfaces.Arg{},
|
||||
Return: types.TypeInt,
|
||||
Body: &ExprCall{
|
||||
Name: operatorFuncName,
|
||||
@@ -1790,7 +1790,7 @@ func TestLexParse0(t *testing.T) {
|
||||
}
|
||||
{
|
||||
fn := &ExprFunc{
|
||||
Args: []*Arg{
|
||||
Args: []*interfaces.Arg{
|
||||
{
|
||||
Name: "a",
|
||||
Type: types.TypeInt,
|
||||
@@ -1841,7 +1841,7 @@ func TestLexParse0(t *testing.T) {
|
||||
}
|
||||
{
|
||||
fn := &ExprFunc{
|
||||
Args: []*Arg{
|
||||
Args: []*interfaces.Arg{
|
||||
{
|
||||
Name: "x",
|
||||
Type: types.TypeStr,
|
||||
@@ -1888,7 +1888,7 @@ func TestLexParse0(t *testing.T) {
|
||||
{
|
||||
|
||||
fn := &ExprFunc{
|
||||
Args: []*Arg{},
|
||||
Args: []*interfaces.Arg{},
|
||||
Body: &ExprInt{
|
||||
V: 42,
|
||||
},
|
||||
@@ -1915,7 +1915,7 @@ func TestLexParse0(t *testing.T) {
|
||||
}
|
||||
{
|
||||
fn := &ExprFunc{
|
||||
Args: []*Arg{
|
||||
Args: []*interfaces.Arg{
|
||||
{
|
||||
Name: "x",
|
||||
Type: types.TypeStr,
|
||||
@@ -1962,7 +1962,7 @@ func TestLexParse0(t *testing.T) {
|
||||
}
|
||||
{
|
||||
fn := &ExprFunc{
|
||||
Args: []*Arg{
|
||||
Args: []*interfaces.Arg{
|
||||
{
|
||||
Name: "x",
|
||||
Type: types.TypeStr,
|
||||
@@ -2027,10 +2027,10 @@ func TestLexParse0(t *testing.T) {
|
||||
Name: "funcgen",
|
||||
// This is the outer function...
|
||||
Func: &ExprFunc{
|
||||
Args: []*Arg{},
|
||||
Args: []*interfaces.Arg{},
|
||||
// This is the inner function...
|
||||
Body: &ExprFunc{
|
||||
Args: []*Arg{},
|
||||
Args: []*interfaces.Arg{},
|
||||
Body: &ExprStr{
|
||||
V: "hello",
|
||||
},
|
||||
|
||||
@@ -62,8 +62,8 @@ func init() {
|
||||
structFields []*ExprStructField
|
||||
structField *ExprStructField
|
||||
|
||||
args []*Arg
|
||||
arg *Arg
|
||||
args []*interfaces.Arg
|
||||
arg *interfaces.Arg
|
||||
|
||||
resContents []StmtResContents // interface
|
||||
resField *StmtResField
|
||||
@@ -828,7 +828,7 @@ args:
|
||||
/* end of list */
|
||||
{
|
||||
posLast(yylex, yyDollar) // our pos
|
||||
$$.args = []*Arg{}
|
||||
$$.args = []*interfaces.Arg{}
|
||||
}
|
||||
| args COMMA arg
|
||||
{
|
||||
@@ -838,21 +838,21 @@ args:
|
||||
| arg
|
||||
{
|
||||
posLast(yylex, yyDollar) // our pos
|
||||
$$.args = append([]*Arg{}, $1.arg)
|
||||
$$.args = append([]*interfaces.Arg{}, $1.arg)
|
||||
}
|
||||
;
|
||||
arg:
|
||||
// `$x`
|
||||
VAR_IDENTIFIER
|
||||
{
|
||||
$$.arg = &Arg{
|
||||
$$.arg = &interfaces.Arg{
|
||||
Name: $1.str,
|
||||
}
|
||||
}
|
||||
// `$x <type>`
|
||||
| VAR_IDENTIFIER type
|
||||
{
|
||||
$$.arg = &Arg{
|
||||
$$.arg = &interfaces.Arg{
|
||||
Name: $1.str,
|
||||
Type: $2.typ,
|
||||
}
|
||||
@@ -1242,7 +1242,7 @@ type_struct_fields:
|
||||
/* end of list */
|
||||
{
|
||||
posLast(yylex, yyDollar) // our pos
|
||||
$$.args = []*Arg{}
|
||||
$$.args = []*interfaces.Arg{}
|
||||
}
|
||||
| type_struct_fields SEMICOLON type_struct_field
|
||||
{
|
||||
@@ -1252,14 +1252,14 @@ type_struct_fields:
|
||||
| type_struct_field
|
||||
{
|
||||
posLast(yylex, yyDollar) // our pos
|
||||
$$.args = append([]*Arg{}, $1.arg)
|
||||
$$.args = append([]*interfaces.Arg{}, $1.arg)
|
||||
}
|
||||
;
|
||||
type_struct_field:
|
||||
IDENTIFIER type
|
||||
{
|
||||
posLast(yylex, yyDollar) // our pos
|
||||
$$.arg = &Arg{ // re-use the Arg struct
|
||||
$$.arg = &interfaces.Arg{ // re-use the Arg struct
|
||||
Name: $1.str,
|
||||
Type: $2.typ,
|
||||
}
|
||||
@@ -1269,7 +1269,7 @@ type_func_args:
|
||||
/* end of list */
|
||||
{
|
||||
posLast(yylex, yyDollar) // our pos
|
||||
$$.args = []*Arg{}
|
||||
$$.args = []*interfaces.Arg{}
|
||||
}
|
||||
| type_func_args COMMA type_func_arg
|
||||
{
|
||||
@@ -1279,15 +1279,15 @@ type_func_args:
|
||||
| type_func_arg
|
||||
{
|
||||
posLast(yylex, yyDollar) // our pos
|
||||
$$.args = append([]*Arg{}, $1.arg)
|
||||
//$$.args = []*Arg{$1.arg} // TODO: is this equivalent?
|
||||
$$.args = append([]*interfaces.Arg{}, $1.arg)
|
||||
//$$.args = []*interfaces.Arg{$1.arg} // TODO: is this equivalent?
|
||||
}
|
||||
;
|
||||
type_func_arg:
|
||||
// `<type>`
|
||||
type
|
||||
{
|
||||
$$.arg = &Arg{
|
||||
$$.arg = &interfaces.Arg{
|
||||
Type: $1.typ,
|
||||
}
|
||||
}
|
||||
@@ -1295,7 +1295,7 @@ type_func_arg:
|
||||
// XXX: should we allow specifying the arg name here?
|
||||
| VAR_IDENTIFIER type
|
||||
{
|
||||
$$.arg = &Arg{
|
||||
$$.arg = &interfaces.Arg{
|
||||
Name: $1.str,
|
||||
Type: $2.typ,
|
||||
}
|
||||
|
||||
@@ -3970,7 +3970,7 @@ type StmtClass struct {
|
||||
scope *interfaces.Scope // store for referencing this later
|
||||
|
||||
Name string
|
||||
Args []*Arg
|
||||
Args []*interfaces.Arg
|
||||
Body interfaces.Stmt // probably a *StmtProg
|
||||
}
|
||||
|
||||
@@ -4008,7 +4008,7 @@ func (obj *StmtClass) Interpolate() (interfaces.Stmt, error) {
|
||||
|
||||
args := obj.Args
|
||||
if obj.Args == nil {
|
||||
args = []*Arg{}
|
||||
args = []*interfaces.Arg{}
|
||||
}
|
||||
|
||||
return &StmtClass{
|
||||
@@ -4032,7 +4032,7 @@ func (obj *StmtClass) Copy() (interfaces.Stmt, error) {
|
||||
|
||||
args := obj.Args
|
||||
if obj.Args == nil {
|
||||
args = []*Arg{}
|
||||
args = []*interfaces.Arg{}
|
||||
}
|
||||
|
||||
if !copied { // it's static
|
||||
@@ -6507,7 +6507,7 @@ type ExprFunc struct {
|
||||
// Args are the list of args that were used when defining the function.
|
||||
// This can include a string name and a type, however the type might be
|
||||
// absent here.
|
||||
Args []*Arg
|
||||
Args []*interfaces.Arg
|
||||
// Return is the return type of the function if it was defined.
|
||||
Return *types.Type // return type if specified
|
||||
// Body is the contents of the function. It can be any expression.
|
||||
@@ -6647,7 +6647,7 @@ func (obj *ExprFunc) Interpolate() (interfaces.Expr, error) {
|
||||
|
||||
args := obj.Args
|
||||
if obj.Args == nil {
|
||||
args = []*Arg{}
|
||||
args = []*interfaces.Arg{}
|
||||
}
|
||||
|
||||
return &ExprFunc{
|
||||
@@ -8600,22 +8600,6 @@ func (obj *ExprVar) Value() (types.Value, error) {
|
||||
return expr.Value() // recurse
|
||||
}
|
||||
|
||||
// Arg represents a name identifier for a func or class argument declaration and
|
||||
// is sometimes accompanied by a type. This does not satisfy the Expr interface.
|
||||
type Arg struct {
|
||||
Name string
|
||||
Type *types.Type // nil if unspecified (needs to be solved for)
|
||||
}
|
||||
|
||||
// String returns a short representation of this arg.
|
||||
func (obj *Arg) String() string {
|
||||
s := obj.Name
|
||||
if obj.Type != nil {
|
||||
s += fmt.Sprintf(" %s", obj.Type.String())
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// ExprIf represents an if expression which *must* have both branches, and which
|
||||
// returns a value. As a result, it has a type. This is different from a StmtIf,
|
||||
// which does not need to have both branches, and which does not return a value.
|
||||
|
||||
Reference in New Issue
Block a user