protected override void VisitBlockSyntax(BlockSyntax pNode) { //Validate that deferred statements do not contain "return" statements //Report any unused variables if (pNode.Deferred && SyntaxHelper.LastStatementIsReturn(pNode)) { CompilerErrors.InvalidDefer(pNode.Span); } //Report any unused variables _locals.AddScope(); base.VisitBlockSyntax(pNode); foreach (var ld in _locals.GetVariablesInScope()) { if (!ld.IsReferenced) { CompilerErrors.VariableNeverUsed(ld.Name, ld.Span); } } _locals.RemoveScope(); }
protected override void VisitModuleSyntax(ModuleSyntax pNode) { //Global scope _locals.AddScope(); foreach (var f in pNode.Fields) { Visit(f); } //Infer methods foreach (var m in pNode.Methods) { Visit(m); } foreach (var s in pNode.Structs) { Visit(s.DeclaredType); Visit(s.AppliesTo); _unit.FromString(s.GetApplicableType(), out SmallType type); using (var st = Store.AddValue("__Struct", type)) { foreach (var m in s.Methods) { Visit(m); } } } _locals.RemoveScope(); }
protected override void VisitModuleSyntax(ModuleSyntax pNode) { _locals = new ScopeCache <LocalReference>(); _locals.AddScope(); using (var v = Store.AddValue <string>("RunMethod", null)) { base.VisitModuleSyntax(pNode); if (pNode == _mainModule && v.Value == null) { CompilerErrors.NoRunMethod(pNode.Span); } } _locals.RemoveScope(); }