private static IDxcTranslationUnit ParseTranslationUnit(string path) { var dxcIntelliSense = HlslDxcLib.CreateDxcIntelliSense(); var index = dxcIntelliSense.CreateIndex(); var commandLineArgs = new string[0]; var unsavedFiles = new IDxcUnsavedFile[] { new TrivialDxcUnsavedFile(path, System.IO.File.ReadAllText(path)) }; var translationUnit = index.ParseTranslationUnit( path, commandLineArgs, commandLineArgs.Length, unsavedFiles, (uint)unsavedFiles.Length, (uint)DxcTranslationUnitFlags.DxcTranslationUnitFlags_UseCallerThread); Assert.NotNull(translationUnit); return(translationUnit); }
static void PrintOutTokenColors(string path) { IDxcIntelliSense isense; try { isense = HlslDxcLib.CreateDxcIntelliSense(); } catch (System.DllNotFoundException dllNotFound) { Console.WriteLine("Unable to create IntelliSense helper - DLL not found there."); Console.WriteLine(dllNotFound.ToString()); return; } catch (Exception e) { Console.WriteLine("Unable to create IntelliSense helper."); Console.WriteLine(e.ToString()); return; } IDxcIndex index = isense.CreateIndex(); string fileName = path; string fileContents = System.IO.File.ReadAllText(path); string[] commandLineArgs = new string[] { "-ferror-limit=200" }; IDxcUnsavedFile[] unsavedFiles = new IDxcUnsavedFile[] { new TrivialDxcUnsavedFile(fileName, fileContents) }; Console.WriteLine("{0}:\n{1}", fileName, fileContents); IDxcTranslationUnit tu = index.ParseTranslationUnit(fileName, commandLineArgs, commandLineArgs.Length, unsavedFiles, (uint)unsavedFiles.Length, 0); if (tu == null) { Console.WriteLine("Unable to parse translation unit"); } else { IDxcSourceRange range = tu.GetCursor().GetExtent(); IDxcToken[] tokens; uint tokenCount; tu.Tokenize(range, out tokens, out tokenCount); Console.WriteLine("{0} tokens found.", tokenCount); for (UInt32 i = 0; i < tokenCount; i++) { PrintToken(tokens[i]); } } }