public PrototypeDefinitionNode(NodeLocation location, NameNode nameNode, InheritanceParentReferenceNode inheritanceParentReferenceNode,
                                List <StatementNode> bodyNodes) : base(location, "prototype", nameNode, inheritanceParentReferenceNode)
 {
     foreach (var node in bodyNodes)
     {
         node.ParentNode = this;
     }
     BodyNodes = bodyNodes;
 }
예제 #2
0
        private Symbol Resolve(SubclassSymbol subclassSymbol)
        {
            SubclassNode symbolNode = (SubclassNode)subclassSymbol.Node;
            InheritanceParentReferenceNode parentReferenceNode = symbolNode.InheritanceParentReferenceNode;

            if (_resolvedSymbolsCurrentIteration.Contains(subclassSymbol))
            {
                parentReferenceNode.Annotations.Add(new InfiniteInheritanceReferenceLoopError());
                return(null);
            }

            if (_resolvedSymbols.Contains(subclassSymbol))
            {
                return(subclassSymbol.BaseClassSymbol);
            }

            _resolvedSymbolsCurrentIteration.Add(subclassSymbol);
            _resolvedSymbols.Add(subclassSymbol);

            if (parentReferenceNode.PartNodes.Count > 0)
            {
                // TODO it's impossible scenario for current grammar
                parentReferenceNode.Annotations.Add(new NotClassOrPrototypeReferenceError());
                return(null);
            }

            parentReferenceNode.Symbol = GetSymbol(parentReferenceNode.Name);

            switch (parentReferenceNode.Symbol)
            {
            case null:
                parentReferenceNode.Annotations.Add(new UndeclaredIdentifierError(parentReferenceNode.Name));
                break;

            case SubclassSymbol parentSubclassSymbol:
                subclassSymbol.InheritanceParentSymbol = parentSubclassSymbol;
                subclassSymbol.BaseClassSymbol         = (ClassSymbol)Resolve(parentSubclassSymbol);
                break;

            case ClassSymbol classSymbol:
                subclassSymbol.InheritanceParentSymbol = classSymbol;
                subclassSymbol.BaseClassSymbol         = classSymbol;
                break;

            default:
                parentReferenceNode.Annotations.Add(new NotClassOrPrototypeReferenceError());
                break;
            }

            if (parentReferenceNode.Symbol != null)
            {
                DeclarationNode declarationNode = (DeclarationNode)parentReferenceNode.Symbol.Node;
                declarationNode.Usages.Add(parentReferenceNode);
            }

            return(subclassSymbol.BaseClassSymbol);
        }
 public InstanceDefinitionNode(NodeLocation location, NameNode nameNode, InheritanceParentReferenceNode inheritanceParentReferenceNode,
                               List <StatementNode> bodyNodes, bool definedWithoutBody) : base(location, "instance", nameNode, inheritanceParentReferenceNode)
 {
     foreach (var node in bodyNodes)
     {
         node.ParentNode = this;
     }
     BodyNodes          = bodyNodes;
     DefinedWithoutBody = definedWithoutBody;
 }
예제 #4
0
        public override ASTNode VisitInstanceDef([NotNull] DaedalusParser.InstanceDefContext instanceDefContext)
        {
            NameNode nameNode = new NameNode(GetLocation(instanceDefContext.nameNode()), instanceDefContext.nameNode().GetText());

            DaedalusParser.ParentReferenceContext parentReferenceContext         = instanceDefContext.parentReference();
            InheritanceParentReferenceNode        inheritanceParentReferenceNode = new InheritanceParentReferenceNode(parentReferenceContext.GetText(), GetLocation(parentReferenceContext));

            _inheritanceReferenceNodes.Add(inheritanceParentReferenceNode);
            List <StatementNode> statementNodes = GetStatementNodes(instanceDefContext.statementBlock());

            return(new InstanceDefinitionNode(GetLocation(instanceDefContext), nameNode, inheritanceParentReferenceNode, statementNodes, definedWithoutBody: false));
        }
예제 #5
0
        public override ASTNode VisitPrototypeDef([NotNull] DaedalusParser.PrototypeDefContext prototypeDefContext)
        {
            NameNode nameNode = new NameNode(GetLocation(prototypeDefContext.nameNode()), prototypeDefContext.nameNode().GetText());

            DaedalusParser.ParentReferenceContext parentReferenceContext         = prototypeDefContext.parentReference();
            InheritanceParentReferenceNode        inheritanceParentReferenceNode = new InheritanceParentReferenceNode(parentReferenceContext.GetText(), GetLocation(parentReferenceContext));

            _inheritanceReferenceNodes.Add(inheritanceParentReferenceNode);
            List <StatementNode> statementNodes = GetStatementNodes(prototypeDefContext.statementBlock());

            return(new PrototypeDefinitionNode(GetLocation(prototypeDefContext), nameNode, inheritanceParentReferenceNode, statementNodes));
        }
예제 #6
0
        private InstanceDeclarationsTemporaryNode GetInstanceDeclarationsTemporaryNode(DaedalusParser.InstanceDeclContext instanceDeclContext)
        {
            DaedalusParser.ParentReferenceContext parentReferenceContext         = instanceDeclContext.parentReference();
            InheritanceParentReferenceNode        inheritanceParentReferenceNode = new InheritanceParentReferenceNode(parentReferenceContext.GetText(), GetLocation(parentReferenceContext));

            _inheritanceReferenceNodes.Add(inheritanceParentReferenceNode);

            List <DeclarationNode> instanceDeclarationNodes = new List <DeclarationNode>();

            foreach (DaedalusParser.NameNodeContext nameNodeContext in instanceDeclContext.nameNode())
            {
                NameNode nameNode = new NameNode(GetLocation(nameNodeContext), nameNodeContext.GetText());
                instanceDeclarationNodes.Add(new InstanceDefinitionNode(GetLocation(instanceDeclContext), nameNode, inheritanceParentReferenceNode, new List <StatementNode>(), definedWithoutBody: true));
            }

            return(new InstanceDeclarationsTemporaryNode(GetLocation(instanceDeclContext), instanceDeclarationNodes));
        }
 protected SubclassNode(NodeLocation location, string type, NameNode nameNode, InheritanceParentReferenceNode inheritanceParentReferenceNode) : base(location, type, nameNode)
 {
     inheritanceParentReferenceNode.ParentNode = this;
     InheritanceParentReferenceNode            = inheritanceParentReferenceNode;
 }