Beispiel #1
0
        private void handleUserDefinedTypeVariableReference(string variableName, object functionStackObject)
        {
            UserDefinedTypeVariableReference tempRef = (UserDefinedTypeVariableReference)functionStackObject;
            string objectName = tempRef.ObjectName;

            VariableNode objectVariable            = new VariableNode(objectName);
            UserDefinedTypeVariableDeclNode parent = null;

            if (symbolTable.doesChildExistAtScope(objectVariable))
            {
                Node localVar = symbolTable.getNode(objectVariable);
                if (localVar is VariableNode)
                {
                    VariableNode localVariableNode = (VariableNode)localVar;

                    if (localVariableNode.Parent is UserDefinedTypeVariableDeclNode)
                    {
                        parent = (UserDefinedTypeVariableDeclNode)localVariableNode.Parent;
                    }
                }
            }

            if (parent == null)
            {
                throw new Exception(string.Format("The user defined variable {0} does not have an accessible parent", variableName));
            }

            string className = parent.UserDefinedVariableTypeName;

            if (declaredClasses.ContainsKey(className))
            {
                UserDefinedTypeNode userDefinedTypeNode = declaredClasses[className];

                if (!userDefinedTypeNode.AllVariableNames.Contains(variableName))
                {
                    addError("the object [ " + className + "]   does not have a varible [" + variableName + "] defined as part of its instance");
                }

                VariableNode tempVariableNode = new VariableNode(variableName);

                if (!symbolTable.doesChildExistInHash(parent, tempVariableNode))
                {
                    symbolTable.addChild(tempVariableNode);
                }
            }
        }
Beispiel #2
0
        public override Node visitUserDefinedTypeDecl(JuliarParser.UserDefinedTypeDeclContext ctx)
        {
            UserDefinedTypeNode userDefinedTypeNode = new UserDefinedTypeNode();

            symbolTable.addLevel(ctx.userDefinedTypeName().Text);

            iterateWrapper(ctx, this, userDefinedTypeNode);

            if (declaredClasses.ContainsKey(userDefinedTypeNode.TypeName))
            {
                throw new Exception("class " + userDefinedTypeNode.TypeName + "already exist at current scope");
            }

            declaredClasses[userDefinedTypeNode.TypeName] = userDefinedTypeNode;

            symbolTable.popScope();

            return(userDefinedTypeNode);
        }
Beispiel #3
0
        private void addChildUserDefined(UserDefinedTypeNode child)
        {
            SymbolTableNode node  = scopeHash[currentScope.peek()];
            int             count = 0;

            foreach (Node childNode in node.children)
            {
                if (child.TypeName.Equals(((UserDefinedTypeNode)childNode).TypeName))
                {
                    count++;
                }
            }

            if (count > 0)
            {
                visitor.addError(string.format(IDENTIFIERTXT, child.TypeName));
                return;
            }

            scopeHash[currentScope.peek()].Children.Add(child);
        }