예제 #1
0
        protected override void VisitIdentifierSyntax(IdentifierSyntax pNode)
        {
            if (CurrentType != null || !_unit.IsTypeDefined(Namespace, pNode.Value))
            {
                //Normal identifier, continue as usual
                if (!IsVariableDefined(pNode.Value, out SmallType type))
                {
                    if (CurrentType == null)
                    {
                        //Generate a slightly different error message if we are in a struct
                        //This can happen if we forget self
                        if (Struct != null)
                        {
                            CompilerErrors.IdentifierNotDeclaredSelf(pNode, pNode.Span);
                        }
                        else
                        {
                            CompilerErrors.IdentifierNotDeclared(pNode, pNode.Span);
                        }
                    }
                    else
                    {
                        CompilerErrors.IdentifierNotDeclared(CurrentType, pNode, pNode.Span);
                    }
                }
                else
                {
                    pNode.SetType(type);
                }
            }
            else
            {
                //Shared or enum value
                var result = _unit.FromString(Namespace, pNode.Value, out SmallType t);
                switch (result)
                {
                case Compiler.FindResult.Found:
                    pNode.SetType(t);
                    break;

                case Compiler.FindResult.IncorrectScope:
                    CompilerErrors.TypeNotInScope(pNode.Value, pNode.Span);
                    break;

                case Compiler.FindResult.NotFound:
                    CompilerErrors.UndeclaredType(pNode.Value, pNode.Span);
                    break;
                }
            }
        }