private IGlobalRunConfig ProduceOperationSetup(SpecialOperationConfigParams defaultModel, bool generateMacros, ICustomFileGlobModel customGlobModel = null) { List <IOperationProvider> operations = new List <IOperationProvider>(); // TODO: if we allow custom config to specify a built-in conditional type, decide what to do. if (defaultModel.ConditionalStyle != ConditionalType.None) { operations.AddRange(ConditionalConfig.ConditionalSetup(defaultModel.ConditionalStyle, "C++", true, true, null)); } if (customGlobModel == null || string.IsNullOrEmpty(customGlobModel.FlagPrefix)) { // these conditions may need to be separated - if there is custom info, but the flag prefix was not provided, we might want to raise a warning / error operations.AddRange(FlagsConfig.FlagsDefaultSetup(defaultModel.FlagPrefix)); } else { operations.AddRange(FlagsConfig.FlagsDefaultSetup(customGlobModel.FlagPrefix)); } IVariableConfig variableConfig; if (customGlobModel != null) { variableConfig = customGlobModel.VariableFormat; } else { variableConfig = VariableConfig.DefaultVariableSetup(); } IReadOnlyList <IMacroConfig> macros = null; List <IMacroConfig> computedMacros = new List <IMacroConfig>(); List <IReplacementTokens> macroGeneratedReplacements = new List <IReplacementTokens>(); if (generateMacros) { macros = ProduceMacroConfig(computedMacros); } macroGeneratedReplacements.Add(new ReplacementTokens(_safeNameName, SourceName)); if (Symbols != null) { foreach (KeyValuePair <string, ISymbolModel> symbol in Symbols) { if (symbol.Value.Replaces != null) { macroGeneratedReplacements.Add(new ReplacementTokens(symbol.Value.Replaces, symbol.Key)); } } } foreach (KeyValuePair <Guid, string> map in _guidToGuidPrefixMap) { foreach (char format in GuidMacroConfig.DefaultFormats) { string newGuid = char.IsUpper(format) ? map.Key.ToString(format.ToString()).ToUpperInvariant() : map.Key.ToString(format.ToString()).ToLowerInvariant(); macroGeneratedReplacements.Add(new ReplacementTokens(map.Value + "-" + format, newGuid)); } } IReadOnlyList <ICustomOperationModel> customOperationConfig; if (customGlobModel != null && customGlobModel.Operations != null) { customOperationConfig = customGlobModel.Operations; } else { customOperationConfig = new List <ICustomOperationModel>(); } GlobalRunConfig config = new GlobalRunConfig() { Operations = operations, VariableSetup = variableConfig, Macros = macros, ComputedMacros = computedMacros, Replacements = macroGeneratedReplacements, CustomOperations = customOperationConfig, }; return(config); }
private IGlobalRunConfig ProduceOperationSetup(SpecialOperationConfigParams defaultModel, bool generateMacros, ICustomFileGlobModel customGlobModel = null) { List <IOperationProvider> operations = new List <IOperationProvider>(); // TODO: if we allow custom config to specify a built-in conditional type, decide what to do. if (defaultModel.ConditionalStyle != ConditionalType.None) { operations.AddRange(ConditionalConfig.ConditionalSetup(defaultModel.ConditionalStyle, defaultModel.EvaluatorName, true, true, null)); } if (customGlobModel == null || string.IsNullOrEmpty(customGlobModel.FlagPrefix)) { // these conditions may need to be separated - if there is custom info, but the flag prefix was not provided, we might want to raise a warning / error operations.AddRange(FlagsConfig.FlagsDefaultSetup(defaultModel.FlagPrefix)); } else { operations.AddRange(FlagsConfig.FlagsDefaultSetup(customGlobModel.FlagPrefix)); } IVariableConfig variableConfig; if (customGlobModel != null) { variableConfig = customGlobModel.VariableFormat; } else { variableConfig = VariableConfig.DefaultVariableSetup(defaultModel.VariableFormat); } IReadOnlyList <IMacroConfig> macros = null; List <IMacroConfig> computedMacros = new List <IMacroConfig>(); List <IReplacementTokens> macroGeneratedReplacements = new List <IReplacementTokens>(); if (generateMacros) { macros = ProduceMacroConfig(computedMacros); } if (SourceName != null) { if (SourceName.ToLower() != SourceName) { if (SourceName.IndexOf('.') > -1) { macroGeneratedReplacements.Add(new ReplacementTokens(_lowerSafeNamespaceName, SourceName.ToLowerInvariant())); macroGeneratedReplacements.Add(new ReplacementTokens(_lowerSafeNameName, SourceName.ToLowerInvariant().Replace('.', '_'))); } else { macroGeneratedReplacements.Add(new ReplacementTokens(_lowerSafeNameName, SourceName.ToLowerInvariant())); } } if (SourceName.IndexOf('.') > -1) { macroGeneratedReplacements.Add(new ReplacementTokens(_safeNamespaceName, SourceName)); macroGeneratedReplacements.Add(new ReplacementTokens(_safeNameName, SourceName.Replace('.', '_'))); } else { macroGeneratedReplacements.Add(new ReplacementTokens(_safeNameName, SourceName)); } } if (Symbols != null) { foreach (KeyValuePair <string, ISymbolModel> symbol in Symbols) { if (symbol.Value.Replaces != null) { if (symbol.Value.Type == "bind") { if (string.IsNullOrWhiteSpace(symbol.Value.Binding)) { EnvironmentSettings.Host.LogMessage($"Binding wasn't specified for bind-type symbol {symbol.Key}"); } else { //Since this is a bind symbol, don't replace the literal with this symbol's value, // replace it with the value of the bound symbol macroGeneratedReplacements.Add(new ReplacementTokens(symbol.Value.Binding, symbol.Value.Replaces)); } } else { //Replace the literal value in the "replaces" property with the evaluated value of the symbol macroGeneratedReplacements.Add(new ReplacementTokens(symbol.Key, symbol.Value.Replaces)); } } } } foreach (KeyValuePair <Guid, string> map in _guidToGuidPrefixMap) { foreach (char format in GuidMacroConfig.DefaultFormats) { string newGuid = char.IsUpper(format) ? map.Key.ToString(format.ToString()).ToUpperInvariant() : map.Key.ToString(format.ToString()).ToLowerInvariant(); macroGeneratedReplacements.Add(new ReplacementTokens(map.Value + "-" + format, newGuid)); } } IReadOnlyList <ICustomOperationModel> customOperationConfig; if (customGlobModel != null && customGlobModel.Operations != null) { customOperationConfig = customGlobModel.Operations; } else { customOperationConfig = new List <ICustomOperationModel>(); } GlobalRunConfig config = new GlobalRunConfig() { Operations = operations, VariableSetup = variableConfig, Macros = macros, ComputedMacros = computedMacros, Replacements = macroGeneratedReplacements, CustomOperations = customOperationConfig, }; return(config); }