public static DMExpression Create(DMObject dmObject, DMProc proc, DMASTExpression expression, DreamPath?inferredPath = null) { var instance = new DMVisitorExpression(dmObject, proc, inferredPath); expression.Visit(instance); return(instance.Result); }
public DMASTProcStatementForRange(DMASTProcStatement initializer, DMASTIdentifier variable, DMASTExpression rangeStart, DMASTExpression rangeEnd, DMASTExpression step, DMASTProcBlockInner body) : base(initializer, body) { Variable = variable; RangeStart = rangeStart; RangeEnd = rangeEnd; Step = step; }
public DMASTDefinitionParameter(DMASTPath path, DMASTExpression value, DMValueType type, DMASTExpression possibleValues) { Path = path; Value = value; Type = type; PossibleValues = possibleValues; }
private void SetVariableValue(DMVariable variable, DMASTExpression value, DMValueType valType = DMValueType.Anything) { DMVisitorExpression._scopeMode = variable.IsGlobal ? "static" : "normal"; DMExpression expression = DMExpression.Create(_currentObject, variable.IsGlobal ? DMObjectTree.GlobalInitProc : null, value, variable.Type); DMVisitorExpression._scopeMode = "normal"; expression.ValType = valType; if (expression.TryAsConstant(out var constant)) { variable.Value = constant; return; } if (variable.IsConst) { throw new CompileErrorException(value.Location, "Value of const var must be a constant"); } //Whether this should be initialized at runtime bool isValid = expression switch { //TODO: A better way of handling procs evaluated at compile time Expressions.ProcCall procCall => procCall.GetTargetProc(_currentObject).Proc?.Name switch { "rgb" => true, "generator" => true, "matrix" => true, "icon" => true, "file" => true, "sound" => true, _ => variable.IsGlobal },
public DMASTProcStatementForLoop(DMASTProcStatementVarDeclaration variableDeclaration, DMASTCallable variable, DMASTExpression condition, DMASTExpression incrementer, DMASTProcBlockInner body) { VariableDeclaration = variableDeclaration; Variable = variable; Condition = condition; Incrementer = incrementer; Body = body; }
public DMASTProcStatementVarDeclaration(DMASTPath path, DMASTExpression value) { int varElementIndex = path.Path.FindElement("var"); DreamPath typePath = path.Path.FromElements(varElementIndex + 1, -2); Type = (typePath.Elements.Length > 0) ? new DMASTPath(typePath) : null; Name = path.Path.LastElement; Value = value; }
private void SetVariableValue(DMVariable variable, DMASTExpression value, DMValueType valType = DMValueType.Anything) { DMVisitorExpression._scopeMode = variable.IsGlobal ? "static" : "normal"; DMExpression expression = DMExpression.Create(_currentObject, variable.IsGlobal ? DMObjectTree.GlobalInitProc : null, value, variable.Type); DMVisitorExpression._scopeMode = "normal"; expression.ValType = valType; if (expression.TryAsConstant(out var constant)) { variable.Value = constant; return; } if (variable.IsConst) { throw new CompileErrorException(value.Location, "Value of const var must be a constant"); } switch (expression) { case Expressions.List: case Expressions.NewList: case Expressions.NewPath: //TODO: A better way of handling procs evaluated at compile time case Expressions.ProcCall procCall when procCall.GetTargetProc(_currentObject).Proc?.Name == "rgb": variable.Value = new Expressions.Null(Location.Unknown); EmitInitializationAssign(variable, expression); break; case Expressions.ProcCall procCall when procCall.GetTargetProc(_currentObject).Proc?.Name == "generator": variable.Value = new Expressions.Null(Location.Unknown); EmitInitializationAssign(variable, expression); break; case Expressions.StringFormat: case Expressions.ProcCall: if (!variable.IsGlobal) { throw new CompileErrorException(value.Location, $"Invalid initial value for \"{variable.Name}\""); } variable.Value = new Expressions.Null(Location.Unknown); EmitInitializationAssign(variable, expression); break; default: throw new CompileErrorException(value.Location, $"Invalid initial value for \"{variable.Name}\""); } }
bool?SimpleTruth(DMASTExpression expr) { switch (expr) { case DMASTConstantInteger e: return(e.Value != 0); case DMASTConstantFloat e: return(e.Value != 0); case DMASTConstantString e: return(e.Value.Length != 0); case DMASTConstantNull: return(false); case DMASTConstantPath: return(true); case DMASTConstantResource: return(true); default: return(null); } }
public DMASTObjectVarDefinition(DMASTPath astPath, DMASTExpression value) { DreamPath path = astPath.Path; int globalElementIndex = path.FindElement("global"); if (globalElementIndex != -1) { path = path.RemoveElement(globalElementIndex); IsGlobal = true; } int varElementIndex = path.FindElement("var"); DreamPath varPath = path.FromElements(varElementIndex + 1, -1); ObjectPath = (varElementIndex > 1) ? new DMASTPath(path.FromElements(0, varElementIndex)) : null; Type = (varPath.Elements.Length > 1) ? new DMASTPath(varPath.FromElements(0, -2)) : null; Name = varPath.LastElement; Value = value; }
public DMASTLeftShift(DMASTExpression a, DMASTExpression b) { A = a; B = b; }
public DMASTBinaryNot(DMASTExpression value) { Value = value; }
public DMASTProcStatementForList(DMASTProcStatement initializer, DMASTIdentifier variable, DMASTExpression list, DMASTProcBlockInner body) : base(initializer, body) { Variable = variable; List = list; }
public DMASTProcStatementForStandard(DMASTProcStatement initializer, DMASTExpression comparator, DMASTExpression incrementor, DMASTProcBlockInner body) : base(initializer, body) { Comparator = comparator; Incrementor = incrementor; }
public DMASTProcStatementIf(DMASTExpression condition, DMASTProcBlockInner body, DMASTProcBlockInner elseBody = null) { Condition = condition; Body = body; ElseBody = elseBody; }
public DMASTListIndex(DMASTExpression expression, DMASTExpression index) { Expression = expression; Index = index; }
public DMASTProcStatementOutputControl(DMASTExpression receiver, DMASTExpression message, DMASTExpression control) { Receiver = receiver; Message = message; Control = control; }
public DMASTProcStatementBrowse(DMASTExpression receiver, DMASTExpression body, DMASTExpression options) { Receiver = receiver; Body = body; Options = options; }
public DMASTProcStatementDoWhile(DMASTExpression conditional, DMASTProcBlockInner body) { Conditional = conditional; Body = body; }
public DMASTProcStatementExpression(DMASTExpression expression) { Expression = expression; }
public DMASTObjectVarOverride(DMASTPath path, DMASTExpression value) { ObjectPath = (path.Path.Elements.Length > 1) ? new DMASTPath(path.Path.FromElements(0, -2)) : null; VarName = path.Path.LastElement; Value = value; }
public DMASTDereferenceProc(DMASTExpression expression, Dereference[] dereferences) : base(expression, dereferences) { }
public DMASTDereference(DMASTExpression expression, Dereference[] dereferences) { Expression = expression; Dereferences = dereferences; }
public DMASTRightShift(DMASTExpression a, DMASTExpression b) { A = a; B = b; }
public DMASTCallParameter(DMASTExpression value, string name = null) { Value = value; Name = name; }
public DMASTProcStatementSwitch(DMASTExpression value, SwitchCase[] cases) { Value = value; Cases = cases; }
public DMASTProcStatementReturn(DMASTExpression value) { Value = value; }
public DMASTProcStatementBrowseResource(DMASTExpression receiver, DMASTExpression file, DMASTExpression filename) { Receiver = receiver; File = file; Filename = filename; }
public DMASTProcStatementDel(DMASTExpression value) { Value = value; }
public DMASTProcStatementSpawn(DMASTExpression time, DMASTProcBlockInner body) { Time = time; Body = body; }
public DMASTExpressionIn(DMASTExpression value, DMASTExpression list) { Value = value; List = list; }