public AttributeNode(string name, NodeLocation location) : base(location)
 {
     Name           = name;
     ArrayIndexNode = null;
 }
 protected WarningAnnotationNoted(NodeLocation noteLocation)
 {
     NoteLocation = noteLocation;
 }
 public UnsupportedTypeError(NodeLocation pointerLocation)
 {
     PointerLocation = pointerLocation;
 }
 public BinaryOperationsNotAllowedInsideFloatExpression(NodeLocation pointerLocation)
 {
     PointerLocation = pointerLocation;
 }
 public UnsupportedOperationError(NodeLocation pointerLocation)
 {
     PointerLocation = pointerLocation;
 }
 public RedefinedIdentifierError(string identifier, NodeLocation noteLocation, NodeLocation pointerLocation) : base(noteLocation)
 {
     _identifier     = identifier;
     PointerLocation = pointerLocation;
 }
 public ArithmeticOperationOverflowError(NodeLocation pointerLocation)
 {
     PointerLocation = pointerLocation;
 }
 public ConstDefinitionsTemporaryNode(NodeLocation location, List <DeclarationNode> nodes) : base(location,
                                                                                                  nodes)
 {
 }
 public InstanceDeclarationsTemporaryNode(NodeLocation location, List <DeclarationNode> nodes) : base(
         location, nodes)
 {
 }
 public NameNode(NodeLocation location, string value) : base(location)
 {
     Value = value;
 }
 protected TemporaryNode(NodeLocation location, List <DeclarationNode> nodes) : base(location)
 {
     Nodes = nodes;
 }
 public InheritanceParentReferenceNode(string name, NodeLocation location) : base(name, location)
 {
 }
 public ReferenceNode(string name, NodeLocation location) : base(location)
 {
     Symbol    = null;
     Name      = name;
     PartNodes = new List <ReferencePartNode>();
 }
 public ArrayIndexNode(ExpressionNode expressionNode, NodeLocation location) : base(location)
 {
     ExpressionNode            = expressionNode;
     ExpressionNode.ParentNode = this;
 }
 public KeywordUsedAsNameError(string identifier, NodeLocation pointerLocation)
 {
     _identifier     = identifier;
     PointerLocation = pointerLocation;
 }
Exemplo n.º 16
0
        private void AddSymbol(Symbol symbol)
        {
            bool addSymbolToTable = true;

            symbol.Index = _nextSymbolIndex++;

            if (SymbolTable.ContainsKey(symbol.Path))
            {
                Symbol previousSymbol = SymbolTable[symbol.Path];

                ASTNode      node     = symbol.Node;
                NodeLocation location = node.Location;
                if (node is DeclarationNode declarationNode)
                {
                    location = declarationNode.NameNode.Location;
                }

                ASTNode      previousNode     = previousSymbol.Node;
                NodeLocation previousLocation = previousNode.Location;
                if (previousNode is DeclarationNode previousDeclarationNode)
                {
                    previousLocation = previousDeclarationNode.NameNode.Location;
                }

                symbol.Node.Annotations.Add(new RedefinedIdentifierError(symbol.Name, previousLocation, location));

                addSymbolToTable = false;
            }

            string[] keywords = { "break", "continue", "while" };
            if (keywords.Contains(symbol.Name.ToLower()))
            {
                if (symbol.Node is DeclarationNode declarationNode)
                {
                    symbol.Node.Annotations.Add(new KeywordUsedAsNameError(symbol.Name, declarationNode.NameNode.Location));
                }
                else
                {
                    throw new Exception();
                }
            }

            switch (symbol)
            {
            case FunctionSymbol functionSymbol:
                TypedSymbols.Add(functionSymbol);
                if (!functionSymbol.IsExternal)
                {
                    SymbolsWithInstructions.Add(functionSymbol);
                }
                break;

            case ITypedSymbol typedSymbol:
                TypedSymbols.Add(typedSymbol);
                break;

            case SubclassSymbol subclassSymbol:
                SubclassSymbols.Add(subclassSymbol);
                SymbolsWithInstructions.Add(subclassSymbol);
                break;

            case ClassSymbol classSymbol:
                _classSymbols.Add(classSymbol);
                break;
            }


            switch (symbol.Node)
            {
            case DeclarationNode declarationNode:
                declarationNode.Symbol = symbol;
                DeclarationNodes.Add(declarationNode);
                break;

            case ReferenceNode referenceNode:
                referenceNode.Symbol = symbol;
                break;

            case StringLiteralNode stringLiteralNode:
                stringLiteralNode.Symbol = (StringConstSymbol)symbol;
                break;
            }

            switch (symbol.Node)
            {
            case IArrayDeclarationNode arrayDeclarationNode:
                ArrayDeclarationNodes.Add(arrayDeclarationNode);
                break;

            case ConstDefinitionNode constDefinitionNode:
                ConstDefinitionNodes.Add(constDefinitionNode);
                break;
            }

            if (addSymbolToTable)
            {
                SymbolTable[symbol.Path] = symbol;
            }
        }
 protected ErrorAnnotationNoted(NodeLocation noteLocation)
 {
     NoteLocation = noteLocation;
 }
 public NamesNotMatchingCaseWiseWarning(NodeLocation noteLocation, string declaredName, string usedName) : base(noteLocation)
 {
     _declaredName = declaredName;
     _usedName     = usedName;
 }
 public InvalidBinaryOperationError(NodeLocation pointerLocation, NodeLocation leftLocation, NodeLocation rightLocation)
 {
     PointerLocation = pointerLocation;
     UnderlineLocations.Add(leftLocation);
     UnderlineLocations.Add(rightLocation);
 }
 protected NodeAnnotation()
 {
     PointerLocation    = null;
     UnderlineLocations = new List <NodeLocation>();
 }
 public DivideByZeroError(NodeLocation pointerLocation, NodeLocation underlineLocation)
 {
     PointerLocation = pointerLocation;
     UnderlineLocations.Add(underlineLocation);
 }
 public CannotInitializeConstWithValueOfDifferentTypeError(SymbolType expectedSymbolType, SymbolType actualSymbolType, NodeLocation pointerLocation, NodeLocation underlineLocation)
 {
     PointerLocation = pointerLocation;
     UnderlineLocations.Add(underlineLocation);
     _expectedSymbolType = expectedSymbolType;
     _actualSymbolType   = actualSymbolType;
 }
 public FloatDoesntSupportCompoundAssignments(NodeLocation pointerLocation)
 {
     PointerLocation = pointerLocation;
 }
 public ArgumentsCountDoesNotMatchError(string identifier, int parametersCount, int argumentsCount, NodeLocation noteLocation) : base(noteLocation)
 {
     _identifier      = identifier;
     _parametersCount = parametersCount;
     _argumentsCount  = argumentsCount;
 }
 public IncompatibleTypeAssignmentError(NodeLocation pointerLocation, string leftTypeName, string rightTypeName)
 {
     _leftTypeName   = leftTypeName;
     _rightTypeName  = rightTypeName;
     PointerLocation = pointerLocation;
 }
 public SymbolIsNotAFunctionError(string identifier, NodeLocation noteLocation) : base(noteLocation)
 {
     _identifier = identifier;
 }
 public InvalidOperandsToBinaryExpressionError(NodeLocation pointerLocation, string leftTypeName, string rightTypeName)
 {
     _leftTypeName   = leftTypeName;
     _rightTypeName  = rightTypeName;
     PointerLocation = pointerLocation;
 }
 public UnknownTypeNameError(string identifier, NodeLocation pointerLocation)
 {
     _identifier     = identifier;
     PointerLocation = pointerLocation;
 }
 public VarAssignmentNotAllowedHereError(NodeLocation pointerLocation)
 {
     PointerLocation = pointerLocation;
 }
 protected ReferencePartNode(NodeLocation location) : base(location)
 {
 }