Пример #1
0
        public void Unsigned3()
        {
            Number val;

            Assert.True(Helper.TryConvertToNumber("-42", out val));
            Assert.Equal(-42, val.Integer);
        }
Пример #2
0
        public void VerifyParse(string str, object value)
        {
            Number converted;

            Assert.True(Helper.TryConvertToNumber(str, out converted));
            Assert.Equal(value, converted.Value);
        }
Пример #3
0
        public void Unsigned2()
        {
            Number val;

            Assert.True(Helper.TryConvertToNumber("6000000000U", out val));
            Assert.Equal(6000000000L, val.Long);
        }
Пример #4
0
        public void Exponent3()
        {
            Number val;

            Assert.True(Helper.TryConvertToNumber("6.5e2L", out val));
            Assert.Equal(650f, val.Single);
        }
Пример #5
0
        public void Exponent1()
        {
            Number val;

            Assert.True(Helper.TryConvertToNumber("6e2", out val));
            Assert.Equal(600f, val.Single);
        }
Пример #6
0
        public void Float1()
        {
            Number val;

            Assert.True(Helper.TryConvertToNumber("6.5F", out val));
            Assert.Equal(6.5f, val.Single);
        }
Пример #7
0
 public void CallingConvention()
 {
     Assert.True(Helper.IsCallTypeModifier(TokenType.CDeclarationCallKeyword));
     Assert.True(Helper.IsCallTypeModifier(TokenType.StandardCallKeyword));
     Assert.True(Helper.IsCallTypeModifier(TokenType.ClrCallKeyword));
     Assert.True(Helper.IsCallTypeModifier(TokenType.InlineKeyword));
     Assert.True(Helper.IsCallTypeModifier(TokenType.PascalCallKeyword));
 }
Пример #8
0
        public void Signed1()
        {
            Number val;

            Assert.True(Helper.TryConvertToNumber("42", out val));
            Assert.Equal(42, val.Integer);
            Assert.True(Helper.TryConvertToNumber("400", out val));
            Assert.Equal(400, val.Integer);
            Assert.True(Helper.TryConvertToNumber("-1", out val));
            Assert.Equal(-1, val.Integer);
        }
Пример #9
0
        public void VerifyChar(char c)
        {
            Token token     = new Token(TokenType.CharacterAnsi, "'" + c + "'");
            char  converted = '0';

            Assert.True(Helper.TryConvertToChar(token, out converted));
            Assert.Equal(c, converted);

            token = new Token(TokenType.CharacterUnicode, "L'" + c + "'");
            Assert.True(Helper.TryConvertToChar(token, out converted));
            Assert.Equal(c, converted);
        }
Пример #10
0
        public void VerifyString(string str)
        {
            Token  token     = new Token(TokenType.QuotedStringAnsi, "\"" + str + "\"");
            string converted = null;

            Assert.True(Helper.TryConvertToString(token, out converted));
            Assert.Equal(str, converted);

            token = new Token(TokenType.QuotedStringUnicode, "L\"" + str + "\"");
            Assert.True(Helper.TryConvertToString(token, out converted));
            Assert.Equal(str, converted);
        }
Пример #11
0
        public void Invalid1()
        {
            Number val;

            Assert.False(Helper.TryConvertToNumber("aoo", out val));
        }
Пример #12
0
        /// <summary>
        /// Process a #include line.  These take typically two forms
        ///   #include "foo.h"
        ///   #include &gt;foo.h&gt;
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <remarks></remarks>

        private void ProcessPoundInclude(PreprocessorLine line)
        {
            if (!_options.FollowIncludes)
            {
                return;
            }

            // if the user did a <> include then there won't be any quotes around the string
            // so go ahead and redo the include to look like a "filename.h" include
            List <Token> list = new List <Token>(line.GetValidTokens());

            // Get rid of the #include
            ThrowIfFalse(list[0].TokenType == TokenType.PoundInclude);
            list.RemoveAt(0);

            string name = null;

            if (list[0].TokenType == TokenType.OpLessThan)
            {
                name = string.Empty;
                list.RemoveAt(0);
                while (list[0].TokenType != TokenType.OpGreaterThan)
                {
                    name += list[0].Value;
                    list.RemoveAt(0);
                }
                list.RemoveAt(0);
            }
            else if (list[0].IsQuotedString)
            {
                name = TokenHelper.ConvertToString(list[0]);
            }
            else
            {
                name = null;
            }

            if (name == null)
            {
                _scanner.AddWarning("Invalid #include statement");
                return;
            }

            // Now actually try and find the file.  First check the custom list
            bool found = false;

            if (File.Exists(name))
            {
                found = true;
                TraceToStream("include {0} followed -> {0}", name);
                TraceToStream("include {0} start", name);
                using (StreamReader reader = new StreamReader(name))
                {
                    ProcessCore(new TextReaderBag(name, reader));
                }
                TraceToStream("include {0} end", name);
            }
            else if (_options.IncludePathList.Count > 0)
            {
                // Search through the path list
                found = false;
                foreach (string prefix in _options.IncludePathList)
                {
                    string fullPath = Path.Combine(prefix, name);
                    if (File.Exists(fullPath))
                    {
                        found = true;
                        TraceToStream("include {0} followed -> {1}", name, fullPath);
                        TraceToStream("include {0} start", name);
                        using (StreamReader reader = new StreamReader(fullPath))
                        {
                            ProcessCore(new TextReaderBag(fullPath, reader));
                        }
                        TraceToStream("include {0} end", name);
                        break;
                    }
                }
            }
            else
            {
                found = false;
            }

            if (!found)
            {
                _scanner.AddWarning("Could not locate include file {0}", name);
                TraceToStream("include {0} not followed", name);
            }
        }