void IScopeAppender.AddStaticBasedScope(IVariableInstance variable) { _operationalStaticScope.AddNativeVariable(variable); _operationalObjectScope.AddNativeVariable(variable); _conflictScope.AddNative(variable); _parseInfo.TranslateInfo.GetComponent <StaticVariableCollection>().AddVariable(variable); }
public ArrayType(CodeType arrayOfType) : base(arrayOfType.Name + "[]") { ArrayOfType = arrayOfType; _scope.AddNativeVariable(_length); AddConditionalFunction <V_FilteredArray>("FilteredArray", "A copy of the specified array with any values that do not match the specified condition removed.", this, "The condition that is evaluated for each element of the copied array. If the condition is true, the element is kept in the copied array."); AddConditionalFunction <V_SortedArray>("SortedArray", "A copy of the specified array with the values sorted according to the value rank that is evaluated for each element.", this, "The value that is evaluated for each element of the copied array. The array is sorted by this rank in ascending order."); AddConditionalFunction <V_IsTrueForAny>("IsTrueForAny", "Whether the specified condition evaluates to true for any value in the specified array.", null); AddConditionalFunction <V_IsTrueForAll>("IsTrueForAll", "Whether the specified condition evaluates to true for every value in the specified array.", null); }
public ValueGroupType(EnumData enumData, bool constant) : base(enumData.CodeName) { Constant = constant; EnumData = enumData; foreach (EnumMember member in enumData.Members) { EnumValuePair newPair = new EnumValuePair(member, constant, this); ValuePairs.Add(newPair); Scope.AddNativeVariable(newPair); } }
private InternalVar CreateInternalVar(string name, string documentation, CodeType type, bool isStatic = false) { // Create the variable. InternalVar newInternalVar = new InternalVar(name, type, CompletionItemKind.Property) { // IsSettable = false, // Make the variable unsettable. Documentation = documentation // Set the documentation. }; // Add the variable to the object scope. if (!isStatic) { objectScope.AddNativeVariable(newInternalVar); } // Add the variable to the static scope. else { staticScope.AddNativeVariable(newInternalVar); } return(newInternalVar); }
public ValueGroupType(EnumData enumData, bool constant) : base(enumData.CodeName) { Scope = new Scope("enum " + Name); Constant = constant; EnumData = enumData; TokenType = TokenType.Enum; if (constant) { TokenModifiers.Add(TokenModifier.Readonly); } foreach (EnumMember member in enumData.Members) { EnumValuePair newPair = new EnumValuePair(member, constant, this); ValuePairs.Add(newPair); Scope.AddNativeVariable(newPair); } }
public ValueGroupType(ElementEnum enumData, ITypeSupplier types, bool constant) : base(enumData.Name) { _staticScope = new Scope("enum " + Name); _objectScope = new Scope("enum " + Name); _constant = constant; EnumData = enumData; TokenType = SemanticTokenType.Enum; if (constant) { TokenModifiers.Add(TokenModifier.Readonly); } foreach (ElementEnumMember member in enumData.Members) { EnumValuePair newPair = new EnumValuePair(member, constant, this); _valuePairs.Add(newPair); _staticScope.AddNativeVariable(newPair); } Operations.DefaultAssignment = !constant; }
public ArrayType(CodeType arrayOfType) : base((arrayOfType?.Name ?? "define") + "[]") { ArrayOfType = arrayOfType; _length = new InternalVar("Length", CompletionItemKind.Property); _last = new InternalVar("Last", ArrayOfType, CompletionItemKind.Property); _first = new InternalVar("First", ArrayOfType, CompletionItemKind.Property); _scope.AddNativeVariable(_length); _scope.AddNativeVariable(_last); _scope.AddNativeVariable(_first); // Filtered Array Func(new FuncMethodBuilder() { Name = "FilteredArray", Documentation = "A copy of the specified array with any values that do not match the specified condition removed.", DoesReturnValue = true, ReturnType = this, Parameters = new CodeParameter[] { new CodeParameter("conditionLambda", "The condition that is evaluated for each element of the copied array. If the condition is true, the element is kept in the copied array.", new MacroLambda(null, ArrayOfType)) }, Action = (actionSet, methodCall) => GenericSort <V_FilteredArray>(actionSet, methodCall) }); // Sorted Array Func(new FuncMethodBuilder() { Name = "SortedArray", Documentation = "A copy of the specified array with the values sorted according to the value rank that is evaluated for each element.", DoesReturnValue = true, ReturnType = this, Parameters = new CodeParameter[] { new CodeParameter("conditionLambda", "The value that is evaluated for each element of the copied array. The array is sorted by this rank in ascending order.", new MacroLambda(null, ArrayOfType)) }, Action = (actionSet, methodCall) => GenericSort <V_SortedArray>(actionSet, methodCall) }); // Is True For Any Func(new FuncMethodBuilder() { Name = "IsTrueForAny", Documentation = "Whether the specified condition evaluates to true for any value in the specified array.", DoesReturnValue = true, Parameters = new CodeParameter[] { new CodeParameter("conditionLambda", "The condition that is evaluated for each element of the specified array.", new MacroLambda(null, ArrayOfType)) }, Action = (actionSet, methodCall) => GenericSort <V_IsTrueForAny>(actionSet, methodCall) }); // Is True For All Func(new FuncMethodBuilder() { Name = "IsTrueForAll", Documentation = "Whether the specified condition evaluates to true for every value in the specified array.", DoesReturnValue = true, Parameters = new CodeParameter[] { new CodeParameter("conditionLambda", "The condition that is evaluated for each element of the specified array.", new MacroLambda(null, ArrayOfType)) }, Action = (actionSet, methodCall) => GenericSort <V_IsTrueForAll>(actionSet, methodCall) }); // Contains Func(new FuncMethodBuilder() { Name = "Contains", Documentation = "Wether the array contains the specified value.", DoesReturnValue = true, Parameters = new CodeParameter[] { new CodeParameter("value", "The value that is being looked for in the array.", ArrayOfType) }, Action = (actionSet, methodCall) => Element.Part <V_ArrayContains>(actionSet.CurrentObject, methodCall.ParameterValues[0]) }); // Random Func(new FuncMethodBuilder() { Name = "Random", Documentation = "Gets a random value from the array.", DoesReturnValue = true, ReturnType = ArrayOfType, Action = (actionSet, methodCall) => Element.Part <V_RandomValueInArray>(actionSet.CurrentObject) }); // Randomize Func(new FuncMethodBuilder() { Name = "Randomize", Documentation = "Returns a copy of the array that is randomized.", DoesReturnValue = true, ReturnType = this, Action = (actionSet, methodCall) => Element.Part <V_RandomizedArray>(actionSet.CurrentObject) }); // Append Func(new FuncMethodBuilder() { Name = "Append", Documentation = "A copy of the array with the specified value appended to it.", DoesReturnValue = true, ReturnType = this, Parameters = new CodeParameter[] { new CodeParameter("value", "The value that is appended to the array. If the value is an array, it will be flattened.") }, Action = (actionSet, methodCall) => Element.Part <V_Append>(actionSet.CurrentObject, methodCall.ParameterValues[0]) }); // Remove Func(new FuncMethodBuilder() { Name = "Remove", Documentation = "A copy of the array with the specified value removed from it.", DoesReturnValue = true, ReturnType = this, Parameters = new CodeParameter[] { new CodeParameter("value", "The value that is removed from the array.") }, Action = (actionSet, methodCall) => Element.Part <V_RemoveFromArray>(actionSet.CurrentObject, methodCall.ParameterValues[0]) }); // Slice Func(new FuncMethodBuilder() { Name = "Slice", Documentation = "A copy of the array containing only values from a specified index range.", DoesReturnValue = true, ReturnType = this, Parameters = new CodeParameter[] { new CodeParameter("startIndex", "The first index of the range."), new CodeParameter("count", "The number of elements in the resulting array. The resulting array will contain fewer elements if the specified range exceeds the bounds of the array.") }, Action = (actionSet, methodCall) => Element.Part <V_ArraySlice>(actionSet.CurrentObject, methodCall.ParameterValues[0], methodCall.ParameterValues[1]) }); // Index Of Func(new FuncMethodBuilder() { Name = "IndexOf", Documentation = "The index of a value within an array or -1 if no such value can be found.", DoesReturnValue = true, Parameters = new CodeParameter[] { new CodeParameter("value", "The value for which to search.") }, Action = (actionSet, methodCall) => Element.Part <V_IndexOfArrayValue>(actionSet.CurrentObject, methodCall.ParameterValues[0]) }); }
void SetupScope() { if (_scopeInstance != null) { return; } _scopeInstance = new Scope(); _operationsInstance = new TypeOperatorInfo(this); Scope.AddNativeVariable(_length); Scope.AddNativeVariable(_last); Scope.AddNativeVariable(_first); var pipeType = new PipeType(ArrayOfType, this); var functionHandler = ArrayOfType.ArrayHandler.GetFunctionHandler(); // Filtered Array new GenericSortFunction() { Name = "FilteredArray", Documentation = "A copy of the specified array with any values that do not match the specified condition removed.", ReturnType = this, ArrayOfType = ArrayOfType, FuncType = _supplier.Boolean(), ParameterDocumentation = "The condition that is evaluated for each element of the copied array. If the condition is true, the element is kept in the copied array.", Function = "Filtered Array", Executor = functionHandler.FilteredArray() }.Add(Scope, _supplier); // Sorted Array new GenericSortFunction() { Name = "SortedArray", Documentation = "A copy of the specified array with the values sorted according to the value rank that is evaluated for each element.", ReturnType = this, ArrayOfType = ArrayOfType, FuncType = _supplier.Boolean(), ParameterDocumentation = "The value that is evaluated for each element of the copied array. The array is sorted by this rank in ascending order.", Function = "Sorted Array", Executor = functionHandler.SortedArray() }.Add(Scope, _supplier); // Is True For Any new GenericSortFunction() { Name = "IsTrueForAny", Documentation = "Whether the specified condition evaluates to true for any value in the specified array.", ReturnType = _supplier.Boolean(), ArrayOfType = ArrayOfType, FuncType = _supplier.Boolean(), ParameterDocumentation = "The condition that is evaluated for each element of the specified array.", Function = "Is True For Any", Executor = functionHandler.Any() }.Add(Scope, _supplier); // Is True For All new GenericSortFunction() { Name = "IsTrueForAll", Documentation = "Whether the specified condition evaluates to true for every value in the specified array.", ReturnType = _supplier.Boolean(), ArrayOfType = ArrayOfType, FuncType = _supplier.Boolean(), ParameterDocumentation = "The condition that is evaluated for each element of the specified array.", Function = "Is True For All", Executor = functionHandler.All() }.Add(Scope, _supplier); // Mapped var mapGenericParameter = new AnonymousType("T", new AnonymousTypeAttributes(false)); var mapmethodInfo = new MethodInfo(new[] { mapGenericParameter }); mapGenericParameter.Context = mapmethodInfo.Tracker; new GenericSortFunction() { Name = "Map", Documentation = "Whether the specified condition evaluates to true for every value in the specified array.", ReturnType = new ArrayType(_supplier, mapGenericParameter), ArrayOfType = ArrayOfType, FuncType = mapGenericParameter, ParameterDocumentation = "The condition that is evaluated for each element of the specified array.", Function = "Mapped Array", Executor = functionHandler.Map(), MethodInfo = mapmethodInfo }.Add(Scope, _supplier); // Contains Func(new FuncMethodBuilder() { Name = "Contains", Documentation = "Whether the array contains the specified value.", ReturnType = _supplier.Boolean(), Parameters = new CodeParameter[] { new CodeParameter("value", "The value that is being looked for in the array.", ArrayOfType) }, Action = (actionSet, methodCall) => functionHandler.Contains(actionSet.CurrentObject, methodCall.ParameterValues[0]) }); // Random if (functionHandler.AllowUnhandled) { Func(new FuncMethodBuilder() { Name = "Random", Documentation = "Gets a random value from the array.", ReturnType = ArrayOfType, Action = (actionSet, methodCall) => Element.Part("Random Value In Array", actionSet.CurrentObject) }); } // Randomize if (functionHandler.AllowUnhandled) { Func(new FuncMethodBuilder() { Name = "Randomize", Documentation = "Returns a copy of the array that is randomized.", ReturnType = this, Action = (actionSet, methodCall) => Element.Part("Randomized Array", actionSet.CurrentObject) }); } // Append if (functionHandler.AllowUnhandled) { Func(new FuncMethodBuilder() { Name = "Append", Documentation = "A copy of the array with the specified value appended to it.", ReturnType = this, Parameters = new CodeParameter[] { new CodeParameter("value", "The value that is appended to the array. If the value is an array, it will be flattened.", pipeType) }, Action = (actionSet, methodCall) => Element.Append(actionSet.CurrentObject, methodCall.ParameterValues[0]) }); } // Remove if (functionHandler.AllowUnhandled) { Func(new FuncMethodBuilder() { Name = "Remove", Documentation = "A copy of the array with the specified value removed from it.", ReturnType = this, Parameters = new CodeParameter[] { new CodeParameter("value", "The value that is removed from the array.", pipeType) }, Action = (actionSet, methodCall) => Element.Part("Remove From Array", actionSet.CurrentObject, methodCall.ParameterValues[0]) }); } // Slice if (functionHandler.AllowUnhandled) { Func(new FuncMethodBuilder() { Name = "Slice", Documentation = "A copy of the array containing only values from a specified index range.", ReturnType = this, Parameters = new CodeParameter[] { new CodeParameter("startIndex", "The first index of the range.", _supplier.Number()), new CodeParameter("count", "The number of elements in the resulting array. The resulting array will contain fewer elements if the specified range exceeds the bounds of the array.", _supplier.Number()) }, Action = (actionSet, methodCall) => Element.Part("Array Slice", actionSet.CurrentObject, methodCall.ParameterValues[0], methodCall.ParameterValues[1]) }); } // Index Of if (functionHandler.AllowUnhandled) { Func(new FuncMethodBuilder() { Name = "IndexOf", Documentation = "The index of a value within an array or -1 if no such value can be found.", ReturnType = _supplier.Number(), Parameters = new CodeParameter[] { new CodeParameter("value", "The value for which to search.", ArrayOfType) }, Action = (actionSet, methodCall) => Element.IndexOfArrayValue(actionSet.CurrentObject, methodCall.ParameterValues[0]) }); } // Modify Append Func(new FuncMethodBuilder() { Name = "ModAppend", Documentation = "Appends a value to the array. This will modify the array directly rather than returning a copy of the array. The source expression must be a variable.", Parameters = new CodeParameter[] { new CodeParameter("value", "The value that is pushed to the array.", pipeType) }, OnCall = SourceVariableResolver.GetSourceVariable, ReturnType = _supplier.Number(), Action = (actionSet, methodCall) => SourceVariableResolver.Modify(actionSet, methodCall, Operation.AppendToArray) }); // Modify Remove By Value Func(new FuncMethodBuilder() { Name = "ModRemoveByValue", Documentation = "Removes an element from the array by a value. This will modify the array directly rather than returning a copy of the array. The source expression must be a variable.", Parameters = new CodeParameter[] { new CodeParameter("value", "The value that is removed from the array.", ArrayOfType) }, OnCall = SourceVariableResolver.GetSourceVariable, ReturnType = _supplier.Number(), Action = (actionSet, methodCall) => SourceVariableResolver.Modify(actionSet, methodCall, Operation.RemoveFromArrayByValue) }); // Modify Remove By Index Func(new FuncMethodBuilder() { Name = "ModRemoveByIndex", Documentation = "Removes an element from the array by the index. This will modify the array directly rather than returning a copy of the array. The source expression must be a variable.", Parameters = new CodeParameter[] { new CodeParameter("index", "The index of the element that is removed from the array.", _supplier.Number()) }, OnCall = SourceVariableResolver.GetSourceVariable, ReturnType = _supplier.Number(), Action = (actionSet, methodCall) => SourceVariableResolver.Modify(actionSet, methodCall, Operation.RemoveFromArrayByIndex) }); // Add type operations. Operations.AddTypeOperation(new[] { // + append new TypeOperation(TypeOperator.Add, pipeType, this, (l, r) => Element.Append(l, r)), // - remove new TypeOperation(TypeOperator.Subtract, pipeType, this, (l, r) => Element.Remove(l, r)) }); Operations.AddTypeOperation(new[] { // += mod append new AssignmentOperation(AssignmentOperator.AddEqual, pipeType, info => info.Modify(Operation.AppendToArray)), // -= mod remove new AssignmentOperation(AssignmentOperator.SubtractEqual, pipeType, info => info.Modify(Operation.RemoveFromArrayByValue)) }); ArrayOfType.ArrayHandler.OverrideArray(this); }
void IScopeAppender.AddObjectBasedScope(IVariableInstance variable) { _operationalObjectScope.AddNativeVariable(variable); _conflictScope.AddNative(variable); }