Ejemplo n.º 1
0
        public ArrayType(ITypeSupplier supplier, CodeType arrayOfType) : base(arrayOfType.GetNameOrAny() + "[]")
        {
            ArrayOfType   = arrayOfType;
            ArrayHandler  = arrayOfType.ArrayHandler;
            Attributes    = arrayOfType.Attributes;
            TypeSemantics = arrayOfType.TypeSemantics;
            AsReferenceResetSettability = arrayOfType.AsReferenceResetSettability;
            DebugVariableResolver       = new Debugger.ArrayResolver(ArrayOfType?.DebugVariableResolver, ArrayOfType?.GetName(), ArrayOfType is ClassType);

            Generics = new[] { arrayOfType };

            _length = new InternalVar("Length", supplier.Number(), CompletionItemKind.Property)
            {
                Ambiguous = false
            };
            _last = new InternalVar("Last", ArrayOfType, CompletionItemKind.Property)
            {
                Ambiguous = false
            };
            _first = new InternalVar("First", ArrayOfType, CompletionItemKind.Property)
            {
                Ambiguous = false
            };
            _supplier = supplier;
        }
        public TeamGroupType(ITypeSupplier typeSupplier, ElementEnum enumData) : base(enumData, typeSupplier, false)
        {
            Opposite = new InternalVar("Opposite", this, CompletionItemKind.Property)
            {
                Documentation = new MarkupBuilder()
                                .Add("The opposite team of the value. If the team value is ").Code("Team 1").Add(", Opposite will be ").Code("Team 2").Add(" and vice versa. If the value is ")
                                .Code("All").Add(", Opposite will still be ").Code("All").Add(".")
            };
            Score = new InternalVar("Score", typeSupplier.Number(), CompletionItemKind.Property)
            {
                Documentation = new MarkupBuilder()
                                .Add("The current score for the team. Results in 0 in free-for-all modes.")
            };
            OnDefense = new InternalVar("OnDefense", typeSupplier.Boolean(), CompletionItemKind.Property)
            {
                Documentation = new MarkupBuilder()
                                .Add("Whether the specified team is currently on defense. Results in False if the game mode is not Assault, Escort, or Assault/Escort.")
            };
            OnOffense = new InternalVar("OnOffense", typeSupplier.Boolean(), CompletionItemKind.Property)
            {
                Documentation = new MarkupBuilder()
                                .Add("Whether the specified team is currently on offense. Results in False if the game mode is not Assault, Escort, or Assault/Escort.")
            };

            _objectScope.AddNativeVariable(Opposite);
            _objectScope.AddNativeVariable(Score);
            _objectScope.AddNativeVariable(OnDefense);
            _objectScope.AddNativeVariable(OnOffense);
        }
Ejemplo n.º 3
0
        public static CodeType DefaultTypeFromOperator(TypeOperator op, ITypeSupplier supplier)
        {
            switch (op)
            {
            case TypeOperator.And:
            case TypeOperator.Or:
            case TypeOperator.NotEqual:
            case TypeOperator.Equal:
            case TypeOperator.GreaterThan:
            case TypeOperator.GreaterThanOrEqual:
            case TypeOperator.LessThan:
            case TypeOperator.LessThanOrEqual:
                return(supplier.Boolean());

            case TypeOperator.Add:
            case TypeOperator.Divide:
            case TypeOperator.Modulo:
            case TypeOperator.Multiply:
            case TypeOperator.Pow:
            case TypeOperator.Subtract:
                return(supplier.Number());

            default: throw new NotImplementedException(op.ToString());
            }
        }
Ejemplo n.º 4
0
 public TypeOperation(ITypeSupplier supplier, TypeOperator op, CodeType right)
 {
     Operator   = op;
     Right      = right ?? throw new ArgumentNullException(nameof(right));
     ReturnType = DefaultTypeFromOperator(op, supplier);
     Resolver   = DefaultFromOperator(op);
 }
Ejemplo n.º 5
0
 public TypeOperation(ITypeSupplier supplier, TypeOperator op, CodeType right, Func <IWorkshopTree, IWorkshopTree, IWorkshopTree> resolver)
 {
     Operator   = op;
     Right      = right ?? throw new ArgumentNullException(nameof(right));
     ReturnType = DefaultTypeFromOperator(op, supplier);
     Resolver   = resolver ?? throw new ArgumentNullException(nameof(resolver));
 }
Ejemplo n.º 6
0
 public static void AddWorkshopFunctionsToScope(Scope scope, ITypeSupplier typeSupplier)
 {
     foreach (var function in WorkshopFunctions)
     {
         scope.AddNativeMethod(function);
     }
 }
Ejemplo n.º 7
0
        public PlayerType(DeltinScript deltinScript, ITypeSupplier typeSupplier) : base("Player")
        {
            AsReferenceResetSettability = true;
            ArrayHandler = this;
            _supplier    = typeSupplier;

            deltinScript.StagedInitiation.On(this);
        }
        public VectorType(DeltinScript deltinScript, ITypeSupplier supplier) : base("Vector")
        {
            TokenType     = SemanticTokenType.Struct;
            _deltinScript = deltinScript;
            _typeSupplier = supplier;

            deltinScript.StagedInitiation.On(this);
        }
Ejemplo n.º 9
0
        private TypeOperation GetDefaultOperation(string op, ITypeSupplier supplier)
        {
            if (Left.Type() == null || Right.Type() == null || Left.Type().IsConstant() || Right.Type().IsConstant())
            {
                return(null);
            }

            return(new TypeOperation(supplier, TypeOperation.TypeOperatorFromString(op), supplier.Any()));
        }
Ejemplo n.º 10
0
        public BooleanType(ITypeSupplier supplier) : base("Boolean")
        {
            _supplier = supplier;

            Operations.AddTypeOperation(new TypeOperation[] {
                new TypeOperation(TypeOperator.And, this, this),
                new TypeOperation(TypeOperator.Or, this, this),
            });
        }
 // String Contains function
 FuncMethod ContainsFunction(ITypeSupplier supplier) => new FuncMethodBuilder()
 {
     Name          = "Contains",
     Documentation = "Determines if the string contains the specified value.",
     ReturnType    = supplier.Boolean(),
     Parameters    = new CodeParameter[] {
         new CodeParameter("value", "The substring that will be searched for.", supplier.String())
     },
     Action = (actionSet, methodCall) => Element.Part("String Contains", actionSet.CurrentObject, methodCall.Get(0))
 };
 // String Split function
 FuncMethod SplitFunction(ITypeSupplier supplier) => new FuncMethodBuilder()
 {
     Name          = "Split",
     Documentation = "Results in an Array of String Values. These String Values will be built from the specified String Value, split around the seperator String.",
     ReturnType    = supplier.Array(supplier.String()),
     Parameters    = new CodeParameter[] {
         new CodeParameter("seperator", "The seperator String with which to split the String Value.", supplier.String()),
     },
     Action = (actionSet, methodCall) => Element.Part("String Split", actionSet.CurrentObject, methodCall.Get(0))
 };
 // String Slice function
 FuncMethod CharInStringFunction(ITypeSupplier supplier) => new FuncMethodBuilder()
 {
     Name          = "CharAt",
     Documentation = "The character found at a specified index of a String.",
     ReturnType    = supplier.String(),
     Parameters    = new CodeParameter[] {
         new CodeParameter("index", "The index of the character.", supplier.Number()),
     },
     Action = (actionSet, methodCall) => Element.Part("Char In String", actionSet.CurrentObject, methodCall.Get(0))
 };
 // String Slice function
 FuncMethod IndexOfFunction(ITypeSupplier supplier) => new FuncMethodBuilder()
 {
     Name          = "IndexOf",
     Documentation = "The index of a character within a String or -1 of no such character can be found.",
     ReturnType    = supplier.Number(),
     Parameters    = new CodeParameter[] {
         new CodeParameter("character", "The character for which to search.", supplier.String()),
     },
     Action = (actionSet, methodCall) => Element.Part("Index Of String Char", actionSet.CurrentObject, methodCall.Get(0))
 };
 // String Replace function
 FuncMethod ReplaceFunction(ITypeSupplier supplier) => new FuncMethodBuilder()
 {
     Name          = "Replace",
     Documentation = "Results in a String Value. This String Value will be built from the specified String Value, where all occurrences of the pattern String are replaced with the replacement String.",
     ReturnType    = supplier.String(),
     Parameters    = new CodeParameter[] {
         new CodeParameter("pattern", "The String pattern to be replaced.", supplier.String()),
         new CodeParameter("replacement", "The String Value in which to replace the pattern String.", supplier.String())
     },
     Action = (actionSet, methodCall) => Element.Part("String Replace", actionSet.CurrentObject, methodCall.Get(0), methodCall.Get(1))
 };
 // String Slice function
 FuncMethod SliceFunction(ITypeSupplier supplier) => new FuncMethodBuilder()
 {
     Name          = "Slice",
     Documentation = "Gets a substring from the string by a specified length.",
     ReturnType    = supplier.String(),
     Parameters    = new CodeParameter[] {
         new CodeParameter("start", "The starting index of the substring.", supplier.Number()),
         new CodeParameter("length", "The length of the substring.", supplier.Number())
     },
     Action = (actionSet, methodCall) => Element.Part("String Slice", actionSet.CurrentObject, methodCall.Get(0), methodCall.Get(1))
 };
        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 static ValueGroupType[] GetEnumTypes(ITypeSupplier supplier)
        {
            var enums = ElementRoot.Instance.Enumerators;
            var types = new List <ValueGroupType>();

            foreach (var enumerator in enums)
            {
                if (!enumerator.Hidden)
                {
                    if (enumerator.Name == "Team")
                    {
                        types.Add(new TeamGroupType(supplier, enumerator));
                    }
                    else
                    {
                        types.Add(new ValueGroupType(enumerator, supplier, !enumerator.ConvertableToElement()));
                    }
                }
            }

            return(types.ToArray());
        }
        public void Add(Scope addToScope, ITypeSupplier supplier)
        {
            // value => ...
            var noIndex = GetFuncMethod();

            noIndex.Parameters = new CodeParameter[] {
                new CodeParameter("conditionLambda", ParameterDocumentation, PortableLambdaType.CreateConstantType(FuncType, ArrayOfType))
            };
            noIndex.Action = (actionSet, methodCall) =>
                             Executor.GetResult(Function, actionSet, inv => Lambda(methodCall).Invoke(actionSet, inv));

            // (value, index) => ...
            var withIndex = GetFuncMethod();

            withIndex.Parameters = new CodeParameter[] {
                new CodeParameter("conditionLambda", ParameterDocumentation, PortableLambdaType.CreateConstantType(FuncType, ArrayOfType, supplier.Number()))
            };
            withIndex.Action = (actionSet, methodCall) =>
                               Executor.GetResult(Function, actionSet, inv => Lambda(methodCall).Invoke(actionSet, inv, Element.ArrayIndex()));

            addToScope.AddNativeMethod(new FuncMethod(noIndex));
            addToScope.AddNativeMethod(new FuncMethod(withIndex));
        }
 public ConstHeroParameter(string name, string documentation, ITypeSupplier typeSupplier) : base(name, documentation, typeSupplier.Hero())
 {
 }
 public ConstNumberParameter(string name, string documentation, ITypeSupplier typeSupplier, double defaultValue) : base(name, documentation, typeSupplier.Number(), new ExpressionOrWorkshopValue(Element.Num(defaultValue)))
 {
     DefaultConstValue = defaultValue;
 }
 public ConstNumberParameter(string name, string documentation, ITypeSupplier typeSupplier) : base(name, documentation, typeSupplier.Number())
 {
 }
Ejemplo n.º 23
0
        public NumberType(DeltinScript deltinScript, ITypeSupplier supplier) : base("Number")
        {
            _supplier = supplier;

            deltinScript.StagedInitiation.On(this);
        }
Ejemplo n.º 24
0
 public MapParameter(ITypeSupplier typeSupplier) : base("map", "The map to compare.", typeSupplier.Map())
 {
 }
 public ConstBoolParameter(string name, string documentation, ITypeSupplier typeSupplier) : base(name, documentation, typeSupplier.Boolean())
 {
 }
 public StringType(DeltinScript deltinScript, ITypeSupplier typeSupplier) : base("String")
 {
     _typeSupplier = typeSupplier;
     deltinScript.StagedInitiation.On(this);
 }
Ejemplo n.º 27
0
 public PathResolveClass(DeltinScript deltinScript)
 {
     _supplier        = deltinScript.Types;
     _pathfinderTypes = deltinScript.GetComponent <PathfinderTypesComponent>();
     Provider         = new SelfContainedClassProvider(deltinScript, this);
 }
 public StringFormatArrayParameter(ITypeSupplier types) : base("args", types.AnyArray())
 {
 }
 public ConstBoolParameter(string name, string documentation, ITypeSupplier typeSupplier, bool defaultValue)
     : base(name, documentation, typeSupplier.Boolean(), new ExpressionOrWorkshopValue(defaultValue ? Element.True() : Element.False()))
 {
 }
 public static bool IsAny(ITypeSupplier supplier, CodeType type) => type.Implements(supplier.Any());