public IListSource<LNode> Parse(IListSource<Token> input, ISourceFile file, IMessageSink msgs, Symbol inputType = null) { // For efficiency we'd prefer to re-use our _parser object, but // when parsing lazily, we can't re-use it because another parsing // operation could start before this one is finished. To force // greedy parsing, we can call ParseStmtsGreedy(), but the caller may // prefer lazy parsing, especially if the input is large. As a // compromise I'll check if the source file is larger than a // certain arbitrary size. Also, ParseExprs() is always greedy // so we can always re-use _parser in that case. bool exprMode = inputType == ParsingService.Exprs; char _ = '\0'; if (inputType == ParsingService.Exprs || file.Text.TryGet(255, ref _)) { EcsParser parser = _parser; if (parser == null) _parser = parser = new EcsParser(input, file, msgs); else { parser.ErrorSink = msgs ?? MessageSink.Current; parser.Reset(input, file); } if (inputType == ParsingService.Exprs) return parser.ParseExprs(); else return parser.ParseStmtsGreedy(); } else { var parser = new EcsParser(input, file, msgs); return parser.ParseStmtsLazy().Buffered(); } }
public override ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile) { var contents = sourceFile.ReadAsText(snapshotParseContext.Tokens); var yamlTextSnapshot = CompositionService.Resolve<YamlTextSnapshot>().With(snapshotParseContext, sourceFile, contents); return yamlTextSnapshot; }
public override ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile) { var text = sourceFile.ReadAsText(snapshotParseContext.Tokens); var xmlTextSnapshot = CompositionService.Resolve<XmlTextSnapshot>().With(snapshotParseContext, sourceFile, text, SchemaNamespace, SchemaFileName); return xmlTextSnapshot; }
public override ISnapshot With(ISourceFile sourceFile) { base.With(sourceFile); Root = new SnapshotTextNode(this); return this; }
public void TraceError(int msg, string text, ISourceFile sourceFile, string details = "") { Write(msg, text, Severity.Error, sourceFile.AbsoluteFileName, TextSpan.Empty, details); if (Configuration.GetBool(Constants.Configuration.Debug)) { Debugger.Launch(); } }
public override IEnumerable<string> GetToolchainIncludes(ISourceFile file) { return new List<string> { Path.Combine(Platform.ReposDirectory, "AvalonStudio.Toolchains.STM32", "lib", "gcc", "arm-none-eabi", "5.4.1", "include"), Path.Combine(Platform.ReposDirectory, "AvalonStudio.Toolchains.STM32", "lib", "gcc", "arm-none-eabi", "5.4.1", "include-fixed"), Path.Combine(Platform.ReposDirectory, "AvalonStudio.Toolchains.STM32", "arm-none-eabi", "include") }; }
public new static VList<LNode> Parse(IList<Token> tokenTree, ISourceFile file, IMessageSink messages) { if (_parser == null) _parser = new AntlrStyleParser(tokenTree, file, messages); else { _parser.Reset(tokenTree, default(Token), file); _parser.ErrorSink = messages; } return _parser.RulesAndStuff(); }
public override IEnumerable<string> GetToolchainIncludes(ISourceFile file) { return new List<string> { Path.Combine(BaseDirectory, "lib", "gcc", "x86_64-w64-mingw32", "5.2.0", "include"), Path.Combine(BaseDirectory, "lib", "gcc", "x86_64-w64-mingw32", "5.2.0", "include-fixed"), Path.Combine(BaseDirectory, "x86_64-w64-mingw32", "include"), Path.Combine(BaseDirectory, "x86_64-w64-mingw32", "include", "c++"), Path.Combine(BaseDirectory, "x86_64-w64-mingw32", "include", "c++", "x86_64-w64-mingw32"), Path.Combine(BaseDirectory, "x86_64-w64-mingw32", "include", "c++", "x86_64-w64-mingw32", "backward") }; }
public ISnapshot LoadSnapshot(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile) { foreach (var loader in Loaders.OrderBy(l => l.Priority)) { if (loader.CanLoad(sourceFile)) { return loader.Load(snapshotParseContext, sourceFile); } } return Factory.Snapshot(sourceFile); }
public IntellisenseManager(TextEditor.TextEditor editor, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ILanguageService languageService, ISourceFile file) { intellisenseJobRunner = new JobRunner(); Task.Factory.StartNew(() => { intellisenseJobRunner.RunLoop(new CancellationToken()); }); this.intellisenseControl = intellisenseControl; this.completionAssistant = completionAssistant; this.languageService = languageService; this.file = file; this.editor = editor; this.editor.LostFocus += Editor_LostFocus; }
public virtual void Parse(IProject project, ISourceFile sourceFile) { var itemName = PathHelper.GetItemName(sourceFile); var fileContext = FileContext.GetFileContext(project, Configuration, sourceFile); var filePath = fileContext.FilePath; if (filePath.StartsWith("~/")) { filePath = filePath.Mid(1); } var filePathWithExtensions = PathHelper.NormalizeItemPath(PathHelper.GetDirectoryAndFileNameWithoutExtensions(filePath)); var fileName = Path.GetFileName(filePath); var fileNameWithoutExtensions = PathHelper.GetFileNameWithoutExtensions(fileName); var directoryName = string.IsNullOrEmpty(filePath) ? string.Empty : PathHelper.NormalizeItemPath(Path.GetDirectoryName(filePath) ?? string.Empty); var tokens = new Dictionary<string, string> { ["ItemPath"] = itemName, ["FilePathWithoutExtensions"] = filePathWithExtensions, ["FilePath"] = filePath, ["Database"] = project.Options.DatabaseName, ["FileNameWithoutExtensions"] = fileNameWithoutExtensions, ["FileName"] = fileName, ["DirectoryName"] = directoryName }; var snapshotParseContext = new SnapshotParseContext(SnapshotService, tokens, new Dictionary<string, List<ITextNode>>()); var snapshot = SnapshotService.LoadSnapshot(snapshotParseContext, sourceFile); var parseContext = Factory.ParseContext(project, snapshot); foreach (var parser in Parsers.OrderBy(p => p.Priority)) { try { if (parser.CanParse(parseContext)) { parser.Parse(parseContext); } } catch (Exception ex) { parseContext.Trace.TraceError(Msg.P1013, ex.Message, sourceFile.AbsoluteFileName, TextSpan.Empty); } } }
private void CompileCS(IConsole console, IStandardProject superProject, IStandardProject project, ISourceFile file, string outputFile) { var startInfo = new ProcessStartInfo(); startInfo.FileName = Path.Combine(BaseDirectory, "Roslyn", "csc.exe"); if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName)) { console.WriteLine("Unable to find compiler (" + startInfo.FileName + ") Please check project compiler settings."); } else { startInfo.WorkingDirectory = project.Solution.CurrentDirectory; startInfo.Arguments = string.Format("{0} /out:{1} {2}", GetCSCCompilerArguments(superProject, project, file), outputFile, file.Location); // Hide console window startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.CreateNoWindow = true; //console.WriteLine (Path.GetFileNameWithoutExtension(startInfo.FileName) + " " + startInfo.Arguments); using (var process = Process.Start(startInfo)) { process.OutputDataReceived += (sender, e) => { console.WriteLine(e.Data); }; process.ErrorDataReceived += (sender, e) => { if (e.Data != null) { console.WriteLine(); console.WriteLine(e.Data); } }; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); } } }
/// <summary> /// Processes single file. /// </summary> private static void ProcessFile(ISourceFile file) { int fileId = ResolveFile(file); Dictionary<Guid, LineRow> lineRows = new Dictionary<Guid, LineRow>(); Dictionary<Guid, DateTime> lineDates = new Dictionary<Guid, DateTime>(); List<ISourceVersion> versions = s_engine.GetVersions(file, s_options); foreach (ISourceVersion version in versions) { int userId = ResolveUser(version); int versionId = ResolveVersion(fileId, userId, version); List<string> lines = s_engine.GetLines(version); for (int i = 0; i < lines.Count; i++) { string text = lines[i]; Guid crc = SourceProcessor.CalculateCrc(text); LineRow lineRow = new LineRow { VersionId = versionId, LineCrc = crc, LineNumber = i, LineText = text }; if (!lineRows.ContainsKey(crc)) { lineRows.Add(crc, lineRow); lineDates.Add(crc, version.VersionDate); } else { if (version.VersionDate < lineDates[crc]) { lineRows[crc] = lineRow; lineDates[crc] = version.VersionDate; } } } } SourceTrackerDb.UploadLines(lineRows.Values); }
public bool CanHandle(ISourceFile file) { var result = false; switch (Path.GetExtension(file.Location)) { case ".cs": result = true; break; } if (!(file.Project.Solution is OmniSharpSolution)) { result = false; } return result; }
public static IList<IFieldElement> GetDisposableFieldsThatHaveNotBeenDisposed(ScopeResolveResult resolveResult, ISourceFile scope, IClassElement iClassElement, out IIfStatement parentIfDisposing) { parentIfDisposing = null; IList<IFieldElement> disposableFields = new List<IFieldElement>(); foreach (IElement child in iClassElement.AllChildren) { if (child.FirstFile == null) continue; // fix for partial classes if (child.FirstFile.Name != scope.Name) continue; IFieldElement iBaseVariable = child as IFieldElement; if (iBaseVariable != null) { if (CanAnalyseAsDisposable(iBaseVariable) && iBaseVariable.Is("System.IDisposable") && !IsDisposed(resolveResult, iClassElement, iBaseVariable)) disposableFields.Add(iBaseVariable); } else if (parentIfDisposing == null) { IMethodElement iMethodElement = child as IMethodElement; if (iMethodElement != null && iMethodElement.Name == STR_Dispose && iMethodElement.Parameters.Count == 1) { string paramName = iMethodElement.Parameters[0].Name; foreach (IElement potentialStatement in iMethodElement.AllChildren) { IIfStatement iIfStatement = potentialStatement as IIfStatement; if (iIfStatement != null) { IExpression condition = iIfStatement.Condition; if (condition != null && (condition.Name == paramName || (condition is ILogicalOperationExpression && (condition as ILogicalOperationExpression).LeftSide.Name == paramName))) { // We have found the "if (disposing)" block of code! parentIfDisposing = iIfStatement; break; } } } } } } return disposableFields; }
/// <summary>Gets the <see cref="SourceRange"/> of a token, under the /// assumption that the token came from the specified source file.</summary> public SourceRange Range(ISourceFile sf) { return(new SourceRange(sf, StartIndex, Length)); }
private IEnumerable<TextRange> GetNameSpaceRanges(ISourceFile scope, INamespaceElement namespaceElement) { if (namespaceElement == null || scope == null) yield break; int filesCount = namespaceElement.Files.Count; if (filesCount > 1) { for (int i = 0; i < filesCount; i++) { ISourceFile elementFile = namespaceElement.Files[i]; if (elementFile.Name == scope.Name && i < namespaceElement.NameRanges.Count) yield return namespaceElement.NameRanges[i]; } yield break; } yield return namespaceElement.FirstNameRange; }
public virtual void Begin(RWList <LNode> classBody, ISourceFile sourceFile) { _classBody = classBody; F = new LNodeFactory(sourceFile); _setDeclNames = new Dictionary <IPGTerminalSet, Symbol>(); }
/// <inheritdoc /> public override bool AnalyzeSourceFile(Workspaces.Core.Workspace workspace, AbsolutePath path, ISourceFile sourceFile) => true;
public void RemoveDocument(Project project, ISourceFile file) { var id = GetDocumentId(file); OnDocumentRemoved(id); }
private static IEnumerable <ModuleDeclarationSyntax> GetModuleDeclarations(ISourceFile sourceFile) => sourceFile is BicepFile bicepFile
public void RemoveFile(ISourceFile file) { file.Parent?.Items.Remove(file); SourceFiles.Remove(file); }
public override ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile) { var textSnapshot = CompositionService.Resolve<SerializationTextSnapshot>().With(sourceFile); return textSnapshot; }
public TokenTree(ISourceFile file) { File = file; }
/// <nodoc/> public static int GetAbsolutePosition(this Location location, ISourceFile sourceFile) { return(sourceFile.LineMap.Map[location.Line - 1] + location.Position - 1); }
public object ToSourceRange(ISourceFile sourceFile) { return(new SourceRange(sourceFile, StartIndex, Length)); }
public TokenTree(ISourceFile file, IEnumerable <Token> items) : base(items) { File = file; }
public TokenTree(ISourceFile file, ICollection <Token> items) : base(items) { File = file; }
private bool IsInScope(ISourceFile scope, IElement element) { return element.Files.Cast<ISourceFile>().Any(file => file.Name == scope.Name); }
public abstract void ExcludeFile(ISourceFile file);
public virtual ISnapshot With([NotNull] ISourceFile sourceFile) { SourceFile = sourceFile; return this; }
public override string GetCompilerArguments(IStandardProject superProject, IStandardProject project, ISourceFile file) { var result = string.Empty; //var settings = GetSettings(project).CompileSettings; var settings = GetSettings(superProject); result += "-Wall -c -fshort-enums "; if (settings.CompileSettings.DebugInformation) { result += "-ggdb3 "; } if (file == null || file.Extension == ".cpp") { switch (settings.CompileSettings.CppLanguageStandard) { case CppLanguageStandard.Cpp98: result += "-std=c++98 "; break; case CppLanguageStandard.Cpp03: result += "-std=c++03 "; break; case CppLanguageStandard.Cpp11: result += "-std=c++11 "; break; case CppLanguageStandard.Cpp14: result += "-std=c++14 "; break; case CppLanguageStandard.Cpp17: result += "-std=c++17 "; break; default: break; } } if (file == null || file.Extension == ".c") { switch (settings.CompileSettings.CLanguageStandard) { case CLanguageStandard.C89: result += "-std=c89 "; break; case CLanguageStandard.C99: result += "-std=c99 "; break; case CLanguageStandard.C11: result += "-std=c11 "; break; } } switch (settings.CompileSettings.Fpu) { case FPUSupport.Soft: result += "-mfpu=fpv4-sp-d16 -mfloat-abi=softfp "; break; case FPUSupport.Hard: result += "-mfpu=fpv4-sp-d16 -mfloat-abi=hard "; break; } // TODO remove dependency on file? if (file != null) { if (file.Extension == ".cpp") { if (!settings.CompileSettings.Rtti) { result += "-fno-rtti "; } if (!settings.CompileSettings.Exceptions) { result += "-fno-exceptions "; } } } switch (settings.CompileSettings.Fpu) { case FPUSupport.Soft: { result += "-mfpu=fpv4-sp-d16 -mfloat-abi=softfp "; } break; case FPUSupport.Hard: { result += "-mfpu=fpv4-sp-d16 -mfloat-abi=hard "; } break; } // TODO make this an option. result += "-ffunction-sections -fdata-sections "; switch (settings.CompileSettings.Optimization) { case OptimizationLevel.None: { result += "-O0 "; } break; case OptimizationLevel.Debug: { result += "-O2 "; } break; case OptimizationLevel.Level1: { result += "-O1 "; } break; case OptimizationLevel.Level2: { result += "-O2 "; } break; case OptimizationLevel.Level3: { result += "-O3 "; } break; } switch (settings.CompileSettings.OptimizationPreference) { case OptimizationPreference.Size: { result += "-Os "; } break; case OptimizationPreference.Speed: { result += "-Ofast "; } break; } result += settings.CompileSettings.CustomFlags + " "; // Referenced includes var referencedIncludes = project.GetReferencedIncludes(); foreach (var include in referencedIncludes) { result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include)); } // global includes var globalIncludes = superProject.GetGlobalIncludes(); foreach (var include in globalIncludes) { result += string.Format("-I\"{0}\" ", include); } // public includes foreach (var include in project.PublicIncludes) { result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include)); } // includes foreach (var include in project.Includes) { result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include.Value)); } var referencedDefines = project.GetReferencedDefines(); foreach (var define in referencedDefines) { result += string.Format("-D{0} ", define); } var toolchainIncludes = GetToolchainIncludes(file); foreach (var include in toolchainIncludes) { result += string.Format("-isystem\"{0}\" ", include); } // global includes var globalDefines = superProject.GetGlobalDefines(); foreach (var define in globalDefines) { result += string.Format("-D{0} ", define); } foreach (var define in project.Defines) { result += string.Format("-D{0} ", define.Value); } foreach (var arg in superProject.ToolChainArguments) { result += string.Format(" {0}", arg); } foreach (var arg in superProject.CompilerArguments) { result += string.Format(" {0}", arg); } // TODO factor out this code from here! if (file != null) { switch (file.Extension) { case ".c": { foreach (var arg in superProject.CCompilerArguments) { result += string.Format(" {0}", arg); } } break; case ".cpp": { foreach (var arg in superProject.CppCompilerArguments) { result += string.Format(" {0}", arg); } } break; } } return(result); }
public virtual void Begin(RWList<LNode> classBody, ISourceFile sourceFile) { _classBody = classBody; F = new LNodeFactory(sourceFile); _setDeclNames = new Dictionary<IPGTerminalSet, Symbol>(); }
public override CompileResult Compile(IConsole console, IStandardProject superProject, IStandardProject project, ISourceFile file, string outputFile) { var result = new CompileResult(); string commandName = file.Extension == ".cpp" ? CPPExecutable : CCExecutable; var fileArguments = string.Empty; if (file.Extension == ".cpp") { fileArguments = "-x c++ -fno-use-cxa-atexit"; } if (file.Extension.ToLower() == ".s") { fileArguments = "-x assembler-with-cpp"; } var arguments = string.Format("{0} {1} {2} -o{3} -MMD -MP", fileArguments, GetCompilerArguments(superProject, project, file), file.Location, outputFile); result.ExitCode = PlatformSupport.ExecuteShellCommand(commandName, arguments, (s, e) => console.WriteLine(e.Data), (s, e) => { if (e.Data != null) { console.WriteLine(); console.WriteLine(e.Data); } }, false, file.CurrentDirectory, false); // console.WriteLine(Path.GetFileNameWithoutExtension(commandName) + " " + arguments); return(result); }
/// <nodoc /> public DisallowedModuleReferenceFailure(ModuleDescriptor descriptor, ISourceFile sourceFile, IEnumerable <Diagnostic> disallowedReferences) : base(descriptor, sourceFile) { m_diagnostics = sourceFile.ParseDiagnostics.Union(disallowedReferences).ToList(); }
public XamlEditorViewModel(ISourceFile file) : base(file) { }
public TokenTree(ISourceFile file, int capacity) : base(capacity) { File = file; }
public override string GetCompilerArguments(IStandardProject superProject, IStandardProject project, ISourceFile file) { var result = string.Empty; //var settings = GetSettings(project).CompileSettings; var settings = GetSettings(superProject); result += "-Wall -c "; if (settings.CompileSettings.DebugInformation) { result += "-g "; } // TODO remove dependency on file? if (file != null) { if (file.Extension == ".cpp") { if (!settings.CompileSettings.Rtti) { result += "-fno-rtti "; } if (!settings.CompileSettings.Exceptions) { result += "-fno-exceptions "; } result += "-std=c++14 "; } } // TODO make this an option. result += "-ffunction-sections -fdata-sections "; switch (settings.CompileSettings.Optimization) { case OptimizationLevel.None: { result += "-O0 "; } break; case OptimizationLevel.Debug: { result += "-Og "; } break; case OptimizationLevel.Level1: { result += "-O1 "; } break; case OptimizationLevel.Level2: { result += "-O2 "; } break; case OptimizationLevel.Level3: { result += "-O3 "; } break; } switch (settings.CompileSettings.OptimizationPreference) { case OptimizationPreference.Size: { result += "-Os "; } break; case OptimizationPreference.Speed: { result += "-Ofast "; } break; } result += settings.CompileSettings.CustomFlags + " "; // toolchain includes // Referenced includes var referencedIncludes = project.GetReferencedIncludes(); foreach (var include in referencedIncludes) { result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include)); } // global includes var globalIncludes = superProject.GetGlobalIncludes(); foreach (var include in globalIncludes) { result += string.Format("-I\"{0}\" ", include); } // public includes foreach (var include in project.PublicIncludes) { result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include)); } // includes foreach (var include in project.Includes) { result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include.Value)); } var referencedDefines = project.GetReferencedDefines(); foreach (var define in referencedDefines) { result += string.Format("-D{0} ", define); } // global includes var globalDefines = superProject.GetGlobalDefines(); foreach (var define in globalDefines) { result += string.Format("-D{0} ", define); } foreach (var define in project.Defines) { result += string.Format("-D{0} ", define.Value); } if (Platform.PlatformIdentifier == PlatformID.Win32NT) { result += string.Format("-D{0} ", "WIN32NT"); } foreach (var arg in superProject.ToolChainArguments) { result += string.Format(" {0}", arg); } foreach (var arg in superProject.CompilerArguments) { result += string.Format(" {0}", arg); } // TODO factor out this code from here! if (file != null) { switch (file.Extension) { case ".c": { foreach (var arg in superProject.CCompilerArguments) { result += string.Format(" {0}", arg); } } break; case ".cpp": { foreach (var arg in superProject.CppCompilerArguments) { result += string.Format(" {0}", arg); } } break; } } return result; }
public IntellisenseManager(IEditor editor, IIntellisenseControl intellisenseControl, ICompletionAssistant completionAssistant, ILanguageService languageService, ISourceFile file, Action <int> onSetSignatureHelpPosition) { intellisenseJobRunner = new JobRunner(); intellisenseQueryRunner = new JobRunner(1); _cancelRunners = new CancellationTokenSource(); _onSetSignatureHelpPosition = onSetSignatureHelpPosition; Task.Factory.StartNew(() => { intellisenseJobRunner.RunLoop(_cancelRunners.Token); }); Task.Factory.StartNew(() => { intellisenseQueryRunner.RunLoop(_cancelRunners.Token); }); this.intellisenseControl = intellisenseControl; this.completionAssistant = completionAssistant; this.languageService = languageService; this.file = file; this.editor = editor; this.editor.LostFocus += Editor_LostFocus; _hidden = true; _shell = IoC.Get <IShell>(); _console = IoC.Get <IConsole>(); var snippetManager = IoC.Get <SnippetManager>(); _snippets = snippetManager.GetSnippets(languageService, file.Project?.Solution, file.Project); }
public Document GetDocument(ISourceFile file) { var documentId = GetDocumentId(file); return(CurrentSolution.GetDocument(documentId)); }
public override string GetCompilerArguments(IStandardProject superProject, IStandardProject project, ISourceFile file) { var result = string.Empty; var settings = superProject.GetToolchainSettings <GccToolchainSettings>(); result += "-Wall -c "; if (settings.CompileSettings.DebugInformation) { result += "-g "; } // TODO make this an option. result += "-ffunction-sections -fdata-sections "; if (file == null || file.Extension == ".cpp") { switch (settings.CompileSettings.CppLanguageStandard) { case CppLanguageStandard.Cpp98: result += "-std=c++98 "; break; case CppLanguageStandard.Cpp03: result += "-std=c++03 "; break; case CppLanguageStandard.Cpp11: result += "-std=c++11 "; break; case CppLanguageStandard.Cpp14: result += "-std=c++14 "; break; case CppLanguageStandard.Cpp17: result += "-std=c++17 "; break; case CppLanguageStandard.Gnu11: result += "-std=gnu++11 "; break; case CppLanguageStandard.Gnu14: result += "-std=gnu++14 "; break; default: break; } if (!settings.CompileSettings.Rtti) { result += "-fno-rtti "; } if (!settings.CompileSettings.Exceptions) { result += "-fno-exceptions "; } } if (file == null || file.Extension == ".c") { switch (settings.CompileSettings.CLanguageStandard) { case CLanguageStandard.C89: result += "-std=c89 "; break; case CLanguageStandard.C99: result += "-std=c99 "; break; case CLanguageStandard.C11: result += "-std=c11 "; break; } } switch (settings.CompileSettings.Optimization) { case OptimizationLevel.None: { result += "-O0 "; } break; case OptimizationLevel.Debug: { result += "-Og "; } break; case OptimizationLevel.Level1: { result += "-O1 "; } break; case OptimizationLevel.Level2: { result += "-O2 "; } break; case OptimizationLevel.Level3: { result += "-O3 "; } break; case OptimizationLevel.Size: { result += "-Os "; } break; case OptimizationLevel.Speed: { result += "-Ofast "; } break; } result += settings.CompileSettings.CustomFlags + " "; // toolchain includes // Referenced includes var referencedIncludes = project.GetReferencedIncludes(); foreach (var include in referencedIncludes) { result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include)); } // global includes var globalIncludes = superProject.GetGlobalIncludes(); foreach (var include in globalIncludes) { result += string.Format("-I\"{0}\" ", include); } // includes foreach (var include in project.Includes) { result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include.Value)); } var referencedDefines = project.GetReferencedDefines(); foreach (var define in referencedDefines) { result += string.Format("-D{0} ", define); } // global includes var globalDefines = superProject.GetGlobalDefines(); foreach (var define in globalDefines) { result += string.Format("-D{0} ", define); } foreach (var define in project.Defines) { result += string.Format("-D{0} ", define.Value); } if (Platform.OSDescription == "Windows") { result += string.Format("-D{0} ", "WIN32NT"); } foreach (var arg in superProject.ToolChainArguments) { result += string.Format(" {0}", arg); } foreach (var arg in superProject.CompilerArguments) { result += string.Format(" {0}", arg); } // TODO factor out this code from here! if (file != null) { switch (file.Extension) { case ".c": { foreach (var arg in superProject.CCompilerArguments) { result += string.Format(" {0}", arg); } } break; case ".cpp": { foreach (var arg in superProject.CppCompilerArguments) { result += string.Format(" {0}", arg); } } break; } } return(result); }
public TokenTree(ISourceFile file, ICollectionAndReadOnly <Token> items) : this(file, (IReadOnlyCollection <Token>)items) { }
public override bool SupportsFile(ISourceFile file) { var result = false; if (Path.GetExtension(file.Location) == ".cpp" || Path.GetExtension(file.Location) == ".c") { result = true; } return result; }
public Task <IEditor> OpenDocument(ISourceFile file, int line, int column = 1, bool debugHighlight = false, bool selectLine = false) { throw new NotImplementedException(); }
private bool NamespaceShouldBeUpdated(ISourceFile scope, IElement element, string expectedNamespace) { INamespaceElement namespaceElement = element as INamespaceElement; if (namespaceElement == null) return false; string currentNamespace = CurrentNamespace(namespaceElement); bool namespaceIsDefault = expectedNamespace == currentNamespace || (ContainsOnlyNamespacesOrUsings(scope, namespaceElement) && expectedNamespace.StartsWith(currentNamespace)); return !namespaceIsDefault; }
public IEnumerable <string> GetToolchainIncludes(ISourceFile file) { //Irrelevant return(new string[0]); }
private IEnumerable<TextRange> GetWrongNamespaceNameRanges(ISourceFile scope, INamespaceElement namespaceElement) { foreach (var range in GetNameSpaceRanges(scope, namespaceElement)) { // Find first namespace part in the same line INamespaceElement rootNamespace = namespaceElement; TextRange startRange = range; while (rootNamespace.ParentNamespace != null) { rootNamespace = rootNamespace.ParentNamespace; startRange = (from tempRange in GetNameSpaceRanges(scope, rootNamespace) where tempRange.Start.Line == range.End.Line select tempRange).DefaultIfEmpty(startRange).First(); } // Find last namespace part in the same line INamespaceElement childNamespace; INamespaceElement temp = namespaceElement; do { childNamespace = temp; temp = (from child in childNamespace.Namespaces.Cast<INamespaceElement>() where (from tempRange in GetNameSpaceRanges(scope, child) where tempRange.End.Line == range.Start.Line select range).Any() select child).FirstOrDefault(); } while (temp != null); TextRange endRange = (from tempRange in GetNameSpaceRanges(scope, childNamespace) where tempRange.End.Line == range.Start.Line select tempRange).FirstOrDefault(); yield return new TextRange(startRange.Start, endRange.End); } }
public override bool CanLoad(ISourceFile sourceFile) { return string.Equals(Path.GetExtension(sourceFile.AbsoluteFileName), ".yaml", StringComparison.OrdinalIgnoreCase); }
private bool ContainsOnlyNamespacesOrUsings(ISourceFile scope, INamespaceElement namespaceElement) { return namespaceElement.Children.All<IElement>(child => !IsInScope(scope, child) || child is INamespaceElement || child is INamespaceReference); }
public override string GetCompilerArguments(IStandardProject superProject, IStandardProject project, ISourceFile file) { var result = string.Empty; //var settings = GetSettings(project).CompileSettings; var settings = GetSettings(superProject); result += "-Wall -c "; if (settings.CompileSettings.DebugInformation) { result += "-g "; } // TODO remove dependency on file? if (file != null) { if (file.Extension == ".cpp") { if (!settings.CompileSettings.Rtti) { result += "-fno-rtti "; } if (!settings.CompileSettings.Exceptions) { result += "-fno-exceptions "; } } } // TODO make this an option. result += "-ffunction-sections -fdata-sections "; switch (settings.CompileSettings.Optimization) { case OptimizationLevel.None: { result += "-O0 "; } break; case OptimizationLevel.Debug: { result += "-Og "; } break; case OptimizationLevel.Level1: { result += "-O1 "; } break; case OptimizationLevel.Level2: { result += "-O2 "; } break; case OptimizationLevel.Level3: { result += "-O3 "; } break; } switch (settings.CompileSettings.OptimizationPreference) { case OptimizationPreference.Size: { result += "-Os "; } break; case OptimizationPreference.Speed: { result += "-Ofast "; } break; } result += settings.CompileSettings.CustomFlags + " "; // toolchain includes // Referenced includes var referencedIncludes = project.GetReferencedIncludes(); foreach (var include in referencedIncludes) { result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include)); } // global includes var globalIncludes = superProject.GetGlobalIncludes(); foreach (var include in globalIncludes) { result += string.Format("-I\"{0}\" ", include); } // public includes foreach (var include in project.PublicIncludes) { result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include)); } // includes foreach (var include in project.Includes) { result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include.Value)); } var referencedDefines = project.GetReferencedDefines(); foreach (var define in referencedDefines) { result += string.Format("-D{0} ", define); } // global includes var globalDefines = superProject.GetGlobalDefines(); foreach (var define in globalDefines) { result += string.Format("-D{0} ", define); } foreach (var define in project.Defines) { result += string.Format("-D{0} ", define.Value); } if (Platform.PlatformIdentifier == PlatformID.Win32NT) { result += string.Format("-D{0} ", "WIN32NT"); } foreach (var arg in superProject.ToolChainArguments) { result += string.Format(" {0}", arg); } foreach (var arg in superProject.CompilerArguments) { result += string.Format(" {0}", arg); } // TODO factor out this code from here! if (file != null) { switch (file.Extension) { case ".c": { foreach (var arg in superProject.CCompilerArguments) { result += string.Format(" {0}", arg); } } break; case ".cpp": { foreach (var arg in superProject.CppCompilerArguments) { result += string.Format(" {0}", arg); } } break; } } return(result); }
public override bool CanLoad(ISourceFile sourceFile) { return sourceFile.AbsoluteFileName.EndsWith(".item.xml", StringComparison.OrdinalIgnoreCase); }
private IAstConverter CreateAstConverter(ISourceFile sourceFile, RuntimeModelContext runtimeModelContext, AbsolutePath path, AstConversionConfiguration conversionConfiguration, Workspace workspace) { var module = ModuleLiteral.CreateFileModule(path, runtimeModelContext.FrontEndHost.ModuleRegistry, runtimeModelContext.Package, sourceFile.LineMap); return(CreateAstConverter(sourceFile, module, runtimeModelContext, path, conversionConfiguration, workspace)); }
/// <summary>Returns the same node with a parentheses attribute added.</summary> public static LNode InParens(this LNode node, ISourceFile file, int startIndex, int endIndex) { return InParens(node, new SourceRange(file, startIndex, endIndex - startIndex)); }
private static void ReportParseDiagnosticsIfNeeded(RuntimeModelContext runtimeModelContext, ISourceFile parsedSourceFile, AbsolutePath path) { foreach (var diagnostic in parsedSourceFile.ParseDiagnostics.AsStructEnumerable()) { var location = GetLocation(diagnostic, runtimeModelContext, parsedSourceFile, path); runtimeModelContext.Logger.ReportTypeScriptSyntaxError(runtimeModelContext.LoggingContext, location, diagnostic.MessageText.ToString()); } foreach (var diagnostic in parsedSourceFile.BindDiagnostics) { var location = GetLocation(diagnostic, runtimeModelContext, parsedSourceFile, path); runtimeModelContext.Logger.ReportTypeScriptBindingError(runtimeModelContext.LoggingContext, location, diagnostic.MessageText.ToString()); } }
public EcsTriviaInjector(IListSource<Token> sortedTrivia, ISourceFile sourceFile, int newlineTypeInt, string mlCommentPrefix, string mlCommentSuffix, string slCommentPrefix) : base(sortedTrivia, sourceFile, newlineTypeInt, mlCommentPrefix, mlCommentSuffix, slCommentPrefix) { }
private Microsoft.CodeAnalysis.Document GetDocument(CSharpDataAssociation dataAssociation, ISourceFile file, RoslynWorkspace workspace = null) { if (file is MetaDataFile metaDataFile) { return(metaDataFile.Document); } else { if (workspace == null) { workspace = RoslynWorkspace.GetWorkspace(dataAssociation.Solution); } return(workspace.GetDocument(file)); } }
private AntlrStyleParser(IList<Token> tokens, ISourceFile file, IMessageSink messageSink) : base(tokens, file, messageSink) { }
public void OpenFile(ISourceFile file) { ProjectFile = file; SourceFile = file; Title = Path.GetFileName(file.Location); }
/// <summary> /// Discover external module dependencies and enqueue them if necessary /// </summary> /// <remarks> /// The parsed file gets updated with the external module references as they are discovered. /// </remarks> private async Task <Possible <bool> > EnqueueSpecDependenciesIfAny(ModuleUnderConstruction owningModule, ISourceFile parsedFile) { var allSpecifiers = m_moduleReferenceResolver.GetExternalModuleReferences(parsedFile); foreach (var moduleName in allSpecifiers) { // Get the module definition from the resolver and enqueue it. Since we don't deal with versions yet at the // import level, there should be exactly one module definition with that name var maybeModuleDefinition = await m_workspaceProvider.FindUniqueModuleDefinitionWithName(moduleName); if (!maybeModuleDefinition.Succeeded) { return(maybeModuleDefinition.Failure); } var moduleDefinition = maybeModuleDefinition.Result; // Since the referenced module has been found, we update the parsed file with the reference. This // information is later used by the checker. if (!m_moduleReferenceResolver.TryUpdateExternalModuleReference(parsedFile, moduleDefinition, out var failure)) { return(failure); } // Update the owning module advertising that the found module was referenced owningModule.AddReferencedModule(moduleDefinition.Descriptor, moduleName.ReferencedFrom); EnqueueModuleForParsing(moduleDefinition); } return(true); }
private SourceFileParseResult ConvertSourceFile(RuntimeModelContext runtimeModelContext, AbsolutePath path, ISourceFile sourceFile) { runtimeModelContext.CancellationToken.ThrowIfCancellationRequested(); // This means that if there is any parse or binding errors conversion won't happen. if (runtimeModelContext.Logger.HasErrors) { return(new SourceFileParseResult(runtimeModelContext.Logger.ErrorCount)); } string specPath = sourceFile.Path.AbsolutePath; // If the serialized AST is available for this file, retrieve it and return instead of converting it if (sourceFile.IsPublicFacade) { var ast = ByteContent.Create(sourceFile.SerializedAst.Item1, sourceFile.SerializedAst.Item2); using (m_statistics.SpecAstDeserialization.Start(specPath)) { return(DeserializeAst(runtimeModelContext, ast)); } } Contract.Assert(!sourceFile.IsPublicFacade, "We are about to do AST conversion, so the corresponding spec file can't be a public facade, we need the real thing"); var converter = CreateAstConverter(sourceFile, runtimeModelContext, path, m_conversionConfiguration, m_workspace); SourceFileParseResult result; using (m_statistics.SpecAstConversion.Start(specPath)) { result = converter.ConvertSourceFile(); } if (runtimeModelContext.Logger.HasErrors) { // Skip serialization step if the error has occurred. return(result); } // At this point we have the computed AST, so we are in a position to generate the public surface of the file (if possible) // and serialize the AST for future reuse. var semanticModel = m_workspace.GetSemanticModel(); Contract.Assert(semanticModel != null); // Observe that here instead of using FrontEndHost.CanUseSpecPublicFacadeAndAst (that we checked for retrieving) we only require // that the associated flag is on. This is because, even though a partial reuse may not have happened, // saving is always a safe operation and the saved results may be available for future builds if (runtimeModelContext.FrontEndHost.FrontEndConfiguration.UseSpecPublicFacadeAndAstWhenAvailable()) { FileContent publicFacadeContent = CreatePublicFacadeContent(sourceFile, semanticModel); #pragma warning disable 4014 ScheduleSavePublicFacadeAndAstAsync(runtimeModelContext, path, sourceFile.Path.AbsolutePath, publicFacadeContent, result).ContinueWith( t => { runtimeModelContext.Logger.ReportFailedToPersistPublicFacadeOrEvaluationAst( runtimeModelContext.LoggingContext, #pragma warning disable SA1129 // Do not use default value type constructor new Location(), #pragma warning restore SA1129 // Do not use default value type constructor t.Exception.ToString()); }, TaskContinuationOptions.OnlyOnFaulted); #pragma warning restore 4014 } return(result); }