Пример #1
0
        public void Visit(DeclarationNode node)
        {
            // Ensure declaration doesn't duplicate another declaration in the current scope.
            Scope           scope        = _scopes.GetScope(node).Scope;
            DeclarationNode previousNode = scope.Variables.Find(existingNode => node.Name == existingNode.Name && node != existingNode);

            if (previousNode != null)
            {
                _errors.AddError($"Duplicate declaration {node.Name}", node);
            }
        }
Пример #2
0
        public void Visit(IdentifierParseNode node)
        {
            ShouldReplace = true;

            NodeScopeInfo   nodeScopeInfo = _scopeManager.GetScope(node);
            DeclarationNode?decl          = nodeScopeInfo.Scope.FindNearestDeclaration(node.Name, nodeScopeInfo.DeclarationIndex);

            if (decl != null)
            {
                NewNode = UpdateSymbolMap(new VariableNode(decl), node);
                return;
            }

            if (_semanticModule.EnumInfo.TryGetValue(node.Name, out EnumDeclarationInfo identifierInfo))
            {
                NewNode = UpdateSymbolMap(new EnumValueNode(identifierInfo.Declaration), node);
                return;
            }

            ShouldReplace = false;
            _errors.AddError($"Undeclared identifier {node.Name}", node);
        }
Пример #3
0
 private void DetermineLifetimeFromDeclaration(DeclarationNode declarationNode)
 {
     Lifetime = _scopeManager.GetScope(declarationNode).Scope;
 }