Example #1
0
 public AstUnresolved(ISourcePosition position, string id) : base(position,PCall.Get)
 {
     if (id == null)
         throw new ArgumentNullException("id");
     
     _id = id;
 }
Example #2
0
 public AstWhileLoop(ISourcePosition position, AstBlock parentBlock, bool isPrecondition = true,
     bool isPositive = true)
     : base(position,parentBlock)
 {
     IsPrecondition = isPrecondition;
     IsPositive = isPositive;
 }
Example #3
0
 public AstTryCatchFinally(ISourcePosition p, AstBlock lexicalScope)
     : base(p, lexicalScope)
 {
     TryBlock = new AstScopedBlock(p, this);
     CatchBlock = new AstScopedBlock(p, TryBlock);
     FinallyBlock = new AstScopedBlock(p, TryBlock);
 }
Example #4
0
 public AstActionBlock(ISourcePosition position, AstBlock parent, AstAction action)
     : base(position,parent)
 {
     if (action == null)
         throw new ArgumentNullException("action");
     Action = action;
 }
Example #5
0
        public static AstExpr ExprFor(this IAstFactory factory, ISourcePosition position, QualifiedId qualifiedId,
            ISymbolView<Symbol> scope)
        {
            var currentScope = scope;
            for (var i = 0; i < qualifiedId.Count; i++)
            {
                // Lookup name part
                Symbol sym;
                if (!currentScope.TryGet(qualifiedId[i], out sym))
                {
                    return new AstUnresolved(position, qualifiedId[i]);
                }

                var expr = factory.ExprFor(position, sym);

                // last part of qualified ID does not need to be a namespace, so we're done here
                if (i == qualifiedId.Count - 1)
                    return expr;

                var nsUsage = expr as AstNamespaceUsage;
                if (nsUsage == null)
                {
                    factory.ReportMessage(Message.Error(
                        string.Format(Resources.Parser_NamespaceExpected, qualifiedId[i], sym),
                        position, MessageClasses.NamespaceExcepted));
                    return factory.IndirectCall(position, factory.Null(position));
                }

                currentScope = nsUsage.Namespace;
            }

            throw new InvalidOperationException("Failed to resolve qualified Id (program control should never reach this point)");
        }
Example #6
0
 public static AstGetSet Call(this IAstFactory factory, ISourcePosition position, EntityRef entity,
                              PCall call = PCall.Get, params AstExpr[] arguments)
 {
     var c = factory.IndirectCall(position, factory.Reference(position, entity), call);
     c.Arguments.AddRange(arguments);
     return c;
 }
Example #7
0
 public void SetUp()
 {
     _position = new SourcePosition("MExprTests.cs",20,62);
     _symbols = SymbolStore.Create();
     _existing = new Dictionary<Symbol, QualifiedId>();
     _otherPosition = new SourcePosition("PrexoniteTests.csproj",33,77);
     _symbolParser = new SymbolMExprParser(_symbols, ConsoleSink.Instance);
 }
Example #8
0
 internal AstLoopBlock(ISourcePosition p, [NotNull] AstBlock parentNode = null, string uid = null, string prefix = null)
     : base(p, parentNode, uid: uid, prefix: prefix)
 {
     //See other ctor!
     _continueLabel = CreateLabel(ContinueWord);
     _breakLabel = CreateLabel(BreakWord);
     _beginLabel = CreateLabel(BeginWord);
 }
Example #9
0
 public AstForLoop(ISourcePosition position, AstBlock parentBlock)
     : this(position, new AstScopedBlock(
         position,
         new AstScopedBlock(
             position, 
             parentBlock, prefix: "init"),
         prefix:"next"))
 {
 }
Example #10
0
 public AstUnaryOperator(ISourcePosition position, UnaryOperator op, AstExpr operand)
     : base(position)
 {
     if (operand == null)
         throw new ArgumentNullException("operand");
     
     _operator = op;
     _operand = operand;
 }
Example #11
0
 public AstCondition(ISourcePosition p, AstBlock parentBlock, AstExpr condition, bool isNegative = false)
     : base(p)
 {
     IfBlock = new AstScopedBlock(p,parentBlock,prefix: "if");
     ElseBlock = new AstScopedBlock(p,parentBlock,prefix:"else");
     if (condition == null)
         throw new ArgumentNullException("condition");
     Condition = condition;
     IsNegative = isNegative;
 }
Example #12
0
 public static bool SourcePositionEquals(this ISourcePosition positionA,
     ISourcePosition positionB)
 {
     if (ReferenceEquals(positionA, null) && ReferenceEquals(positionB, null))
         return true;
     else if (ReferenceEquals(positionA, null) || ReferenceEquals(positionB, null))
         return false;
     else
         return positionA.Line == positionB.Line
             && positionA.Column == positionB.Column
                 && positionA.File.Equals(positionB.File, StringComparison.Ordinal);
 }
Example #13
0
        public AstStringConcatenation(ISourcePosition position, AstGetSet simpleConcatPrototype, AstGetSet multiConcatPrototype, params AstExpr[] arguments)
            : base(position)
        {
            if (simpleConcatPrototype == null)
                throw new ArgumentNullException("simpleConcatPrototype");
            if (multiConcatPrototype == null)
                throw new ArgumentNullException("multiConcatPrototype");
            
            if (arguments == null)
                arguments = new AstExpr[] {};

            _arguments.AddRange(arguments);
            _simpleConcatPrototype = simpleConcatPrototype;
            _multiConcatPrototype = multiConcatPrototype;
        }
Example #14
0
 public static bool TryCreateConstant(
     CompilerTarget target,
     ISourcePosition position,
     PValue value,
     out AstExpr expr)
 {
     expr = null;
     if (value.Type is ObjectPType)
         target.Loader.Options.ParentEngine.CreateNativePValue(value.Value);
     if (value.Type is IntPType 
         || value.Type is RealPType 
         || value.Type is BoolPType 
         || value.Type is StringPType 
         || value.Type is NullPType 
         || _isModuleName(value))
         expr = new AstConstant(position.File, position.Line, position.Column, value.Value);
     else //Cannot represent value in a constant instruction
         return false;
     return true;
 }
Example #15
0
 public AstExpand(ISourcePosition position, EntityRef entity, PCall call) : base(position, call)
 {
     _entity = entity;
 }
Example #16
0
 protected virtual AstExpr CreatePrefix(ISourcePosition position,
     IEnumerable<AstExpr> clauses)
 {
     throw new NotSupportedException(string.Format(Resources.AstLazyLogical_CreatePrefixMustBeImplementedForPartialApplication, GetType().Name));
 }
Example #17
0
        public static AstExpr CreateDisjunction(ISourcePosition position,
            IEnumerable<AstExpr> clauses)
        {
            var cs = clauses.ToList();

            if (cs.Count == 0)
            {
                return new AstConstant(position.File, position.Line, position.Column, true);
            }
            else if (cs.Count == 1)
            {
                return cs[0];
            }
            else
            {
                var disj = new AstLogicalOr(position.File, position.Line, position.Column, cs[0],
                    cs[1]);
                foreach (var clause in cs.Skip(2))
                    disj.AddExpression(clause);
                return disj;
            }
        }
Example #18
0
 protected AstTypeExpr(ISourcePosition position) : base(position)
 {
 }
Example #19
0
 protected override AstExpr CreatePrefix(ISourcePosition position,
     IEnumerable<AstExpr> clauses)
 {
     return CreateDisjunction(position, clauses);
 }
Example #20
0
 protected AstNode([NotNull] ISourcePosition position)
 {
     if (position == null)
         throw new ArgumentNullException("position");
     _position = position;
 }
Example #21
0
 public AstCreateClosure(ISourcePosition position, EntityRef.Function implementation)
     : base(position)
 {
     _implementation = implementation;
 }
Example #22
0
 protected override AstGetSet CreateNullNode(ISourcePosition position)
 {
     return Parser._NullNode(position);
 }
Example #23
0
 /// <summary>
 /// This constructor should only be called from the public constructor.
 /// It is just here to wire up the loop block to be a sub block of the 
 /// initialization and next iteration blocks. (So that symbols declared in 
 /// initialization are available in the loop body)
 /// </summary>
 /// <param name="position">The source position for this node and all block nodes.</param>
 /// <param name="nextBlock">The block reserved for the "next iteration" code. 
 /// It's parent block must be the initialization block.</param>
 private AstForLoop(ISourcePosition position, AstScopedBlock nextBlock)
     : base(position, nextBlock)
 {
     _initialize = (AstScopedBlock)nextBlock.LexicalScope;
     _nextIteration = nextBlock;
 }
Example #24
0
 public AstForeachLoop(ISourcePosition position, AstBlock parentBlock)
     : base(position, parentBlock)
 {
 }
Example #25
0
 public AstNamespaceUsage(ISourcePosition position, PCall call, [NotNull] Namespace @namespace) : base(position, call)
 {
     if (@namespace == null)
         throw new ArgumentNullException("namespace");
     _namespace = @namespace;
 }
Example #26
0
 private static AstGetSet _assembleImplCall(MacroContext context, SymbolEntry implementationSymbolEntry,
                                            ISourcePosition position)
 {
     var internalId = context.CreateConstant(implementationSymbolEntry.InternalId);
     var interpretation = implementationSymbolEntry.Interpretation.ToExpr(position);
     var moduleNameOpt = context.CreateConstantOrNull(implementationSymbolEntry.Module);
     var implCall = context.Factory.IndirectCall(context.Invocation.Position,
                                                 context.Factory.Reference(context.Invocation.Position,
                                                                           EntityRef.Command.Create(
                                                                               Impl.Alias)));
     implCall.Arguments.Add(internalId);
     implCall.Arguments.Add(interpretation);
     implCall.Arguments.Add(moduleNameOpt);
     return implCall;
 }
Example #27
0
 protected AstGetSetImplBase(ISourcePosition position, PCall call)
     : base(position)
 {
     _call = call;
     _proxy = new ArgumentsProxy(new List<AstExpr>());
 }
Example #28
0
 protected override AstGetSet CreateNullNode(ISourcePosition position)
 {
     return IndirectCall(position, Null(position));
 }
Example #29
0
 public void ReportMessage(MessageSeverity severity, string message,
     ISourcePosition position = null)
 {
     position = position ?? _invocation.Position;
     _session.Target.Loader.ReportMessage(Message.Create(severity, message, position,null));
 }
Example #30
0
 internal AstLoop(ISourcePosition p, AstBlock parentBlock)
     : base(p)
 {
     _block = new AstLoopBlock(p, parentBlock, prefix:"body");
 }