public void TestBlockCommentConditionalSetup() { IEnumerable <IOperationProvider> ops = new ConditionalConfig().ConfigureFromJObject(BlockConditionalSetup, null); IList <IOperationProvider> operations = new List <IOperationProvider>(ops); Assert.Equal(2, operations.Count); // conditional & pseudo comment balancer Assert.True(operations[0] is Conditional); Conditional conditionalOp = operations[0] as Conditional; Assert.Equal(2, conditionalOp.Tokens.EndIfTokens.Count); Assert.True(conditionalOp.Tokens.EndIfTokens.Any(x => x.Value == "#endif")); Assert.True(conditionalOp.Tokens.EndIfTokens.Any(x => x.Value == "/*#endif")); Assert.Equal(1, conditionalOp.Tokens.ActionableIfTokens.Count); Assert.Equal("/*#if", conditionalOp.Tokens.ActionableIfTokens[0].Value); Assert.Equal(4, conditionalOp.Tokens.ActionableElseIfTokens.Count); Assert.True(conditionalOp.Tokens.ActionableElseIfTokens.Any(x => x.Value == "#elseif")); Assert.True(conditionalOp.Tokens.ActionableElseIfTokens.Any(x => x.Value == "/*#elseif")); Assert.True(conditionalOp.Tokens.ActionableElseIfTokens.Any(x => x.Value == "#elif")); Assert.True(conditionalOp.Tokens.ActionableElseIfTokens.Any(x => x.Value == "/*#elif")); Assert.Equal(2, conditionalOp.Tokens.ActionableElseTokens.Count); Assert.True(conditionalOp.Tokens.ActionableElseTokens.Any(x => x.Value == "#else")); Assert.True(conditionalOp.Tokens.ActionableElseTokens.Any(x => x.Value == "/*#else")); Assert.True(conditionalOp.WholeLine); Assert.True(conditionalOp.TrimWhitespace); }
public void TestCustomConditionalSetupExplicitStyleSpecification() { IEnumerable <IOperationProvider> ops = new ConditionalConfig().ConfigureFromJObject(CustomConditionalSetupExplicitStyleSpecification, null); IList <IOperationProvider> operations = new List <IOperationProvider>(ops); Assert.Equal(1, operations.Count); Assert.True(operations[0] is Conditional); Conditional conditionalOp = operations[0] as Conditional; Assert.Equal(1, conditionalOp.Tokens.ActionableIfTokens.Count); Assert.Equal("<!--#if", conditionalOp.Tokens.ActionableIfTokens[0].Value); Assert.Equal(2, conditionalOp.Tokens.ActionableElseTokens.Count); Assert.True(conditionalOp.Tokens.ActionableElseTokens.Any(x => x.Value == "<!--#else")); Assert.True(conditionalOp.Tokens.ActionableElseTokens.Any(x => x.Value == "#else")); Assert.Equal(2, conditionalOp.Tokens.ActionableElseIfTokens.Count); Assert.True(conditionalOp.Tokens.ActionableElseIfTokens.Any(x => x.Value == "<!--#elseif")); Assert.True(conditionalOp.Tokens.ActionableElseIfTokens.Any(x => x.Value == "#elseif")); Assert.Equal(2, conditionalOp.Tokens.EndIfTokens.Count); Assert.True(conditionalOp.Tokens.EndIfTokens.Any(x => x.Value == "<!--#endif")); Assert.True(conditionalOp.Tokens.EndIfTokens.Any(x => x.Value == "#endif")); Assert.True(conditionalOp.WholeLine); Assert.True(conditionalOp.TrimWhitespace); }
public void TestLineCommentConditionalSetup() { IEnumerable <IOperationProvider> ops = new ConditionalConfig().ConfigureFromJObject(LineConditionalSetup, null); IList <IOperationProvider> operations = new List <IOperationProvider>(ops); Assert.Equal(3, operations.Count); Assert.True(operations[0] is Conditional); Conditional conditionalOp = operations[0] as Conditional; Assert.Equal(conditionalOp.Tokens.IfTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.IfTokens[0], "//#if"); Assert.Equal(conditionalOp.Tokens.ElseIfTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.ElseIfTokens[0], "//#elseif"); Assert.Equal(conditionalOp.Tokens.ElseTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.ElseTokens[0], "//#else"); Assert.Equal(conditionalOp.Tokens.EndIfTokens.Count, 2); Assert.True(conditionalOp.Tokens.EndIfTokens.Contains("//#endif")); Assert.True(conditionalOp.Tokens.EndIfTokens.Contains("////#endif")); Assert.Equal(conditionalOp.Tokens.ActionableIfTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.ActionableIfTokens[0], "////#if"); Assert.Equal(conditionalOp.Tokens.ActionableElseIfTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.ActionableElseIfTokens[0], "////#elseif"); Assert.Equal(conditionalOp.Tokens.ActionableElseTokens.Count, 1); Assert.Equal(conditionalOp.Tokens.ActionableElseTokens[0], "////#else"); Assert.True(conditionalOp.WholeLine); Assert.True(conditionalOp.TrimWhitespace); }
public void HandleModelConfig(FileInfo sourceFile, ModelConfig baseModel, List <Model3D> modelCollection, DataTreeObject dataTreeParent = null, Transform3D globalTransform = null, Dictionary <string, dynamic> extraData = null) { ConditionalConfig model = (ConditionalConfig)baseModel.implementation; SetupCosmeticInformation(model, dataTreeParent); if (model.defaultModel != null) { SKAnimatorToolsProxy.IncrementEnd(); List <Model3D> mdls = ConfigReferenceUtil.HandleConfigReference(sourceFile, model.defaultModel, modelCollection, dataTreeParent, globalTransform, false, extraData); if (mdls != null) { foreach (Model3D mdl in mdls) { mdl.ExtraData["ConditionalConfigFlag"] = true; mdl.ExtraData["ConditionalConfigDefault"] = true; if (model.defaultTransform != null) { mdl.Transform = model.defaultTransform; } modelCollection.Add(mdl); } } SKAnimatorToolsProxy.IncrementProgress(); } SKAnimatorToolsProxy.IncrementEnd(model.cases.Length); foreach (ConditionalConfig.Case condition in model.cases) { List <Model3D> mdls = ConfigReferenceUtil.HandleConfigReference(sourceFile, condition.model, modelCollection, dataTreeParent, globalTransform, false, extraData); if (mdls != null) { foreach (Model3D mdl in mdls) { mdl.ExtraData["ConditionalConfigFlag"] = true; mdl.ExtraData["ConditionalConfigValue"] = true; try { bool state = condition.condition.createEvaluator(new DummyScope(model)).evaluate(); mdl.ExtraData["ConditionalConfigValue"] = state; } catch { } if (condition.transform != null) { mdl.Transform = condition.transform; } modelCollection.Add(mdl); } } SKAnimatorToolsProxy.IncrementProgress(); } }
public void SetupCosmeticInformation(ConditionalConfig data, DataTreeObject dataTreeParent) { if (dataTreeParent == null) { return; } dataTreeParent.AddSimpleProperty("Default Data", MakeModelTransformPair(data.defaultModel, data.defaultTransform), SilkImage.Conditional); DataTreeObject optionContainer = new DataTreeObject() { ImageKey = SilkImage.Array }; int idx = 0; foreach (ConditionalConfig.Case condition in data.cases) { optionContainer.AddSimpleProperty("Case " + idx, MakeModelTransformPair(condition.model, condition.transform, condition.condition), SilkImage.Conditional); idx++; } dataTreeParent.AddSimpleProperty("Cases", optionContainer, SilkImage.Array); }
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); }