/// <summary> /// Read my note in https://github.com/3F/DllExport/issues/90 /// /// .assembly extern 'netstandard' /// ... ^^^^^^^^^^^ /// /// .class public auto ansi beforefieldinit ... /// extends[mscorlib] System.Object /// ^^^^^^^^ /// ... /// call instance void [mscorlib]System.Object::.ctor() /// ^^^^^^^^ /// </summary> /// <param name="il"></param> /// <param name="state"></param> /// <returns></returns> private bool EmitMSCorlib(List <string> il, ParserStateValues state) { if (state.ExternalAssemlyDeclarations.Count < 1) { return(false); } const string _EASM = "mscorlib"; if (state.ExternalAssemlyDeclarations.Any(x => x.AssemblyName == _EASM)) { return(false); } il.InsertRange ( state.ExternalAssemlyDeclarations[0].InputLineIndex, new [] { $".assembly extern '{_EASM}'", "{", " .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) ", " .ver 4:0:0:0", "}" } ); return(true); }
protected void Notify(ParserStateValues stateValues, int severity, string code, string message, params object[] values) { SourceCodeRange range; if (stateValues != null && (range = stateValues.GetRange()) != null) { this.Notifier.Notify(severity, code, range.FileName, new SourceCodePosition?(range.StartPosition), new SourceCodePosition?(range.EndPosition), message, values); } else { this.Notifier.Notify(severity, code, message, values); } }
protected bool ValidateExportNameAndLogError( ExportedMethod exportMethod, ParserStateValues stateValues) { bool flag; if (exportMethod == null) { flag = false; } else if (exportMethod.ExportName != null && (exportMethod.ExportName.Contains("'") || Regex.IsMatch(exportMethod.ExportName, "\\P{IsBasicLatin}"))) { this.Notify(stateValues, 3, DllExportLogginCodes.ExportNamesHaveToBeBasicLatin, Resources.Export_name_0_on_1__2_is_Unicode_windows_export_names_have_to_be_basic_latin, (object)exportMethod.ExportName, (object)exportMethod.ExportedClass.FullTypeName, (object)exportMethod.MemberName); flag = false; } else { flag = true; } return(flag); }
public abstract void Execute(ParserStateValues state, string trimmedLine);
public IEnumerable <string> GetLines(CpuPlatform cpu) { using (this.GetNotifier().CreateContextName((object)this, Resources.ParseILContextName)) { Dictionary <ParserState, IParserStateAction> actionsByState = IlParser.ParserStateAction.GetActionsByState(this); List <string> stringList1 = new List <string>(1000000); ParserStateValues state = new ParserStateValues(cpu, (IList <string>)stringList1) { State = ParserState.Normal }; Stopwatch stopwatch1 = Stopwatch.StartNew(); var dest = Path.Combine(TempDirectory, InputValues.FileName + ".il"); using (var sreader = new StreamReader(new FileStream(dest, FileMode.Open), Encoding.Unicode)) { while (!sreader.EndOfStream) { stringList1.Add(sreader.ReadLine()); } } Action <IParserStateAction, string> action1 = (Action <IParserStateAction, string>)((action, trimmedLine) => { string name = action.GetType().Name; using (this.GetNotifier().CreateContextName((object)action, name)) action.Execute(state, trimmedLine); }); if (this.ProfileActions) { Action <IParserStateAction, string> executeActionCore = action1; action1 = (Action <IParserStateAction, string>)((action, trimmedLine) => { Stopwatch stopwatch = Stopwatch.StartNew(); executeActionCore(action, trimmedLine); stopwatch.Stop(); action.Milliseconds += stopwatch.ElapsedMilliseconds; }); } Dictionary <string, int> usedScopeNames = new Dictionary <string, int>(); for (int index = 0; index < stringList1.Count; ++index) { state.InputPosition = index; string str1 = stringList1[index]; IlParsingUtils.ParseIlSnippet(str1, ParsingDirection.Forward, (Func <IlParsingUtils.IlSnippetLocation, bool>)(current => { if (!current.WithinString && (int)current.CurrentChar == 93 && (current.LastIdentifier != null && !usedScopeNames.ContainsKey(current.LastIdentifier))) { usedScopeNames.Add(current.LastIdentifier, usedScopeNames.Count); } return(true); }), (Action <IlParsingUtils.IlSnippetFinalizaton>)null); string str2 = str1.NullSafeTrim(); state.AddLine = true; IParserStateAction parserStateAction; if (!actionsByState.TryGetValue(state.State, out parserStateAction)) { this.GetNotifier().Notify(2, DllExportLogginCodes.NoParserActionError, Resources.No_action_for_parser_state_0_, (object)state.State); } else { action1(parserStateAction, str2); } if (state.AddLine) { state.Result.Add(str1); } } List <string> stringList2 = state.Result; if (state.ExternalAssemlyDeclarations.Count > 0) { stringList2 = new List <string>(state.Result.Count); stringList2.AddRange((IEnumerable <string>)state.Result); List <ExternalAssemlyDeclaration> assemlyDeclarationList = new List <ExternalAssemlyDeclaration>(state.ExternalAssemlyDeclarations.Count); Dictionary <string, int> foundAliases = new Dictionary <string, int>(); foreach (string inputText in stringList2) { if (inputText.Length >= 3 && inputText.Contains("[")) { IlParsingUtils.ParseIlSnippet(inputText, ParsingDirection.Forward, (Func <IlParsingUtils.IlSnippetLocation, bool>)(current => { if (current.WithinScope && !current.WithinString && (current.LastIdentifier != null && !foundAliases.ContainsKey(current.LastIdentifier))) { foundAliases.Add(current.LastIdentifier, foundAliases.Count); } return(true); }), (Action <IlParsingUtils.IlSnippetFinalizaton>)null); } } foreach (ExternalAssemlyDeclaration assemlyDeclaration in (IEnumerable <ExternalAssemlyDeclaration>)state.ExternalAssemlyDeclarations) { if (!foundAliases.ContainsKey(assemlyDeclaration.AliasName)) { assemlyDeclarationList.Add(assemlyDeclaration); } } if (assemlyDeclarationList.Count > 0) { assemlyDeclarationList.Reverse(); foreach (ExternalAssemlyDeclaration assemlyDeclaration in assemlyDeclarationList) { int num1 = 0; int num2 = -1; for (int inputLineIndex = assemlyDeclaration.InputLineIndex; inputLineIndex < stringList2.Count; ++inputLineIndex) { string str = stringList2[inputLineIndex].TrimStart(); if (str == "{") { ++num1; } else if (str == "}") { if (num1 == 1) { num2 = inputLineIndex; break; } --num1; } } if (num2 > -1) { this.GetNotifier().Notify(-2, DllExportLogginCodes.RemovingReferenceToDllExportAttributeAssembly, string.Format(Resources.Deleting_reference_to_0_, (object)assemlyDeclaration.AssemblyName, assemlyDeclaration.AliasName != assemlyDeclaration.AssemblyName ? (object)string.Format(Resources.AssemblyAlias, (object)assemlyDeclaration.AliasName) : (object)"")); stringList2.RemoveRange(assemlyDeclaration.InputLineIndex, num2 - assemlyDeclaration.InputLineIndex + 1); } } } } stopwatch1.Stop(); this.GetNotifier().Notify(-2, "EXPPERF02", Resources.Parsing_0_lines_of_IL_took_1_ms_, (object)stringList1.Count, (object)stopwatch1.ElapsedMilliseconds); if (this.ProfileActions) { foreach (KeyValuePair <ParserState, IParserStateAction> keyValuePair in actionsByState) { this.GetNotifier().Notify(-1, "EXPPERF03", Resources.Parsing_action_0_took_1_ms, (object)keyValuePair.Key, (object)keyValuePair.Value.Milliseconds); } } return((IEnumerable <string>)stringList2); } }