示例#1
0
        public void Define(Symbol sym, IScope currentScope)
        {
            if (TestForDefineErrors(sym, currentScope))
            {
                return;
            }

            currentScope.Define(sym);
        }
示例#2
0
        public bool TestForDefineErrors(Symbol sym, IScope currentScope)
        {
            string location = string.Empty;
            if (sym.Def != null)
                location = "line " + sym.Def.Line + ":" + sym.Def.CharPositionInLine + " ";

            if (currentScope.IsDefinedLocally(sym.Name))
            {
                _listener.Error(location + "Symbol '"
                            + sym.Name + "' already defined"
                    );
                return true;
            }

            if (currentScope.ScopeName == "local")
            {
                //if we're in a local scope, travel up until we hit a function def scope
                //or an event def scope and make sure we're not shadowing any parameters
                //if we are, issue a warning

                if (FindSymbolInMethodScope(sym, currentScope) != null)
                {
                    _listener.Info(location + "Symbol '"
                                + sym.Name + "' shadows parameter of the same name"
                         );
                }
            }

            return false;
        }
示例#3
0
 public void Define(Symbol sym)
 {
     this.Members.Add(sym.Name, sym);
     sym.Scope = this;
 }
示例#4
0
        /// <summary>
        /// Tries to find a matching symbol in the function parameter scope
        /// </summary>
        /// <param name="sym"></param>
        /// <param name="localScope"></param>
        /// <returns></returns>
        private Symbol FindSymbolInMethodScope(Symbol sym, IScope localScope)
        {
            IScope searchScope = localScope;
            while ((searchScope = searchScope.EnclosingScope) != null)
            {
                MethodSymbol methScope = searchScope as MethodSymbol;
                if (methScope != null)
                {
                    if (methScope.IsDefinedLocally(sym.Name))
                    {
                        return methScope.Resolve(sym.Name);
                    }
                }

                EventSymbol eventScope = searchScope as EventSymbol;
                if (eventScope != null)
                {
                    if (eventScope.IsDefinedLocally(sym.Name))
                    {
                        return eventScope.Resolve(sym.Name);
                    }
                }
            }

            return null;
        }
示例#5
0
 public void Define(Symbol sym)
 {
     _symbols.Add(sym.Name, sym);
     sym.Scope = this;
 }