Exemple #1
0
        private bool _tryParseCrossReference(MExpr expr, [NotNull] ISymbolView<Symbol> symbols, out Symbol symbol)
        {
            symbol = null;

            List<MExpr> elements;
            if (!expr.TryMatchHead(SymbolMExprSerializer.CrossReferenceHead, out elements))
                return false;

            var currentScope = symbols;
            for (var i = 0; i < elements.Count; i++)
            {
                var element = elements[i];
                string symbolName;
                if (!element.TryMatchStringAtom(out symbolName))
                    throw new ErrorMessageException(Message.Error(
                        string.Format("Symbolic reference must be consist only of symbol names. Found {0} {1} instead.", (element != null ? element.GetType().ToString() : ""), element),
                        element.Position, MessageClasses.SymbolNotResolved));
                if (!currentScope.TryGet(symbolName, out symbol))
                    throw new ErrorMessageException(
                       Message.Error(
                           String.Format("Cannot find symbol {0} referred to by delcaration {1}.", symbolName, expr),
                           expr.Position, MessageClasses.SymbolNotResolved));

                // If this is not the last element in the sequence, it must refer to a namespace symbol
                if (i < elements.Count - 1)
                {
                    var errors = new List<Message>();
                    var nsSym = NamespaceSymbol.UnwrapNamespaceSymbol(symbol, element.Position, _messageSink, errors);

                    Message abortMessage = null;
                    foreach (var error in errors)
                    {
                        if (abortMessage == null)
                            abortMessage = error;
                        else
                            _messageSink.ReportMessage(error);
                    }

                    if (abortMessage != null)
                        throw new ErrorMessageException(abortMessage);

                    // Impossible. Condition required to convey that fact to null-analysis
                    if (nsSym == null)
                        throw new PrexoniteException("Namespace symbol was expected to exist. Internal error (\"impossible condition\").");
                    currentScope = nsSym.Namespace;
                }
            }
            if (symbol == null)
                throw new ErrorMessageException(Message.Error(
                    Resources.SymbolMExprParser_EmptySymbolicReference, expr.Position,
                    MessageClasses.SymbolNotResolved));

            return true;
        }
Exemple #2
0
 public ClosureConversionResult(Dictionary <string, MExpr> table, MExpr main)
 {
     FunctionTable = table;
     Main          = main;
 }