using System; using System.Diagnostics; namespace NTERA.Engine.Compiler { [DebuggerDisplay("{Name} ({Parameters.Length})")] public class FunctionDefinition { public string Name { get; } public FunctionParameter[] Parameters { get; } public FunctionVariable[] Variables { get; } public bool IsReturnFunction { get; } public string Filename { get; } public Marker Position { get; } public FunctionDefinition(string name, FunctionParameter[] parameters, FunctionVariable[] methodVariables, bool isReturnFunction, string filename, Marker position = default(Marker)) { Name = name; Parameters = parameters; Variables = methodVariables; IsReturnFunction = isReturnFunction; Filename = filename; Position = position; } } [Flags] public enum VariableType { None = 0, Constant = 1, Reference = 2, Dynamic = 4, SaveData = 8, CharaData = 16, Global = 32, } public class FunctionVariable { public string Name { get; } public ValueType ValueType { get; } public VariableType VariableType { get; } public Value? DefaultValue { get; } public Value CalculatedValue => DefaultValue.HasValue ? DefaultValue.Value : ValueType == ValueType.String ? new Value("") : new Value(0d); //for some reason, this can't be null coalesce (??), as it disregards the value public FunctionVariable(string name, ValueType valueType, VariableType variableType = VariableType.None, Value? defaultValue = null) { Name = name; ValueType = valueType; VariableType = variableType; DefaultValue = defaultValue; } } public class FunctionParameter { public string Name { get; } public string[] Indices { get; } public bool IsArrayParameter { get; } public Value? DefaultValue { get; } public FunctionParameter(string name, string[] indices, Value? defaultValue = null, bool isArrayParameter = false) { Name = name; Indices = indices; DefaultValue = defaultValue; IsArrayParameter = isArrayParameter; } } }