//public override void EnterArgumentWithoutName([NotNull] SBP.ArgumentWithoutNameContext context)
        //{
        //    m_argumentIndex = m_expressionData.Peek().Count;
        //}

        //public override void ExitArgumentWithoutName([NotNull] SBP.ArgumentWithoutNameContext context)
        //{
        //    m_expressionData.Peek().Peek().ArgumentIndex = m_argumentIndex;
        //}

        public override void ExitReferenceArgument([NotNull] SBP.ReferenceArgumentContext context)
        {
            string name    = context.children[1].GetText();
            string refType = context.children[0].GetText();

            m_expressionData.Push(SBExpressionData.CreateIdentifier(name, refType));
        }
Пример #2
0
        private SBExpressionData ResolveQualifiedType(string identifier, bool reportUnresolved = false, IToken token = null)
        {
            if (identifier.Contains('.'))
            {
                string[] parts = identifier.Split('.');
                int c = parts.Length;

                SBExpressionData result = this.ResolveSingleIdentifierType(parts[0], reportUnresolved, token);
                if (result != null)
                {
                    for (int i = 1; i < c; i++)
                    {
                        result = this.ResolveDotIdentifier(result, SBExpressionData.CreateIdentifier(parts[i], token: token));
                        if (result == null)
                        {
                            return null;
                        }
                    }
                    if (result != null)
                    {
                        return result;
                    }
                }
            }
            else
            {
                return this.ResolveSingleIdentifierType(identifier, reportUnresolved, token);
            }

            return null;
        }
Пример #3
0
 public override void ExitExpDotIdentifier([NotNull] SBP.ExpDotIdentifierContext context)
 {
     var left = m_expressionData.Pop();
     left = this.ResolveIfIdentifier(left, true);
     if (left.IsUnresolvedIdentifier || left.IsError())
     {
         m_expressionData.Push(new SBExpressionData(
             SBExpressionType.OperationError, "Error parsing 'dot' operation.", context.GetText(), new TokenOrSection(context.Start, context.Stop, context.GetText())));
     }
     else
     {
         var child = context.GetChild(2) as TerminalNodeImpl;
         var identifier = SBExpressionData.CreateIdentifier(child.GetText(), token: child.Payload as CommonToken);
         var result = this.ResolveDotIdentifier(left, identifier);
         if (result == null)
         {
             var payload = context.GetChild(2).Payload as CommonToken;
             m_errors.SymanticError(payload.Line, payload.StartIndex, false, $"Unknown identifier: '{identifier.Value as string}'.");
             result = new SBExpressionData(
                 SBExpressionType.OperationError, "Error parsing 'dot' operation.", context.GetText(), new TokenOrSection(context.Start, context.Stop, context.GetText()));
         }
         else if (result.IsError())
         {
             var payload = context.GetChild(2).Payload as CommonToken;
             m_errors.SymanticError(payload.Line, payload.StartIndex, false, result.Argument);
         }
         m_expressionData.Push(result);
     }
 }
Пример #4
0
        private SBExpressionData ResolveQualifiedIdentifier(string identifier, bool inFunctionScope, bool reportUnresolved = false, IToken token = null)
        {
            if (String.IsNullOrWhiteSpace(identifier)) throw new ArgumentException("Empty identifier string.");

            if (identifier.Contains('.'))
            {
                string[] parts = identifier.Split('.');
                int c = parts.Length;

                SBExpressionData result = this.ResolveSingleIdentifier(parts[0], inFunctionScope, reportUnresolved, token);
                if (result != null)
                {
                    for (int i = 1; i < c; i++)
                    {
                        result = this.ResolveDotIdentifier(result, SBExpressionData.CreateIdentifier(parts[i], token: token));
                        if (result == null)
                        {
                            return null;
                        }
                    }
                }
                return result;
            }
            else
            {
                return this.ResolveSingleIdentifier(identifier, inFunctionScope, reportUnresolved, token);
            }
        }
Пример #5
0
        private SBExpressionData ResolveSingleIdentifierType(string identifier, bool reportUnresolved = false, IToken token = null)
        {
            IIdentifierInfo foundIdentifier = null;

            if (m_file != null)
            {
                var identifiers = m_file.LookupIdentifier(identifier);
                if (identifiers != null)
                {
                    if (identifiers.Count > 1)
                    {
                        throw new ParsingErrorException((token != null) ? token.Line : -1, identifier, "More than one alternative. ");
                    }
                    return this.IdentifierToExpressionData(identifiers[0], token);
                }

                foundIdentifier = this.TryGetFileElementInScope(m_file?.Usings, identifier);    // File elements can also act as types.
                if (foundIdentifier != null)
                {
                    return this.IdentifierToExpressionData(foundIdentifier, token);
                }

                #region TBD
                foreach (var nsUsing in m_file.ListResolvedNamespaceUsings())
                {
                    var foundViaUsing = this.ResolveDotIdentifier(nsUsing, SBExpressionData.CreateIdentifier(identifier, token: token));
                    if (foundViaUsing != null)
                    {
                        return foundViaUsing;
                    }
                }
                #endregion
            }
            if (m_addonManager != null)
            {
                foundIdentifier = m_addonManager.Lookup(m_file?.Usings, identifier);
                if (foundIdentifier != null)
                {
                    return this.IdentifierToExpressionData(foundIdentifier, token);
                }
            }

            if (reportUnresolved)
            {
                if (token != null)
                {
                    m_errors.UnresolvedType(token.Line, token.Column, identifier);
                }
                else
                {
                    m_errors.UnresolvedType(-1, -1, identifier);
                }
            }
            return null;
        }
Пример #6
0
 // Checks if the current context is an identifier, and pushes it to the expression stack.
 private void PushIfIdentifier(ParserRuleContext context)
 {
     if (context.ChildCount == 1)
     {
         var child = context.GetChild(0) as TerminalNodeImpl;
         if (child != null && child.Payload.Type == SBP.IDENTIFIER)
         {
             m_expressionData.Push(SBExpressionData.CreateIdentifier(context.GetText(), token: child.Payload as CommonToken));
         }
     }
 }
 public override void ExitPrimary([NotNull] SBP.PrimaryContext context)
 {
     if (context.Start.Type == Grammar.StepBro.IDENTIFIER)
     {
         m_expressionData.Push(SBExpressionData.CreateIdentifier(context.GetText(), token: context.Start));
     }
     else if (context.Start.Type == Grammar.StepBro.THIS)
     {
         var thisProperty = Expression.Property(
             m_currentProcedure.ContextReferenceInternal,
             typeof(IScriptCallContext).GetProperty(nameof(IScriptCallContext.This)));
         m_expressionData.Push(new SBExpressionData(
                                   HomeType.Immediate,
                                   SBExpressionType.PropertyReference,
                                   new TypeReference(typeof(IProcedureThis)),
                                   thisProperty,
                                   token: context.Start));
     }
 }
Пример #8
0
 public override void ExitKeyword([NotNull] SBP.KeywordContext context)
 {
     m_expressionData.Push(SBExpressionData.CreateIdentifier(context.GetText(), token: context.Start as CommonToken));
 }
Пример #9
0
        private SBExpressionData ResolveSingleIdentifier(string identifier, bool inFunctionScope, bool reportUnresolved = false, IToken token = null)
        {
            IIdentifierInfo foundIdentifier = null;
            if (inFunctionScope)
            {
                foundIdentifier = this.TryGetLocalVariable(identifier);
                if (foundIdentifier != null) goto returnFound;
                foundIdentifier = this.TryGetProcedureParameter(identifier);
                if (foundIdentifier != null) goto returnFound;

                if (m_addonManager != null)
                {
                    foundIdentifier = m_addonManager.Lookup(m_file?.Usings, identifier);
                    if (foundIdentifier != null)
                    {
                        return this.IdentifierToExpressionData(foundIdentifier, token);
                    }
                    var foundScriptUtilsAccess = this.ResolveDotIdentifierTypeReference(s_ScriptUtilsTypeData, SBExpressionData.CreateIdentifier(identifier, token: token));
                    if (foundScriptUtilsAccess != null)
                    {
                        return foundScriptUtilsAccess;
                    }
                }
            }
            if (m_file != null)
            {
                var identifiers = m_file.LookupIdentifier(identifier);
                if (identifiers != null)
                {
                    if (identifiers.Count > 1)
                    {
                        throw new ParsingErrorException((token != null) ? token.Line : -1, identifier, "More than one alternative. ");
                    }
                    foundIdentifier = identifiers[0];
                }
                if (foundIdentifier == null)
                {
                    foundIdentifier = this.TryGetFileElementInScope(m_file?.Usings, identifier);
                }
            }

        returnFound:
            if (foundIdentifier != null)
            {
                return this.IdentifierToExpressionData(foundIdentifier, token);
            }

            var foundType = this.ResolveSingleIdentifierType(identifier, false, token);
            if (foundType != null)
            {
                return foundType;
            }

            if (reportUnresolved)
            {
                m_errors.UnresolvedIdentifier(token, identifier);
            }
            return new SBExpressionData(SBExpressionType.UnknownIdentifier, "", identifier, token);
        }