Esempio n. 1
0
        public bool VisitNode(VariableDeclaration node)
        {
            ASTNode nodeType;
            if (node.VarType.Type == ASTNodeType.Struct || node.VarType.Type == ASTNodeType.Enumeration)
            {
                // Check type, if its a struct or enum, visit that first.
                node.VarType.Outer = node.Outer;
                Success = Success && node.VarType.AcceptVisitor(this);
                // Add the type to the list of types in the class.
                NodeUtils.GetContainingClass(node).TypeDeclarations.Add(node.VarType);
                nodeType = node.VarType;
            }
            else if (!Symbols.TryGetSymbol(node.VarType.Name, out nodeType, NodeUtils.GetOuterClassScope(node)))
            {
                return Error("No type named '" + node.VarType.Name + "' exists in this scope!", node.VarType.StartPos, node.VarType.EndPos);
            }
            else if (!typeof(VariableType).IsAssignableFrom(nodeType.GetType()))
            {
                return Error("Invalid variable type, must be a class/struct/enum/primitive.", node.VarType.StartPos, node.VarType.EndPos);
            }

            if (node.Outer.Type == ASTNodeType.Class)
            {
                int index = NodeUtils.GetContainingClass(node).VariableDeclarations.IndexOf(node);
                foreach (VariableIdentifier ident in node.Variables)
                {
                    if (Symbols.SymbolExistsInCurrentScope(ident.Name))
                        return Error("A member named '" + ident.Name + "' already exists in this class!", ident.StartPos, ident.EndPos);
                    Variable variable = new Variable(node.Specifiers, ident, nodeType as VariableType, ident.StartPos, ident.EndPos);
                    variable.Outer = node.Outer;
                    Symbols.AddSymbol(variable.Name, variable);
                    NodeUtils.GetContainingClass(node).VariableDeclarations.Insert(index++, variable);
                }
                NodeUtils.GetContainingClass(node).VariableDeclarations.Remove(node);
            }
            else if (node.Outer.Type == ASTNodeType.Struct)
            {
                int index = (node.Outer as Struct).Members.IndexOf(node);
                foreach (VariableIdentifier ident in node.Variables)
                {
                    if (Symbols.SymbolExistsInCurrentScope(ident.Name))
                        return Error("A member named '" + ident.Name + "' already exists in this struct!", ident.StartPos, ident.EndPos);
                    Variable variable = new Variable(node.Specifiers, ident, nodeType as VariableType, ident.StartPos, ident.EndPos);
                    variable.Outer = node.Outer;
                    Symbols.AddSymbol(variable.Name, variable);
                    (node.Outer as Struct).Members.Insert(index++, variable);
                }
                (node.Outer as Struct).Members.Remove(node);
            }

            return Success;
        }
Esempio n. 2
0
 public bool VisitNode(VariableDeclaration node)
 {
     return true;
 }