Exemplo n.º 1
0
        static bool PreprocessCode(string[] source, out List <Tuple <string, string, int> > exports, out Dictionary <string, List <CodeSegment> > segments)
        {
            segments = new Dictionary <string, List <CodeSegment> >();
            exports  = new List <Tuple <string, string, int> >();

            foreach (var _src in source)
            {
                string   src      = _src.ToLower();
                string[] contents = File.ReadAllLines(src);
                for (int i = 0; i < contents.Length; i++)
                {
                    string trimmed = contents[i].Trim();
                    if (trimmed == "#if IL" || trimmed == "#If IL Then") // found an IL segment...
                    {
                        CodeSegment seg = new CodeSegment();
                        seg.Start = ++i;
                        do
                        {
                            trimmed = contents[i].TrimStart();
                            if (trimmed.StartsWith(".exportnative ", StringComparison.OrdinalIgnoreCase))
                            {
                                // .exportnative (custom directive for exporting functions)
                                string exportName = trimmed.Remove(0, 14);
                                if (exports.Find((x) => x.Item1 == exportName) != null)
                                {
                                    Console.WriteLine("ERROR: Found duplicate-name export entries for \"" + exportName + "\"");
                                    return(false); // failed
                                }
                                exports.Add(Tuple.Create(exportName, src, i));
                            }
                            seg.ILCode.Add(contents[i++]);
                            trimmed = contents[i].TrimStart();
                        } while (trimmed != "#endif" && trimmed != "#End If"); // end of IL statement

                        seg.End     = i;
                        seg.SrcName = Path.GetFileName(src).ToLower(); // not case sensitive

                        List <CodeSegment> segCollection;
                        if (!segments.TryGetValue(src, out segCollection))
                        {
                            segments.Add(src, (segCollection = new List <CodeSegment>()));
                        }

                        Console.WriteLine("Found IL {0} from line {1} to line {2}", seg.SrcName, seg.Start + 1, seg.End);
                        segCollection.Add(seg);
                    }
                }
            }
            return(true); // success
        }
Exemplo n.º 2
0
        static bool PreprocessCode(string[] source, out List<Tuple<string, string, int>> exports, out Dictionary<string, List<CodeSegment>> segments)
        {
            segments = new Dictionary<string, List<CodeSegment>>();
            exports = new List<Tuple<string, string, int>>();

            foreach (var _src in source)
            {
                string src = _src.ToLower();
                string[] contents = File.ReadAllLines(src);
                for (int i = 0; i < contents.Length; i++)
                {
                    string trimmed = contents[i].Trim();
                    if (trimmed == "#if IL" || trimmed == "#If IL Then") // found an IL segment...
                    {
                        CodeSegment seg = new CodeSegment();
                        seg.Start = ++i;
                        do
                        {
                            trimmed = contents[i].TrimStart();
                            if (trimmed.StartsWith(".exportnative ", StringComparison.OrdinalIgnoreCase))
                            {
                                // .exportnative (custom directive for exporting functions)
                                string exportName = trimmed.Remove(0, 14);
                                if (exports.Find((x) => x.Item1 == exportName) != null)
                                {
                                    Console.WriteLine("ERROR: Found duplicate-name export entries for \"" + exportName + "\"");
                                    return false; // failed
                                }
                                exports.Add(Tuple.Create(exportName, src, i));
                            }
                            seg.ILCode.Add(contents[i++]);
                            trimmed = contents[i].TrimStart();

                        } while (trimmed != "#endif" && trimmed != "#End If"); // end of IL statement

                        seg.End = i;
                        seg.SrcName = Path.GetFileName(src).ToLower(); // not case sensitive

                        List<CodeSegment> segCollection;
                        if (!segments.TryGetValue(src, out segCollection))
                            segments.Add(src, (segCollection = new List<CodeSegment>()));

                        Console.WriteLine("Found IL {0} from line {1} to line {2}", seg.SrcName, seg.Start + 1, seg.End);
                        segCollection.Add(seg);
                    }
                }
            }
            return true; // success
        }