Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

Commit

Permalink
Cleanup flag situtation in Variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kiljacken committed Mar 14, 2016
1 parent 9045cd6 commit d2e6c92
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/ast/ast.go
Expand Up @@ -136,13 +136,11 @@ type Variable struct {
Name string
Mutable bool
Attrs parser.AttrGroup
FromStruct bool
ParentStruct StructType
ParentModule *Module
IsParameter bool
IsArgument bool

IsReceiver bool // TODO separate this out so it isn't as messy
// Is the variable not from an variable decl
IsImplicit bool
}

func (v Variable) String() string {
Expand Down
8 changes: 4 additions & 4 deletions src/ast/constructor.go
Expand Up @@ -434,7 +434,7 @@ func (c *Constructor) constructVarDeclNode(v *parser.VarDeclNode) *VariableDecl
Attrs: v.Attrs(),
Mutable: v.Mutable.Value != "",
ParentModule: c.module,
IsReceiver: v.IsReceiver,
IsImplicit: v.IsImplicit,
}

if v.Type != nil {
Expand Down Expand Up @@ -872,8 +872,8 @@ func (c *Constructor) constructFunctionNode(v *parser.FunctionNode) *Function {

if v.Header.Receiver != nil {
function.Receiver = c.constructVarDeclNode(v.Header.Receiver)
if !function.Receiver.Variable.IsReceiver {
panic("INTERNAL ERROR: Reciever variable was not marked a reciever")
if !function.Receiver.Variable.IsImplicit {
panic("INTERNAL ERROR: Reciever variable was not marked implicit")
}

// Propagate generic parameters from reciever to method
Expand All @@ -900,7 +900,7 @@ func (c *Constructor) constructFunctionNode(v *parser.FunctionNode) *Function {
for _, arg := range v.Header.Arguments { // TODO rename v.Header.Arguments to v.Header.Parameters
arguments = append(arguments, arg)
decl := c.constructVarDeclNode(arg)
decl.Variable.IsParameter = true
decl.Variable.IsImplicit = true
function.Parameters = append(function.Parameters, decl)
function.Type.Parameters = append(function.Type.Parameters, decl.Variable.Type)
}
Expand Down
3 changes: 0 additions & 3 deletions src/ast/mangle.go
Expand Up @@ -173,9 +173,6 @@ func (v Variable) MangledName(typ MangleType) string {
switch typ {
case MANGLE_ARK_UNSTABLE:
result := fmt.Sprintf("_V%d%s", len(v.Name), v.Name)
if v.FromStruct {
result = v.ParentModule.MangledName(typ) + result
}
return result
default:
panic("")
Expand Down
1 change: 0 additions & 1 deletion src/ast/visitor.go
Expand Up @@ -183,7 +183,6 @@ func (v *ASTVisitor) VisitChildren(n Node) {
n.Subscript = v.VisitExpr(n.Subscript)

case *SizeofExpr:
// TODO: Maybe visit sizeofExpr.Type at some point?
n.Expr = v.VisitExpr(n.Expr)

case *ArrayLenExpr:
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parse_tree.go
Expand Up @@ -218,7 +218,7 @@ type VarDeclNode struct {
Value ParseNode
Mutable LocatedString

IsReceiver bool
IsImplicit bool
ReceiverGenericSigil *GenericSigilNode
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser/parser.go
Expand Up @@ -727,7 +727,7 @@ func (v *parser) parseVarDeclBody(isReceiver bool) *VarDeclNode {
res := &VarDeclNode{
Name: NewLocatedString(name),
Type: varType,
IsReceiver: isReceiver,
IsImplicit: isReceiver,
}
start := name.Where.Start()
if mutable != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/semantic/unused.go
Expand Up @@ -65,7 +65,7 @@ func (v *UnusedCheck) AnalyzeUsage(s *SemanticAnalyzer) {
decl := v.encounteredDecl[idx]
switch it := it.(type) {
case *ast.Variable:
if !it.IsParameter && !it.IsReceiver && !it.FromStruct && v.uses[it] == 0 {
if !it.IsImplicit && v.uses[it] == 0 {
s.Warn(decl, "Unused variable `%s`", it.Name)
}

Expand Down

0 comments on commit d2e6c92

Please sign in to comment.