public FunctionDeclarationNode(SourcePosition pos, List<Node> parameters, String functionName, Node body)
     : base(pos)
 {
     this.Name = functionName;
     this.parameters = parameters;
     this.body = body;
 }
Пример #2
0
 public IfNode(SourcePosition pos, Node testCondition, Node thenBlock, Node elseBlock)
     : base(pos)
 {
     this.testCondition = testCondition;
     this.thenBlock = thenBlock;
     this.elseBlock = elseBlock;
 }
Пример #3
0
 public TryCatchFinallyNode(SourcePosition pos, BlockNode tryBlock, CatchNode catchNode, BlockNode finallyBlock)
     : base(pos)
 {
     this.tryBlock = tryBlock;
     this.catchNode = catchNode;
     this.finallyBlock = finallyBlock;
 }
Пример #4
0
 public void TestMerge()
 {
     SourcePosition loc1 = new SourcePosition(0, 1, 1);
     SourcePosition loc2 = new SourcePosition(2, 1, 3);
     SourcePosition loc3 = new SourcePosition(5, 2, 6);
     SourcePosition loc4 = new SourcePosition(6, 1, 7);
     SourcePosition loc5 = new SourcePosition(9, 2, 14);
     Assert.AreEqual(SourceRange.Unknown, SourceRange.Merge());
     Assert.AreEqual(SourceRange.Unknown, SourceRange.Merge(null));
     Assert.AreEqual(SourceRange.Unknown, SourceRange.Merge(SourceRange.Unknown));
     Assert.AreEqual(SourceRange.Unknown, SourceRange.Merge(SourceRange.Unknown, SourceRange.Unknown));
     Assert.AreEqual(new SourceRange(loc1), SourceRange.Merge(SourceRange.Unknown, new SourceRange(loc1)));
     Assert.AreEqual(new SourceRange(loc1),
         SourceRange.Merge(SourceRange.Unknown, new SourceRange(loc1), SourceRange.Unknown, new SourceRange(loc1)));
     Assert.AreEqual(new SourceRange(loc1, loc5),
         SourceRange.Merge(new SourceRange(loc3, loc5), SourceRange.Unknown, new SourceRange(loc1)));
     Assert.AreEqual(new SourceRange(loc1, loc5),
         SourceRange.Merge(new SourceRange(loc3, loc5), new SourceRange(loc1, loc5)));
     Assert.AreEqual(new SourceRange(loc1, loc5),
         SourceRange.Merge(new SourceRange(loc4, loc5), new SourceRange(loc1, loc2), new SourceRange(loc2, loc3)));
     Assert.AreEqual(new SourceRange(loc2, loc5),
         SourceRange.Merge(new SourceRange(loc3, loc5), new SourceRange(loc2, loc3)));
     Assert.AreEqual(new SourceRange(loc2, loc5),
         SourceRange.Merge(new SourceRange(loc4, loc5), new SourceRange(loc2, loc3)));
     Assert.AreEqual(new SourceRange(loc1, loc3),
         SourceRange.Merge(new SourceRange(loc1, loc2), new SourceRange(loc2, loc3)));
 }
Пример #5
0
 public ForLoopNode(SourcePosition pos, Node initialization, Node condition, Node final, Node loopBlock)
     : base(pos)
 {
     this.initialization = initialization;
     this.condition = condition;
     this.final = final;
     this.loopBlock = loopBlock;
 }
Пример #6
0
 /// <summary>
 /// 返回指定的位置是否完全包含在当前范围中。
 /// </summary>
 /// <param name="thisObj">当前范围。</param>
 /// <param name="location">要检查的位置。</param>
 /// <returns>如果指定的位置包含在当前范围中,则为 <c>true</c>;否则为 <c>false</c>。
 /// 对于未知的范围,也会返回 <c>false</c>。</returns>
 /// <exception cref="ArgumentNullException"><paramref name="thisObj"/> 为 <c>null</c>。</exception>
 public static bool Contains(this ISourceLocatable thisObj, SourcePosition location)
 {
     CommonExceptions.CheckArgumentNull(thisObj, "thisObj");
     Contract.EndContractBlock();
     if (location.IsUnknown || thisObj.IsUnknown())
     {
         return false;
     }
     return thisObj.End.Index >= location.Index && thisObj.Start.Index <= location.Index;
 }
Пример #7
0
		private static OracleCodeSnippet BuildCodeSnippet(Snippet s, SourcePosition sourcePosition)
		{
			return new OracleCodeSnippet
			{
				Name = s.Name,
				BaseText = s.Text,
				Description = s.Description,
				SourceToReplace = sourcePosition,
				Parameters = new List<ICodeSnippetParameter>(
					(s.Parameters ?? Enumerable.Empty<SnippetParameter>()).Select(p => new OracleCodeSnippetParameter
					{
						Index = p.Index,
						DefaultValue = p.DefaultValue
					})).AsReadOnly()
			};
		}
Пример #8
0
 public void TestContains()
 {
     SourcePosition loc1 = new SourcePosition(0, 1, 1);
     SourcePosition loc2 = new SourcePosition(2, 1, 3);
     SourcePosition loc3 = new SourcePosition(5, 1, 6);
     SourcePosition loc4 = new SourcePosition(6, 1, 7);
     SourcePosition loc5 = new SourcePosition(9, 2, 14);
     SourceRange range1 = new SourceRange(loc1, loc2);
     SourceRange range2 = new SourceRange(loc2, loc4);
     SourceRange range3 = new SourceRange(loc1, loc4);
     SourceRange range4 = new SourceRange(loc1, loc5);
     // Contains(ISourceLocatable)
     Assert.AreEqual(false, SourceRange.Unknown.Contains(SourceRange.Unknown));
     Assert.AreEqual(false, SourceRange.Unknown.Contains(range1));
     Assert.AreEqual(true, range1.Contains(range1));
     Assert.AreEqual(false, range1.Contains(range2));
     Assert.AreEqual(false, range1.Contains(SourceRange.Unknown));
     Assert.AreEqual(false, range2.Contains(range3));
     Assert.AreEqual(false, range2.Contains(range4));
     Assert.AreEqual(true, range3.Contains(range2));
     Assert.AreEqual(true, range4.Contains(range2));
     // Contains(SourcePosition)
     Assert.AreEqual(false, range2.Contains(SourcePosition.Unknown));
     Assert.AreEqual(false, range2.Contains(loc1));
     Assert.AreEqual(true, range2.Contains(loc2));
     Assert.AreEqual(true, range2.Contains(loc3));
     Assert.AreEqual(true, range2.Contains(loc4));
     Assert.AreEqual(false, range2.Contains(loc5));
     // Contains(int)
     Assert.AreEqual(false, range2.Contains(loc1.Index));
     Assert.AreEqual(true, range2.Contains(loc2.Index));
     Assert.AreEqual(true, range2.Contains(loc3.Index));
     Assert.AreEqual(true, range2.Contains(loc4.Index));
     Assert.AreEqual(false, range2.Contains(loc5.Index));
     // Contains(int,int)
     Assert.AreEqual(false, range2.Contains(loc1.Line, loc1.Col));
     Assert.AreEqual(true, range2.Contains(loc2.Line, loc2.Col));
     Assert.AreEqual(true, range2.Contains(loc3.Line, loc3.Col));
     Assert.AreEqual(true, range2.Contains(loc4.Line, loc4.Col));
     Assert.AreEqual(false, range2.Contains(loc5.Line, loc5.Col));
 }
Пример #9
0
        /*
         * Evaluate the function.
         *
         * @param interpreter
         * @param pos Source position of function call
         * @return The result of evaluating the function.
         */
        public JavaScriptObject Execute(Scope parentscope, List<JavaScriptObject> arguments, SourcePosition pos, JavaScriptObject thisObject)
        {
            Scope executionscope = new Scope(parentscope);
            int numberMissingArgs = 0;
            int numberRequiredArgs = 0;
            FunctionArguments argumentsVariable = new FunctionArguments(arguments);
            for (int paramIndex = 0; paramIndex < this.ArgumentCount; paramIndex++)
            {
                String argumentName = this.GetArgumentName(paramIndex);
                JavaScriptObject value = this.GetDefaultValue(paramIndex);
                if (value == null)
                {
                    numberRequiredArgs++;
                }
                if (paramIndex < argumentsVariable.Count)
                {
                    // Value provided in function call overrides the default value
                    value = argumentsVariable[paramIndex];
                }
                if (value == null)
                {
                    numberMissingArgs++;
                }

                executionscope.SetLocalVariable(argumentName, value);
            }

            executionscope.SetLocalVariable("arguments", argumentsVariable);

            if (numberMissingArgs > 0)
            {
                throw new TooFewArgumentsException(this.Name, numberRequiredArgs, argumentsVariable.Count, pos);
            }

            return this.Execute(pos, executionscope, thisObject);
        }
Пример #10
0
 public ConstDeclaration(Identifier identifier, Expression expression, SourcePosition position)
     : base(position)
 {
     _identifier = identifier;
     _expression = expression;
 }
Пример #11
0
 /// <summary>
 /// 返回表示文件结束的词法单元。
 /// </summary>
 /// <param name="loc">文件结束的位置。</param>
 /// <returns>表示文件结束的词法单元。</returns>
 /// <overloads>
 /// <summary>
 /// 返回表示文件结束的词法单元。
 /// </summary>
 /// </overloads>
 public static Token <T> GetEndOfFile(SourcePosition loc)
 {
     return(new Token <T>(EndOfFile, string.Empty, loc));
 }
Пример #12
0
 /// <summary>
 /// Constructor, only factory can instantiates nodes.
 /// </summary>
 /// <param name="nodeId">[in] The id of the node.</param>
 /// <param name="factory">[in] Poiter to the Factory the node belongs to.</param>
 public Positioned(uint nodeId, Factory factory) : base(nodeId, factory)
 {
     m_position = new SourcePosition(fact.StringTable);
 }
Пример #13
0
 // ctor that converts zero-based SourcePosition class to one-based SourcePos struct
 public SourcePos(SourcePosition zeroBasedPostion)
 {
     this.Line   = zeroBasedPostion.ZeroBasedLineNumber + 1;
     this.Column = zeroBasedPostion.ZeroBasedColumnNumber + 1;
 }
Пример #14
0
 public FloatNode(SourcePosition sourcePosition, string number)
     : base(sourcePosition)
 {
     this.number = new JavaScriptFloat(number);
 }
Пример #15
0
 public IfNode(SourcePosition position, ExpressionNode condition, StatementNode @true, StatementNode @false) : base(position)
 {
     Condition = condition;
     True      = @true;
     False     = @false;
 }
Пример #16
0
 public StateLabel(String name, int offset, SourcePosition start, SourcePosition end)
     : base(ASTNodeType.StateLabel, start, end)
 {
     StartOffset = offset;
     Name        = name;
 }
Пример #17
0
 public BlockNode(SourcePosition pos, List<Node> statements)
     : base(pos)
 {
     this.statements = statements;
 }
Пример #18
0
        public OperatorDeclaration TryParseOperatorDecl()
        {
            Func <ASTNode> operatorParser = () =>
            {
                var specs = ParseSpecifiers(GlobalLists.FunctionSpecifiers);

                var token = Tokens.ConsumeToken(TokenType.Operator) ??
                            Tokens.ConsumeToken(TokenType.PreOperator) ??
                            Tokens.ConsumeToken(TokenType.PostOperator) ??
                            new Token <String>(TokenType.INVALID);

                if (token.Type == TokenType.INVALID)
                {
                    return(null);
                }

                Token <String> precedence = null;
                if (token.Type == TokenType.Operator)
                {
                    if (Tokens.ConsumeToken(TokenType.LeftParenth) == null)
                    {
                        return(Error("Expected '('! (Did you forget to specify operator precedence?)", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                    }

                    precedence = Tokens.ConsumeToken(TokenType.IntegerNumber);
                    if (precedence == null)
                    {
                        return(Error("Expected an integer number!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                    }

                    if (Tokens.ConsumeToken(TokenType.RightParenth) == null)
                    {
                        return(Error("Expected ')'!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                    }
                }

                Token <String> returnType = null, name = null;
                var            firstString = TryParseOperatorIdentifier();
                if (firstString == null)
                {
                    return(Error("Expected operator name or return type!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                }

                var secondString = TryParseOperatorIdentifier();
                if (secondString == null)
                {
                    name = firstString;
                }
                else
                {
                    returnType = firstString;
                    name       = secondString;
                }

                VariableType retVarType = returnType != null ?
                                          new VariableType(returnType.Value, returnType.StartPosition, returnType.EndPosition) : null;

                if (Tokens.ConsumeToken(TokenType.LeftParenth) == null)
                {
                    return(Error("Expected '('!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                }

                var operands = new List <FunctionParameter>();
                while (CurrentTokenType != TokenType.RightParenth)
                {
                    var operand = TryParseParameter();
                    if (operand == null)
                    {
                        return(Error("Malformed operand!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                    }

                    operands.Add(operand);
                    if (Tokens.ConsumeToken(TokenType.Comma) == null && CurrentTokenType != TokenType.RightParenth)
                    {
                        return(Error("Unexpected operand content!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                    }
                }

                if (token.Type == TokenType.Operator && operands.Count != 2)
                {
                    return(Error("In-fix operators requires exactly 2 parameters!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                }

                else if (token.Type != TokenType.Operator && operands.Count != 1)
                {
                    return(Error("Post/Pre-fix operators requires exactly 1 parameter!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                }

                if (Tokens.ConsumeToken(TokenType.RightParenth) == null)
                {
                    return(Error("Expected ')'!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                }

                CodeBody       body = new CodeBody(null, CurrentPosition, CurrentPosition);
                SourcePosition bodyStart = null, bodyEnd = null;
                if (Tokens.ConsumeToken(TokenType.SemiColon) == null)
                {
                    if (!ParseScopeSpan(TokenType.LeftBracket, TokenType.RightBracket, out bodyStart, out bodyEnd))
                    {
                        return(Error("Malformed operator body!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                    }

                    body = new CodeBody(null, bodyStart, bodyEnd);
                }

                // TODO: determine if operator should be a delimiter! (should only symbol-based ones be?)
                if (token.Type == TokenType.PreOperator)
                {
                    return(new PreOpDeclaration(name.Value, false, body, retVarType, operands.First(), specs, name.StartPosition, name.EndPosition));
                }
                else if (token.Type == TokenType.PostOperator)
                {
                    return(new PostOpDeclaration(name.Value, false, body, retVarType, operands.First(), specs, name.StartPosition, name.EndPosition));
                }
                else
                {
                    return(new InOpDeclaration(name.Value, Int32.Parse(precedence.Value), false, body, retVarType,
                                               operands.First(), operands.Last(), specs, name.StartPosition, name.EndPosition));
                }
            };

            return((OperatorDeclaration)Tokens.TryGetTree(operatorParser));
        }
Пример #19
0
 public DelegateCall(SymbolReference del, List <Expression> arguments, SourcePosition start = null, SourcePosition end = null)
     : base(ASTNodeType.FunctionCall, start, end)
 {
     DelegateReference = del;
     Arguments         = arguments;
 }
Пример #20
0
        public Function TryParseFunction()
        {
            Func <ASTNode> stubParser = () =>
            {
                var specs = ParseSpecifiers(GlobalLists.FunctionSpecifiers);

                if (Tokens.ConsumeToken(TokenType.Function) == null)
                {
                    return(null);
                }

                Token <String> returnType = null, name = null;

                var firstString = Tokens.ConsumeToken(TokenType.Word);
                if (firstString == null)
                {
                    return(Error("Expected function name or return type!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                }

                var secondString = Tokens.ConsumeToken(TokenType.Word);
                if (secondString == null)
                {
                    name = firstString;
                }
                else
                {
                    returnType = firstString;
                    name       = secondString;
                }

                VariableType retVarType = returnType != null ?
                                          new VariableType(returnType.Value, returnType.StartPosition, returnType.EndPosition) : null;

                if (Tokens.ConsumeToken(TokenType.LeftParenth) == null)
                {
                    return(Error("Expected '('!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                }

                var parameters = new List <FunctionParameter>();
                while (CurrentTokenType != TokenType.RightParenth)
                {
                    var param = TryParseParameter();
                    if (param == null)
                    {
                        return(Error("Malformed parameter!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                    }

                    parameters.Add(param);
                    if (Tokens.ConsumeToken(TokenType.Comma) == null && CurrentTokenType != TokenType.RightParenth)
                    {
                        return(Error("Unexpected parameter content!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                    }
                }

                if (Tokens.ConsumeToken(TokenType.RightParenth) == null)
                {
                    return(Error("Expected ')'!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                }

                CodeBody       body = new CodeBody(null, CurrentPosition, CurrentPosition);
                SourcePosition bodyStart = null, bodyEnd = null;
                if (Tokens.ConsumeToken(TokenType.SemiColon) == null)
                {
                    if (!ParseScopeSpan(TokenType.LeftBracket, TokenType.RightBracket, out bodyStart, out bodyEnd))
                    {
                        return(Error("Malformed function body!", CurrentPosition, CurrentPosition.GetModifiedPosition(0, 1, 1)));
                    }

                    body = new CodeBody(null, bodyStart, bodyEnd);
                }

                return(new Function(name.Value, retVarType, body, specs, parameters, name.StartPosition, name.EndPosition));
            };

            return((Function)Tokens.TryGetTree(stubParser));
        }
Пример #21
0
 /// <summary>
 /// 使用词法单元的相关信息初始化 <see cref="Token{T}"/> 类的新实例。
 /// 起始位置和结束位置都会被设置为 <paramref name="loc"/>。
 /// </summary>
 /// <param name="id">标识符。</param>
 /// <param name="text">文本。</param>
 /// <param name="loc">词法单元的位置。</param>
 /// <overloads>
 /// <summary>
 /// 初始化 <see cref="Token{T}"/> 类的新实例。
 /// </summary>
 /// </overloads>
 public Token(T id, string text, SourcePosition loc)
 {
     this.Id    = id;
     this.Text  = text;
     this.Start = this.End = loc;
 }
Пример #22
0
 /// <summary>
 /// 返回表示文件结束的词法单元。
 /// </summary>
 /// <param name="loc">文件结束的位置。</param>
 /// <param name="value">词法单元的值。</param>
 /// <returns>表示文件结束的词法单元。</returns>
 public static Token <T> GetEndOfFile(SourcePosition loc, object value)
 {
     return(new Token <T>(EndOfFile, string.Empty, loc, loc, value));
 }
Пример #23
0
 public ConcatOpNode(SourcePosition pos, Node left, Node right)
     : base(pos, "+", left, right)
 {
 }
Пример #24
0
 public ParenNode(SourcePosition position, ExpressionNode value) : base(position)
 {
     Value = value;
 }
Пример #25
0
 public NewObjectNode(SourcePosition pos, String constructorName, List<Node> arguments)
     : base(pos, constructorName, arguments)
 {
 }
Пример #26
0
 protected PredicativeExpressionElement(SourcePosition pos) : base(pos)
 {
 }
 public InvalidOperatorException(SourcePosition pos)
     : base("Invalid operator", pos)
 {
 }
Пример #28
0
 public TypeDeclaration(Identifier identifier, TypeDenoter type, SourcePosition position) : base(position, type)
 {
     Identifier = identifier;
 }
Пример #29
0
 public DivideOpNode(SourcePosition pos, Node left, Node right)
     : base(pos, "/", left, right)
 {
 }
Пример #30
0
		/// <summary>
		/// 抛出未定义的正则表达式的异常。
		/// </summary>
		/// <param name="name">未定义的正则表达式的名字。</param>
		/// <param name="start">异常的起始位置。</param>
		/// <param name="end">异常的结束位置。</param>
		private void ThrowUndefinedRegex(string name, SourcePosition start, SourcePosition end)
		{
			string message = ExceptionResources.GetString("UndefinedRegex", name);
			throw CompilerCommonExceptions.ParsingException(pattern, message, start, end);
		}
Пример #31
0
 public AndOpNode(SourcePosition pos, Node left, Node right)
     : base(pos, "and", left, right)
 {
 }
Пример #32
0
 public FalseNode(SourcePosition pos)
     : base(pos)
 {
 }
Пример #33
0
 protected Declaration(SourcePosition pos) : base(pos)
 {
     Compiler.WriteDebuggingInfo($"Creating {this.GetType().Name}");
 }
Пример #34
0
 protected override JavaScriptObject Execute(SourcePosition pos, Scope scope, JavaScriptObject thisObject)
 {
     JavaScriptInteger sleeptime = scope.GetVariable("milliseconds", pos).ToInteger();
     Thread.Sleep(sleeptime.Value);
     return sleeptime;
 }
Пример #35
0
 /// <inheritdoc />
 /// <summary>
 /// 创建一个32位整数表达式
 /// </summary>
 /// <param name="position">该表达式在源代码中的对应位置</param>
 public IntegerExpression(SourcePosition position) : base(position)
 {
 }
Пример #36
0
 public FunctionCallNode(SourcePosition pos, String functionName, List<Node> arguments)
     : base(pos)
 {
     this.functionName = functionName;
     this.arguments = arguments;
 }
Пример #37
0
 public LaconfigToken(LaconfigLexer lexer, LaconfigTokenType type, SourcePosition startPos, SourcePosition endPos, string text, object value = null) :
     base(lexer, startPos, endPos, text, value)
 {
     Type = type;
 }
Пример #38
0
 private bool Error(String msg, SourcePosition start = null, SourcePosition end = null)
 {
     Log.LogError(msg, start, end);
     Success = false;
     return(false);
 }
Пример #39
0
 /// <summary>
 /// 使用指定的起始位置和 Tab 宽度初始化 <see cref="SourceLocator"/> 类的新实例。
 /// </summary>
 /// <param name="initPosition">起始位置。</param>
 /// <param name="tabSize">Tab 的宽度。</param>
 public SourceLocator(SourcePosition initPosition, int tabSize)
 {
     this.tabSize = tabSize;
     this.NextPosition = initPosition;
 }
 public EmptyFormalParameterSequence(SourcePosition position) : base(position)
 {
 }
Пример #41
0
 public NegateOpNode(SourcePosition pos, Node value)
     : base(pos, "-", value)
 {
 }
 /// <inheritdoc />
 /// <summary>
 /// 创建一个参数表达式
 /// </summary>
 /// <param name="position">该表达式在源代码中的对应位置</param>
 public ParameterExpression(SourcePosition position) : base(position)
 {
 }
Пример #43
0
 public ObjectNode(SourcePosition pos, Node expression)
     : base(pos)
 {
     this.expression = expression;
 }
Пример #44
0
 public BinaryExpression(Expression leftExpression, Operator operation, Expression rightExpression, SourcePosition position) : base(position)
 {
     Compiler.WriteDebuggingInfo($"Creating {GetType().Name}");
     Operation       = operation;
     LeftExpression  = leftExpression;
     RightExpression = rightExpression;
 }
Пример #45
0
 public WhileNode(SourcePosition pos, Node testCondition, Node loopBody)
     : base(pos)
 {
     this.testCondition = testCondition;
     this.loopBody = loopBody;
 }
Пример #46
0
            }//Run

            private void flush()
            {
                if (
                    (!isString) &&
                    (!isCommentBlock) &&
                    (!isCommentLine) &&
                    (buffer.Length == 0)
                    )
                {
                    return;
                }

                string text  = buffer.ToString();
                object value = null;

                buffer.Length = 0;

                CSTokenType type = CSTokenType.tUnknown;

                if (isString)
                {
                    type = CSTokenType.tStringLiteral;


                    if (!isVerbatim)
                    {
                        try //expand escapes
                        {
                            text = CSStrings.UnescapeString(text);
                        }
                        catch (StringEscapeErrorException err)
                        {
                            lexer.EmitMessage(MessageType.Error, (int)CSMsgCode.eInvalidStringEscape, tagStartPos, null, err.ErroredEscape);
                            return;
                        }
                    }
                }
                else if (isCommentLine && isDirective)//directives treated similar to line comments
                {
                    type = CSTokenType.tDirective;
                }
                else if (isCommentBlock || isCommentLine)
                {
                    type = CSTokenType.tComment;
                }
                else
                {
                    try
                    {
                        value = CSNumbers.Convert(text, out type);
                    }
                    catch (ArgumentException err)
                    {
                        lexer.EmitMessage(MessageType.Error, (int)CSMsgCode.eValueTooBig, tagStartPos, null, err.Message);
                        return;
                    }

                    if (value == null) //not number
                    {
                        type = CSKeywords.Resolve(text);

                        if (type == CSTokenType.tIdentifier)
                        {
                            if (text.StartsWith("@"))
                            {
                                text        = text.Remove(0, 1); //take care of verbatim names like: @class, @void, @var etc..
                                tagStartPos = new SourcePosition(tagStartPos.LineNumber, tagStartPos.ColNumber + 1, tagStartPos.CharNumber + 1);
                            }

                            if (!CSIdentifiers.Validate(text))
                            {
                                lexer.EmitMessage(MessageType.Error, (int)CSMsgCode.eInvalidIdentifier, tagStartPos, null, text);
                                return;
                            }
                        }
                    } //not a number
                }     //not a comment


                if (type == CSTokenType.tStringLiteral)
                {
                    value = text;
                }

                tokens.Add(new CSToken(lexer, type, tagStartPos, tagEndPos, text, value));
            }
Пример #47
0
 public Node(SourcePosition position)
 {
     this.position = position;
 }
Пример #48
0
 internal SourceChar(SourcePosition position, char value)
 {
     this.Position = position;
     this.Value    = value;
 }
Пример #49
0
 public ThisNode(SourcePosition sourcePosition, Node value)
     : base(sourcePosition)
 {
     this.value = value;
 }
        List <Instruction> GetInstructions(SbAddress sbAddress, uint numInstructions,
                                           bool withSource)
        {
            _lineEntryCache.Clear();
            var instructions = new List <Instruction>();

            // If we need source information, we look at the previous instruction to find out
            // if it is on the same line and/or in the same file.
            var position = SourcePosition.Empty;

            if (withSource)
            {
                // Find previous instruction and initialize lineAddress and lastLine here.
                SbAddress previousSbAddress =
                    _target.ResolveLoadAddress(sbAddress.GetLoadAddress(_target) - 1);
                if (previousSbAddress != null)
                {
                    position = GetPositionForAddress(previousSbAddress);
                }
            }

            uint numInstructionsRead = 0;
            List <InstructionInfo> cachedInstructions =
                _target.ReadInstructionInfos(sbAddress, numInstructions, _flavor);

            for (int i = 0; i < cachedInstructions.Count; i++)
            {
                Instruction currentInstruction = new Instruction();

                if (numInstructionsRead >= numInstructions)
                {
                    break;
                }

                numInstructionsRead++;

                InstructionInfo instruction = cachedInstructions[i];

                _lineEntryCache.Add(instruction.Address, instruction.LineEntry);

                currentInstruction.Address = instruction.Address;

                // Since Visual Studio doesn't do a good job formatting opcode and operands, in
                // addition to not providing a field to show instruction comments, do all the
                // formatting ourselves and put the entire string in the opcode field.
                string operands          = instruction.Operands;
                string comment           = instruction.Comment;
                string instructionString = $"{instruction.Mnemonic,-10}";
                if (string.IsNullOrEmpty(comment))
                {
                    instructionString += $" {operands}";
                }
                else
                {
                    instructionString += $" {operands,-30} # {comment}";
                }
                currentInstruction.Text = instructionString;

                if (!string.IsNullOrEmpty(instruction.SymbolName))
                {
                    currentInstruction.Symbol = instruction.SymbolName;
                }

                // If we so far believe we should get source position, let us get it here.
                if (withSource)
                {
                    SourcePosition lastPosition = position;
                    position = GetPositionFor(instruction.LineEntry);
                    WritePositionToInstruction(lastPosition, position, i == 0,
                                               ref currentInstruction);
                }
                instructions.Add(currentInstruction);
            }
            return(instructions);
        }
Пример #51
0
 public GreaterThenOpNode(SourcePosition pos, Node left, Node right)
     : base(pos, ">", left, right)
 {
 }
Пример #52
0
 public StopStatement(SourcePosition start, SourcePosition end)
     : base(ASTNodeType.StopStatement, start, end)
 {
 }
Пример #53
0
 public ModOpNode(SourcePosition pos, Node left, Node right)
     : base(pos, "%", left, right)
 {
 }
Пример #54
0
 protected Command(SourcePosition position) : base(position)
 {
     Compiler.WriteDebuggingInfo($"Creating {this.GetType().Name}");
 }
Пример #55
0
 public OrOpNode(SourcePosition pos, Node left, Node right)
     : base(pos, "or", left, right)
 {
 }
Пример #56
0
 public PositionedMessage(String msg, SourcePosition start, SourcePosition end) : base(msg)
 {
     Start = start;
     End   = end;
 }
Пример #57
0
 public LookupNode(SourcePosition pos, VariableNode variableNode, Node keyNode)
     : base(pos)
 {
     this.variableNode = variableNode;
     this.keyNode = keyNode;
 }
Пример #58
0
 public SubscriptVname(Vname vname, Expression expression, SourcePosition position)
     : base(position)
 {
     _vname      = vname;
     _expression = expression;
 }
Пример #59
0
 public GreaterEqualOpNode(SourcePosition pos, Node left, Node right)
     : base(pos, ">=", left, right)
 {
 }
Пример #60
0
 public AssignCommand(Vname vname, Expression expression, SourcePosition position)
     : base(position)
 {
     _vname      = vname;
     _expression = expression;
 }