Example #1
0
 protected virtual T VisitConstDefinition(ConstDefinitionNode node)
 {
     Visit(node.TypeNameNode);
     Visit(node.NameNode);
     Visit(node.RightSideNode);
     return(DefaultResult);
 }
Example #2
0
        private void BuildConst(ConstDefinitionNode constDefinitionNode, bool buildArray = false)
        {
            string constName     = constDefinitionNode.NameNode.Value;
            string constTypeName = constDefinitionNode.TypeNameCapitalized;

            BlockSymbol parentBlockSymbol = GetParentBlockSymbol(constDefinitionNode);
            ConstSymbol constSymbol       = buildArray ? new ConstArraySymbol(parentBlockSymbol, constTypeName, constName, constDefinitionNode) : new ConstSymbol(parentBlockSymbol, constTypeName, constName, constDefinitionNode);

            AddSymbol(constSymbol);
        }
Example #3
0
        protected override NodeValue VisitConstDefinition(ConstDefinitionNode node)
        {
            node.RightSideValue = Visit(node.RightSideNode);
            if (node.RightSideValue is UndefinedValue)
            {
                return(null);
            }

            CheckValueType(node);
            return(null);
        }
Example #4
0
        private void CheckValueType(ConstDefinitionNode node)
        {
            SymbolType expectedType  = node.Symbol.BuiltinType;
            SymbolType actualType    = NodeValueToBuiltinType(node.RightSideValue);
            ASTNode    rightSideNode = node.RightSideNode
            ;

            try
            {
                CheckType(expectedType, actualType);
            }
            catch (IncompatibleTypesException)
            {
                rightSideNode.Annotations.Add(new CannotInitializeConstWithValueOfDifferentTypeError(expectedType, actualType, node.NameNode.Location, rightSideNode.Location));//+
            }
        }
Example #5
0
        private ConstDefinitionsTemporaryNode GetConstDefinitionsTemporaryNode(DaedalusParser.ConstDefContext constDefContext)
        {
            NameNode typeNameNode = new NameNode(GetLocation(constDefContext.dataType()), constDefContext.dataType().GetText());

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

            foreach (IParseTree childContext in constDefContext.children)
            {
                if (childContext is DaedalusParser.ConstValueDefContext constValueDefContext)
                {
                    DaedalusParser.NameNodeContext nameNodeContext = constValueDefContext.nameNode();
                    NameNode            nameNode            = new NameNode(GetLocation(nameNodeContext), nameNodeContext.GetText());
                    ExpressionNode      rightSideNode       = (ExpressionNode)Visit(constValueDefContext.constValueAssignment().expression());
                    ConstDefinitionNode constDefinitionNode = new ConstDefinitionNode(GetLocation(constValueDefContext),
                                                                                      typeNameNode, nameNode, rightSideNode);
                    _constDefinitionNodes.Add(constDefinitionNode);
                    constDefinitionNodes.Add(constDefinitionNode);
                }
                else if (childContext is DaedalusParser.ConstArrayDefContext constArrayDefContext)
                {
                    DaedalusParser.NameNodeContext nameNodeContext = constArrayDefContext.nameNode();
                    NameNode       nameNode      = new NameNode(GetLocation(nameNodeContext), nameNodeContext.GetText());
                    ExpressionNode arraySizeNode = (ExpressionNode)VisitArraySize(constArrayDefContext.arraySize());

                    List <ExpressionNode> elementNodes = new List <ExpressionNode>();
                    foreach (DaedalusParser.ExpressionContext expressionContext in constArrayDefContext.constArrayAssignment().expression())
                    {
                        elementNodes.Add((ExpressionNode)Visit(expressionContext));
                    }

                    ConstArrayDefinitionNode constArrayDefinitionNode =
                        new ConstArrayDefinitionNode(GetLocation(nameNodeContext), typeNameNode, nameNode, arraySizeNode,
                                                     elementNodes);
                    _arrayDeclarationNodes.Add(constArrayDefinitionNode);
                    constDefinitionNodes.Add(constArrayDefinitionNode);
                }
            }
            return(new ConstDefinitionsTemporaryNode(GetLocation(constDefContext), constDefinitionNodes));
        }
Example #6
0
        /*
         * Uninitialized = -1,
         * Void = 0,
         * Float = 1,
         * Int = 2,
         * String = 3,
         * Class = 4,
         * Func = 5,
         * Prototype = 6,
         * Instance = 7,
         */

        protected override void VisitConstDefinition(ConstDefinitionNode node)
        {
        }
Example #7
0
 protected override void VisitConstDefinition(ConstDefinitionNode constDefinitionNode)
 {
     BuildConst(constDefinitionNode);
 }
 protected virtual void VisitConstDefinition(ConstDefinitionNode node)
 {
     Visit(node.TypeNameNode);
     Visit(node.NameNode);
     Visit(node.RightSideNode);
 }