コード例 #1
0
ファイル: CFileHandler.cs プロジェクト: jonathanvdc/cin
 public static Task <CompilationUnit> ParseCompilationUnitAsync(IProjectSourceItem SourceItem, SyntaxAssembly Assembly, CompilationParameters Parameters)
 {
     Parameters.Log.LogEvent(new LogEntry("Status", "parsing " + SourceItem.SourceIdentifier));
     return(Task.Run(() =>
     {
         var code = GetSourceSafe(SourceItem, Parameters);
         if (code == null)
         {
             return null;
         }
         var parser = Preprocess(code, Parameters);
         var unit = ParseCompilationUnit(parser, Assembly);
         Parameters.Log.LogEvent(new LogEntry("Status", "parsed " + SourceItem.SourceIdentifier));
         return unit;
     }));
 }
コード例 #2
0
ファイル: CFileHandler.cs プロジェクト: jonathanvdc/cin
 public static ISourceDocument GetSourceSafe(IProjectSourceItem Item, CompilationParameters Parameters)
 {
     try
     {
         return(Item.GetSource(Parameters.CurrentPath.AbsolutePath.Path));
     }
     catch (FileNotFoundException)
     {
         Parameters.Log.LogError(new LogEntry("error getting source code", "file '" + Item.SourceIdentifier + "' was not found."));
         return(null);
     }
     catch (Exception ex)
     {
         Parameters.Log.LogError(new LogEntry("error getting source code", "'" + Item.SourceIdentifier + "' could not be opened."));
         Parameters.Log.LogError(new LogEntry("exception", ex.ToString()));
         return(null);
     }
 }
コード例 #3
0
        public static Task<IFunctionalNamespace> ParseCompilationUnitAsync(IProjectSourceItem SourceItem, CompilationParameters Parameters, IBinder Binder, IAssembly DeclaringAssembly, MacroProcessor Processor, IMessageSink Sink)
        {
            Parameters.Log.LogEvent(new LogEntry("Status", "Parsing " + SourceItem.SourceIdentifier));
            return Task.Run(() =>
            {
                var code = ProjectHandlerHelpers.GetSourceSafe(SourceItem, Parameters);
                if (code == null)
                {
                    return null;
                }
                var namer = ECSharpTypeNamer.Instance;
                var convRules = DefaultConversionRules.Create(namer.Convert);
                var globalScope = new GlobalScope(new FunctionalBinder(Binder), convRules, Parameters.Log, namer, new Flame.Syntax.MemberProvider(Binder).GetMembers, GetParameters);
                bool isLes = Enumerable.Last(SourceItem.SourceIdentifier.Split('.')).Equals("les", StringComparison.OrdinalIgnoreCase);
                var service = isLes ? (IParsingService)LesLanguageService.Value : EcsLanguageService.Value;
                var nodes = ParseNodes(code.Source, SourceItem.SourceIdentifier, service, Processor, Sink);

                if (Parameters.Log.Options.GetOption<bool>("E", false))
                {
                    var outputService = GetParsingService(Parameters.Log.Options, "syntax-format", service);
                    string newFile = outputService.Print(nodes, Sink, indentString: new string(' ', 4));
                    Parameters.Log.LogMessage(new LogEntry("'" + SourceItem.SourceIdentifier + "' after macro expansion", Environment.NewLine + newFile));
                }

                var unit = ParseCompilationUnit(nodes, globalScope, DeclaringAssembly);
                Parameters.Log.LogEvent(new LogEntry("Status", "Parsed " + SourceItem.SourceIdentifier));
                return unit;
            });
        }