Beispiel #1
0
        internal override IEnumerable <NameExpression> Walk()
        {
            List <NameExpression> freeVariables = new List <NameExpression>();

            foreach (Statement statement in Statements)
            {
                freeVariables.AddRange(statement.Walk());
            }


            // The Walk() call will have populated all variables in LetStatements
            // For function definitions, we need a special handling for overloads
            DeclaredVariables = Statements
                                .Where(statement => statement is Definition &&
                                       !(statement is FunctionDefinition))
                                .Select(statement => (statement as Definition).DeclaredVariable)
                                .ToList();

            List <FunctionDefinition> functions = Statements
                                                  .Where(statement => statement is FunctionDefinition)
                                                  .Select(statement => statement as FunctionDefinition)
                                                  .ToList();

            Overloads = Compiler.GenerateOverloads(functions);
            DeclaredVariables.AddRange(Overloads.Select(o => o.variable));

            Compiler.MatchVariables(freeVariables, DeclaredVariables);

            return(freeVariables);
        }
        /// <summary>
        /// Rename all our guys in our internal statements.
        /// </summary>
        /// <param name="originalName"></param>
        /// <param name="newName"></param>
        public void RenameBlockVariables(string originalName, string newName)
        {
#if false
            // And remove any declarations. When we rename, we are doing it because this block
            // is being made to look like an already existing other block - so the variable will
            // have been declared over there already.
            var decl = DeclaredVariables.Where(d => d.RawValue == originalName).FirstOrDefault();
            if (decl != null)
            {
                Remove(decl);
            }
#else
            // Rename the declared variables as requested. While these variables may be used again,
            // they need to appear here or if the combine fails, they will not be declared (and they
            // will be used).
            foreach (var v in DeclaredVariables.Where(d => d.RawValue == originalName))
            {
                v.RenameRawValue(originalName, newName);
            }

            // Did that cause any duplicates? If so, remove them.
            if (DeclaredVariables.Where(d => d.RawValue == newName).Count() > 1)
            {
                _variables.Remove(_variables.Where(d => d.RawValue == newName).First());
            }
#endif
            foreach (var s in _statements)
            {
                s.RenameVariable(originalName, newName);
            }
        }
Beispiel #3
0
 public void Clear()
 {
     _schema = null;
     Path.Clear();
     Fragments.Clear();
     UsedVariables.Clear();
     UnusedVariables.Clear();
     DeclaredVariables.Clear();
     Errors.Clear();
 }
Beispiel #4
0
 public Function ToFunction()
 {
     return
         (new Function(
              _name,
              _lineNo,
              _parameterNames.ToList(),
              _directives,
              DeclaredVariables.ToList(),
              NestedFunctions.ToList(),
              FunctionBody,
              _isDeclaration));
 }
Beispiel #5
0
        protected override DeclaredVariables GetDeclaredVariables(
            string source, bool visibleScopesOnly,
            DeclarationContext declarationContext)
        {
            DeclaredVariables variables = new DeclaredVariables(
                source, fullNamespaceList, visibleScopesOnly,
                declarationContext);

            List <Variable> controls = GetServerControls();

            variables.Items.AddRange(controls);

            return(variables);
        }
Beispiel #6
0
                public void Free()
                {
                    foreach (var scope in NestedScopes)
                    {
                        scope.Free();
                    }
                    NestedScopes.Free();

                    foreach (var closure in Closures)
                    {
                        closure.Free();
                    }
                    Closures.Free();
                    DeclaredVariables.Free();
                }
Beispiel #7
0
 public void Clear()
 {
     _schema = null;
     Path.Clear();
     Variables.Clear();
     Fragments.Clear();
     UsedVariables.Clear();
     UnusedVariables.Clear();
     DeclaredVariables.Clear();
     Names.Clear();
     Types.Clear();
     Directives.Clear();
     OutputFields.Clear();
     InputFields.Clear();
     Errors.Clear();
     IsInError = false;
 }
 public void BlockEnd()
 {
     DeclaredVariables.Remove(Deepness);
     Deepness--;
 }
 public void BlockStart()
 {
     Deepness++;
     DeclaredVariables.Add(Deepness, new Dictionary <string, Variable>());
 }
 public void Visit(Declaration instruction)
 {
     DeclaredVariables.Add(instruction.Name);
 }