public void Generated_namespace_with_usings_is_correct(bool useVB) { var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#"); var expected = generator switch { CSharpGenerator => @"using static First = FirstNamespace; using Second.Namespace; using Third.Yes.No.Namespace; namespace CodeNamespace { }", VBGenerator => @"Imports First = FirstNamespace Imports Second.Namespace Imports Third.Yes.No.Namespace Namespace CodeNamespace End Namespace", }; var code = Code.Create(CodeNamespace) .Usings( new Using(FirstNamespace, FirstNamespaceAlias, true), SecondNamespace, ThirdNamespace); var actual = generator.Generate(code); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
/// <summary> /// Initializes a new instance of the <see cref="CompositionPoint"/> class. /// </summary> /// <param name="declaringComponent">The declaring component.</param> /// <param name="entryMethod">The entry method.</param> /// <param name="isExplicit">if set to <c>true</c> it is explicit composition point.</param> /// <param name="argumentProvider">The argument provider.</param> public CompositionPoint(TypeDescriptor declaringComponent, MethodID entryMethod, bool isExplicit, GeneratorBase argumentProvider) { IsExplicit = isExplicit; EntryMethod = entryMethod; DeclaringComponent = declaringComponent; ArgumentProvider = argumentProvider; }
public override double GetValue(double x, double y, double z) { double value = 0.0; double curPersistence = 1.0; //double nx, ny, nz; x *= Frequency; y *= Frequency; z *= Frequency; for (int currentOctave = 0; currentOctave < OctaveCount; currentOctave++) { long seed = (Seed + currentOctave) & 0xffffffff; /*nx = Math.MakeInt32Range(x); * ny = Math.MakeInt32Range(y); * nz = Math.MakeInt32Range(z);*/ double signal = GeneratorBase.GradientCoherentNoise(x, y, z, (int)seed, Quality); //signal = cachedNoise3(x, y, z); value += signal * curPersistence; x *= Lacunarity; y *= Lacunarity; z *= Lacunarity; curPersistence *= Persistence; } return(value); }
/// <summary> /// Push call of given name and generator to call stack /// </summary> /// <param name="name">Name of pushed method</param> /// <param name="generator">Generator which instructions will be pushed</param> /// <param name="argumentValues">Arguments of pushed call</param> internal void PushCall(MethodID name, GeneratorBase generator, Instance[] argumentValues) { var callTransformProvider = Edits == null ? null : Edits.TransformProvider; var isDirty = generator == null || argumentValues.Any((value) => value.IsDirty); if (isDirty) { //For dirty call we will propagate dirty flag foreach (var argumentValue in argumentValues) { argumentValue.IsDirty = true; } LastReturnValue = Machine.CreateDirectInstance("DirtyReturn"); LastReturnValue.IsDirty = true; //and call wont be pushed return; } var call = new CallContext(this, name, callTransformProvider, generator, argumentValues); if (_entryContext == null) { _entryContext = call; } else { if (CurrentCall != null) { CurrentCall.RegisterCall(call); } } _callStack.Push(call); }
public override double GetValue(double x, double y, double z) { double value = 0.0; double curPersistence = 1.0; //double nx, ny, nz; x *= Frequency; y *= Frequency; z *= Frequency; for (int currentOctave = 0; currentOctave < OctaveCount; currentOctave++) { long seed = (Seed + currentOctave) & 0xffffffff; double signal = GeneratorBase.GradientCoherentNoise(x, y, z, (int)seed, NoiseQuality); signal = 2.0 * System.Math.Abs(signal) - 1.0; value += signal * curPersistence; x *= Lacunarity; y *= Lacunarity; z *= Lacunarity; curPersistence *= Persistence; } value += 0.5; return(value); }
public override double GetValue(double x, double y, double z) { x *= Frequency; y *= Frequency; z *= Frequency; double value = 0.0; double weight = 1.0; const double offset = 1.0; const double gain = 2.0; for (int currentOctave = 0; currentOctave < OctaveCount; currentOctave++) { //double nx, ny, nz; /* nx = Math.MakeInt32Range(x); * ny = Math.MakeInt32Range(y); * nz = Math.MakeInt32Range(z);*/ long seed = (Seed + currentOctave) & 0x7fffffff; double signal = GeneratorBase.GradientCoherentNoise(x, y, z, (int)seed, NoiseQuality); // Make the ridges. signal = Math.Abs(signal); signal = offset - signal; // Square the signal to increase the sharpness of the ridges. signal *= signal; // The weighting from the previous octave is applied to the signal. // Larger values have higher weights, producing sharp points along the // ridges. signal *= weight; // Weight successive contributions by the previous signal. weight = signal * gain; if (weight > 1.0) { weight = 1.0; } if (weight < 0.0) { weight = 0.0; } // Add the signal to the output value. value += (signal * SpectralWeights[currentOctave]); // Go to the next octave. x *= Lacunarity; y *= Lacunarity; z *= Lacunarity; } return((value * 1.25) - 1.0); }
void HandleGeneratorStateChanged(GeneratorBase.GeneratorState state) { switch (state) { case GeneratorBase.GeneratorState.Initialized: EnableBones(false); break; } }
public void Parse_DuplicateVariable() { Config.Locale = "en"; const string template = "#{Name.last_name}, #{Name.last_name} and #{Name.last_name}"; var result = GeneratorBase <Company> .Parse(template); var parts = result.Split(',', ' ').Where(x => x != string.Empty).Distinct().ToArray(); Assert.GreaterOrEqual(parts.Length, 3); }
public void Generated_code_with_member_is_correct(bool useVB) { var memberName = "AMember"; var cls = new Class(ClassName) .Member(new Property(memberName, "string")); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#"); var expected = generator switch { CSharpGenerator => @$ "public class {ClassName} {{
private void Generate_Click(object sender, EventArgs e) { string _tableNmae = TableName.Text; string temp = Template.Text; GeneratorBase generator = GeneratorFactory.GetGeneratorByName(GeneratorEnum.EntityGenerator); generator.SetTableName(_tableNmae); generator.SetTemplate(temp); Code.Text = generator.GetCode(); }
/// <summary> /// Adds the method. /// </summary> /// <param name="method">The method.</param> /// <param name="info">The information.</param> /// <param name="implementedTypes">The implemented types.</param> private void addMethod(GeneratorBase method, TypeMethodInfo info, IEnumerable <InstanceInfo> implementedTypes) { var implemented = implementedTypes.ToArray(); if (!_knownInheritance.ContainsKey(info.DeclaringType)) { _knownInheritance[info.DeclaringType] = TypeDescriptor.ObjectInfo; } _methods.AddItem(new MethodItem(method, info), implemented); }
internal void Initialize(WorldConfiguration config) { chunkCache = new ChunkCache(); storage = new ChunkStorage(); generator = config.Generator; Player = new Player(); Player.PrevPosition = World.Instance.Player.Position = new Vector3(0, 100, -20); entityToControl = Player; globalEntities.Add(new Sun()); globalEntities.Add(new Moon()); globalEntities.Add(Player); }
public void Generated_field_is_correct(bool useVB) { var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");; var expected = generator switch { CSharpGenerator => @$ "", VBGenerator => $@"", _ => throw new NotImplementedException() }; //var actual = generator.OutputConstructor(ctor).GetOutput(); //actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
/// <summary> /// Push dynamic call generated from given <see cref="GeneratorBase"/> /// </summary> /// <param name="methodNameHint">Hint for name of generated method</param> /// <param name="generator">Generator of instructions for dynamic call</param> /// <param name="argumentValues">Arguments of dynamic call</param> public void DynamicCall(string methodNameHint, GeneratorBase generator, params Instance[] argumentValues) { var dynamicCall = new DynamicCallEntry(new MethodID(methodNameHint, false), generator, argumentValues.ToArray()); if (CurrentCall.ContextsDynamicCalls == null) { CurrentCall.ContextsDynamicCalls = dynamicCall; } else { CurrentCall.ContextsDynamicCalls.LastCall.NextDynamicCall = dynamicCall; } }
public void Generator(GeneratorBase gen) { if (gen is PlaneGenerator) { Plane(gen as PlaneGenerator); } else if (gen is CircleGenerator) { Circle(gen as CircleGenerator); } else if (gen is RectangleGenerator) { Rectangle(gen as RectangleGenerator); } }
public void Generated_readonly_auto_property_is_correct(bool useVB) { var property = new Property(PropertyName, "string", readOnly: true); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#"); var expected = generator switch { CSharpGenerator => @"public string PropertyName { get; }", VBGenerator => @"Public ReadOnly Property PropertyName As String", _ => throw new NotImplementedException() }; var actual = generator.OutputProperty(property).GetOutput(); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
public void Generated_expression_body_property_is_correct(bool useVB) { var property = new Property(PropertyName, "string", readOnly: true) .GetterReturn(Expression.Value(42)); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");; var expected = generator switch { CSharpGenerator => @"public string PropertyName => 42;", _ => throw new NotImplementedException() }; var actual = generator.OutputProperty(property).GetOutput().NormalizeWhitespace(); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
/// <summary> /// 重複した関数であるか。 /// </summary> /// <param name="generator">ジェネレータ。</param> /// <param name="sentence">センテンス。</param> /// <param name="function">関数。</param> /// <returns>重複した関数であるか。</returns> private static bool IsDuplicationFunction(GeneratorBase generator, Sentence sentence, string function) { if (!ReferenceEquals(generator, sentence.Owner)) { return(false); } if (sentence.Tokens.Length <= 2) { return(false); } if (!(sentence.Tokens[0] is TokenName) || (sentence.Tokens[1] == null)) { return(false); } return(sentence.Tokens[1].ToString().IndexOf("." + function) == 0); }
/// <summary> /// Initializes a new instance of the <see cref="MethodItem"/> class. /// </summary> /// <param name="generator">The instruction generator defining instruction of represented method.</param> /// <param name="info">Information about signature of represented method.</param> /// <exception cref="System.NotSupportedException">Cannot create method item for generic method without generic generator</exception> public MethodItem(GeneratorBase generator, TypeMethodInfo info) { Info = info; _genericGenerator = generator as GenericMethodGenerator; if (info.HasGenericParameters) { if (_genericGenerator == null) { throw new NotSupportedException("Cannot create method item for generic method without generic generator"); } } else { Generator = generator; } }
public void Generated_class_is_correct(bool useVB) { var cls = new Class(ClassName); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#"); var expected = generator switch { CSharpGenerator => @$ "public class {ClassName} {{ }}", VBGenerator => $@"Public Class {ClassName} End Class", _ => throw new NotImplementedException() }; var actual = generator.OutputClass(cls).GetOutput().NormalizeWhitespace(); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
public void Generated_method_is_correct(bool useVB) { var method = new Method(MethodName); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");; var expected = generator switch { CSharpGenerator => @$ "public void {MethodName}() {{ }}", VBGenerator => $@"Public Sub {MethodName}() End Sub", _ => throw new NotImplementedException() }; var actual = generator.OutputMethod(method).GetOutput(); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
public void Generated_constructor_is_correct(bool useVB) { var ctor = new Constructor(new TypeRep("ClassName")); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");; var expected = generator switch { CSharpGenerator => @"public ClassName() { }", VBGenerator => @"Public Sub New() End Sub", _ => throw new NotImplementedException() }; var actual = generator.OutputConstructor(ctor).GetOutput(); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
/// <summary> /// 重複した関数の削除。 /// </summary> /// <param name="generator">ジェネレータ。</param> /// <param name="list">リスト。</param> /// <param name="function">関数。</param> public static void RemoveDuplicationFunction(GeneratorBase generator, List<Sentence> list, string function) { bool findChangeText = false; for (int i = list.Count - 1; 0 <= i; i--) { if (IsDuplicationFunction(generator, list[i], function)) { if (findChangeText) { list.RemoveAt(i); } findChangeText = true; } else { findChangeText = false; } } }
/// <summary> /// 重複したセンテンスの削除。 /// </summary> /// <param name="generator">ジェネレータ。</param> /// <param name="list">リスト。</param> /// <param name="pattern">パターン。</param> public static void RemoveDuplicationSentence(GeneratorBase generator, List<Sentence> list, object[] pattern) { Sentence old = null; for (int i = list.Count - 1; 0 <= i; i--) { Sentence current = list[i]; if (ReferenceEquals(generator, current.Owner)) { if (old != null) { if (IsDuplicationSentence(old, current, pattern)) { list.RemoveAt(i); } } } old = current; } }
public void Generated_method_is_correct_with_returnType(bool useVB) { var method = new Method(MethodName) .ReturnType("string"); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");; var expected = generator switch { CSharpGenerator => @$ "public string {MethodName}() {{ }}", VBGenerator => $@"Public Function {MethodName}() As String End Function", _ => throw new NotImplementedException() }; var actual = generator.OutputMethod(method).GetOutput(); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
/// <summary> /// 重複したセンテンスの削除。 /// </summary> /// <param name="generator">ジェネレータ。</param> /// <param name="list">リスト。</param> /// <param name="pattern">パターン。</param> public static void RemoveDuplicationSentence(GeneratorBase generator, List <Sentence> list, object[] pattern) { Sentence old = null; for (int i = list.Count - 1; 0 <= i; i--) { Sentence current = list[i]; if (ReferenceEquals(generator, current.Owner)) { if (old != null) { if (IsDuplicationSentence(old, current, pattern)) { list.RemoveAt(i); } } } old = current; } }
public void Generated_constructor_with_parameters_is_correct(bool useVB) { var ctor = new Constructor(new TypeRep("ClassName")) .Parameter("abc", typeof(string)) .Parameter("def", typeof(int)); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");; var expected = generator switch { CSharpGenerator => @$ "public ClassName(string abc, int def) {{ }}", VBGenerator => $@"Public Sub New(abc As String, def As Integer) End Sub", _ => throw new NotImplementedException() }; var actual = generator.OutputConstructor(ctor).GetOutput(); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
/// <summary> /// 重複した関数の削除。 /// </summary> /// <param name="generator">ジェネレータ。</param> /// <param name="list">リスト。</param> /// <param name="function">関数。</param> public static void RemoveDuplicationFunction(GeneratorBase generator, List <Sentence> list, string function) { bool findChangeText = false; for (int i = list.Count - 1; 0 <= i; i--) { if (IsDuplicationFunction(generator, list[i], function)) { if (findChangeText) { list.RemoveAt(i); } findChangeText = true; } else { findChangeText = false; } } }
public void Generated_constructor_with_this_and_argument_is_correct(bool useVB) { var ctor = new Constructor(new TypeRep("Abc")) .ThisCall(Expression.Value(42)); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");; var expected = generator switch { CSharpGenerator => @"public Abc() : this(42) { }", VBGenerator => @"Public Sub New() Me.New(42) End Sub", _ => throw new NotImplementedException() }; var actual = generator.OutputConstructor(ctor).GetOutput(); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
public void Generated_method_with_parameters_is_correct(bool useVB) { var method = new Method(MethodName) .Parameter("value", typeof(int)) .Parameter("s", typeof(string)); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");; var expected = generator switch { CSharpGenerator => @$ "public void {MethodName}(int value, string s) {{ }}", VBGenerator => $@"Public Sub {MethodName}(value As Integer, s As String) End Sub", _ => throw new NotImplementedException() }; var actual = generator.OutputMethod(method).GetOutput(); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
public void Generated_method_with_modifiers_is_correct(bool useVB) { var method = new Method(MethodName, modifiers: MemberModifiers.Partial | MemberModifiers.Override) .ReturnType("string") .Parameter("value", typeof(int)) .Parameter("s", typeof(string)); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");; var expected = generator switch { CSharpGenerator => @$ "public partial override string {MethodName}(int value, string s) {{ }}", VBGenerator => $@"Public Partial Overrides Function {MethodName}(value As Integer, s As String) As String End Function", _ => throw new NotImplementedException() }; var actual = generator.OutputMethod(method).GetOutput(); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
public void Generated_full_property_is_correct(bool useVB) { var property = new Property(PropertyName, "string") .GetterStatements(Expression.AssignVar("y", "int", Expression.Value(11))) .GetterReturn(Expression.Value(5)) .SetterStatements(Expression.AssignVar("x", "int", Expression.Value(7))); var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");; var expected = generator switch { CSharpGenerator => @"public string PropertyName { get { int y = 11; return 5; } set { int x = 7; } }", VBGenerator => $@"Public Property PropertyName As String Get Dim y As Integer = 11 Return 5 End Get Set(Value As String) Dim x As Integer = 7 End Set End Property", _ => throw new NotImplementedException() }; var actual = generator.OutputProperty(property).GetOutput(); actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace()); }
protected virtual void WriteGenerator(GeneratorBase generator) { WriteObjectTag(generator); WriteToken(InspectorTokenType.Space); WriteToken(InspectorTokenType.ObjectStart); switch (generator.State) { case GeneratorState.Running: WriteObjectState("<running>"); break; case GeneratorState.SuspendedStart: case GeneratorState.SuspendedYield: WriteObjectState("<suspended>"); break; default: WriteObjectState("<closed>"); break; } WriteObjectBody(generator); WriteToken(InspectorTokenType.ObjectEnd); }
/// <summary> /// 重複した関数であるか。 /// </summary> /// <param name="generator">ジェネレータ。</param> /// <param name="sentence">センテンス。</param> /// <param name="function">関数。</param> /// <returns>重複した関数であるか。</returns> private static bool IsDuplicationFunction(GeneratorBase generator, Sentence sentence, string function) { if (!ReferenceEquals(generator, sentence.Owner)) { return false; } if (sentence.Tokens.Length <= 2) { return false; } if (!(sentence.Tokens[0] is TokenName) || (sentence.Tokens[1] == null)) { return false; } return sentence.Tokens[1].ToString().IndexOf("." + function) == 0; }
public void Add(GeneratorBase generator) { var generatorBase = generator as ContractGeneratorBase; if (generatorBase != null) { generatorBase.MetadataProvider = MetadataProvider; Formatter.AddNamespace(generatorBase.ContractDefinition.Namespace); } generator.Output = Output; generator.Formatter = Formatter; generator.IntendProvider = IntendProvider; _contractGenerator.Add(generator); }