protected abstract void TranslateNewArray(List <string> output, StringConstant type, Expression size);
protected abstract void TranslateNewList(List <string> output, StringConstant type);
protected abstract void TranslateCast(List <string> output, StringConstant typeValue, Expression expression);
protected abstract void TranslateComment(List <string> output, StringConstant commentValue);
public RegisterUserCommand(string userId, string password) { UserId = new StringConstant(userId); Password = new StringConstant(password); }
public ExportKeysCommand(string fileUri) { FileUri = new StringConstant(fileUri); }
public override void VisitStringConstant(StringConstant node) { Append("\'" + node.Value + "\'"); }
private static Expression ParseEntityWithoutSuffixChain(TokenStream tokens, Executable owner) { string next = tokens.PeekValue(); if (next == "null") { return(new NullConstant(tokens.Pop(), owner)); } if (next == "true") { return(new BooleanConstant(tokens.Pop(), true, owner)); } if (next == "false") { return(new BooleanConstant(tokens.Pop(), false, owner)); } Token peekToken = tokens.Peek(); if (next.StartsWith("'")) { return(new StringConstant(tokens.Pop(), StringConstant.ParseOutRawValue(peekToken), owner)); } if (next.StartsWith("\"")) { return(new StringConstant(tokens.Pop(), StringConstant.ParseOutRawValue(peekToken), owner)); } if (next == "new") { return(ParseInstantiate(tokens, owner)); } char firstChar = next[0]; if (VARIABLE_STARTER.Contains(firstChar)) { Token varToken = tokens.Pop(); return(new Variable(varToken, varToken.Value, owner)); } if (firstChar == '[') { Token bracketToken = tokens.PopExpected("["); List <Expression> elements = new List <Expression>(); bool previousHasCommaOrFirst = true; while (!tokens.PopIfPresent("]")) { if (!previousHasCommaOrFirst) { tokens.PopExpected("]"); // throws appropriate error } elements.Add(Parse(tokens, owner)); previousHasCommaOrFirst = tokens.PopIfPresent(","); } return(new ListDefinition(bracketToken, elements, owner)); } if (firstChar == '{') { Token braceToken = tokens.PopExpected("{"); List <Expression> keys = new List <Expression>(); List <Expression> values = new List <Expression>(); bool previousHasCommaOrFirst = true; while (!tokens.PopIfPresent("}")) { if (!previousHasCommaOrFirst) { tokens.PopExpected("}"); // throws appropriate error } keys.Add(Parse(tokens, owner)); tokens.PopExpected(":"); values.Add(Parse(tokens, owner)); previousHasCommaOrFirst = tokens.PopIfPresent(","); } return(new DictionaryDefinition(braceToken, keys, values, owner)); } if (next.Length > 2 && next.Substring(0, 2) == "0x") { Token intToken = tokens.Pop(); int intValue = IntegerConstant.ParseIntConstant(intToken, intToken.Value); return(new IntegerConstant(intToken, intValue, owner)); } if (Parser.IsInteger(next)) { Token numberToken = tokens.Pop(); string numberValue = numberToken.Value; if (tokens.IsNext(".")) { Token decimalToken = tokens.Pop(); if (decimalToken.HasWhitespacePrefix) { throw new ParserException(decimalToken, "Decimals cannot have whitespace before them."); } Token afterDecimal = tokens.Pop(); if (afterDecimal.HasWhitespacePrefix) { throw new ParserException(afterDecimal, "Cannot have whitespace after the decimal."); } if (!Parser.IsInteger(afterDecimal.Value)) { throw new ParserException(afterDecimal, "Decimal must be followed by an integer."); } numberValue += "." + afterDecimal.Value; double floatValue = FloatConstant.ParseValue(numberToken, numberValue); return(new FloatConstant(numberToken, floatValue, owner)); } int intValue = IntegerConstant.ParseIntConstant(numberToken, numberToken.Value); return(new IntegerConstant(numberToken, intValue, owner)); } if (tokens.IsNext(".")) { Token dotToken = tokens.PopExpected("."); string numberValue = "0."; Token postDecimal = tokens.Pop(); if (postDecimal.HasWhitespacePrefix || !Parser.IsInteger(postDecimal.Value)) { throw new ParserException(dotToken, "Unexpected dot."); } numberValue += postDecimal.Value; double floatValue; if (double.TryParse(numberValue, out floatValue)) { return(new FloatConstant(dotToken, floatValue, owner)); } throw new ParserException(dotToken, "Invalid float literal."); } throw new ParserException(tokens.Peek(), "Encountered unexpected token: '" + tokens.PeekValue() + "'"); }
public WhileType TypeExpression(StringConstant stringConst, CompilerContext context) { stringConst.CompilerScope = context.CurrentScope; return(WhileType.STRING); }
private Expression ParseEntityWithoutSuffixChain(TokenStream tokens, Node owner) { tokens.EnsureNotEof(); Token nextToken = tokens.Peek(); string next = nextToken.Value; if (next == this.parser.Keywords.NULL) { return(new NullConstant(tokens.Pop(), owner)); } if (next == this.parser.Keywords.TRUE) { return(new BooleanConstant(tokens.Pop(), true, owner)); } if (next == this.parser.Keywords.FALSE) { return(new BooleanConstant(tokens.Pop(), false, owner)); } if (next == this.parser.Keywords.THIS) { return(new ThisKeyword(tokens.Pop(), owner)); } if (next == this.parser.Keywords.BASE) { return(new BaseKeyword(tokens.Pop(), owner)); } Token peekToken = tokens.Peek(); if (next.StartsWith("'")) { return(new StringConstant(tokens.Pop(), StringConstant.ParseOutRawValue(peekToken), owner)); } if (next.StartsWith("\"")) { return(new StringConstant(tokens.Pop(), StringConstant.ParseOutRawValue(peekToken), owner)); } if (next == "@") // Raw strings (no escape sequences, a backslash is a literal backslash) { Token atToken = tokens.Pop(); Token stringToken = tokens.Pop(); char stringTokenChar = stringToken.Value[0]; if (stringTokenChar != '"' && stringTokenChar != '\'') { throw new ParserException(atToken, "Unexpected token: '@'"); } string stringValue = stringToken.Value.Substring(1, stringToken.Value.Length - 2); return(new StringConstant(atToken, stringValue, owner)); } if (next == this.parser.Keywords.NEW) { return(this.ParseInstantiate(tokens, owner)); } char firstChar = next[0]; if (nextToken.Type == TokenType.WORD) { Token varToken = tokens.Pop(); if (tokens.IsNext("=>")) { return(this.ParseLambda( tokens, varToken, new AType[] { AType.Any() }, new Token[] { varToken }, owner)); } else { return(new Variable(varToken, varToken.Value, owner)); } } if (firstChar == '[' && nextToken.File.CompilationScope.IsCrayon) { Token bracketToken = tokens.PopExpected("["); List <Expression> elements = new List <Expression>(); bool previousHasCommaOrFirst = true; while (!tokens.PopIfPresent("]")) { if (!previousHasCommaOrFirst) { tokens.PopExpected("]"); // throws appropriate error } elements.Add(Parse(tokens, owner)); previousHasCommaOrFirst = tokens.PopIfPresent(","); } return(new ListDefinition(bracketToken, elements, AType.Any(), owner, false, null)); } if (firstChar == '{' && nextToken.File.CompilationScope.IsCrayon) { Token braceToken = tokens.PopExpected("{"); List <Expression> keys = new List <Expression>(); List <Expression> values = new List <Expression>(); bool previousHasCommaOrFirst = true; while (!tokens.PopIfPresent("}")) { if (!previousHasCommaOrFirst) { tokens.PopExpected("}"); // throws appropriate error } keys.Add(Parse(tokens, owner)); tokens.PopExpected(":"); values.Add(Parse(tokens, owner)); previousHasCommaOrFirst = tokens.PopIfPresent(","); } return(new DictionaryDefinition(braceToken, AType.Any(), AType.Any(), keys, values, owner)); } if (nextToken.Type == TokenType.NUMBER) { if (next.Contains(".")) { double floatValue; if (double.TryParse(next, out floatValue)) { return(new FloatConstant(tokens.Pop(), floatValue, owner)); } throw new ParserException(nextToken, "Invalid float literal."); } return(new IntegerConstant( tokens.Pop(), IntegerConstant.ParseIntConstant(nextToken, next), owner)); } throw new ParserException(tokens.Peek(), "Encountered unexpected token: '" + tokens.PeekValue() + "'"); }
protected override void TranslateNewDictionary(List <string> output, StringConstant keyType, StringConstant valueType) { CSharpPlatform platform = (CSharpPlatform)this.Platform; string csharpKeyType = platform.GetTypeStringFromAnnotation(keyType.FirstToken, keyType.Value); string csharpValueType = platform.GetTypeStringFromAnnotation(valueType.FirstToken, valueType.Value); output.Add("new Dictionary<"); output.Add(csharpKeyType); output.Add(", "); output.Add(csharpValueType); output.Add(">()"); }
protected override void TranslateConvertListToArray(List <string> output, StringConstant type, Expression list) { this.Translator.TranslateExpression(output, list); output.Add(".ToArray()"); }
protected override void TranslateComment(List <string> output, StringConstant commentValue) { #if DEBUG output.Add("// " + commentValue.Value); #endif }
protected override void TranslateCast(List <string> output, StringConstant typeValue, Expression expression) { this.Translator.TranslateExpression(output, expression); }
/// <summary> /// Check if the tag provided is associated with this `GameObject`. /// </summary> /// <param name="go">This `GameObject`</param> /// <param name="tag">The tag to search for.</param> /// <returns>`true` if the tag exists, otherwise `false`.</returns> public static bool HasTag(this GameObject go, StringConstant tag) { return(go.HasTag(tag.Value)); }
private void CheckGetCodeWordCount(String value, Int32 expected, String message) { StringConstant target = new StringConstant(value); ICodeGeneratorTest.CheckGetCodeWordCount(target, expected, message); }
private List <KeyValuePair <string, bool> > GetFunctionNames() { // NOTE: moving to LuaScriptFunction.HandleUpvalues()!!! // TODO: move this over to NOT ONLY the root function!! List <KeyValuePair <string, bool> > names = new List <KeyValuePair <string, bool> >(); // NOTE: Global functions use GETGLOBAL to get first parts, then // CLOSURE to set the variables they just got, and then SETTABLE // to move a constant (second part of func name) into the global // also, while we are at it, lets check if it sets global or not for (int i = 0; i < this.Decoder.File.Function.Instructions.Count; i++) { var instr = this.Decoder.File.Function.Instructions[i]; switch (instr.OpCode) { case LuaOpcode.CLOSURE: string name = ""; string globalName = ""; bool isGlobal = false; int j = i - 1; // Find GETGLOBAL while (j >= 0) { if (this.Decoder.File.Function.Instructions[j].OpCode == LuaOpcode.CLOSURE) { break; // start of another closure } if (this.Decoder.File.Function.Instructions[j].OpCode == LuaOpcode.GETGLOBAL) { globalName = this.Decoder.File.Function.Constants[j].ToString(); globalName = globalName.Substring(1, globalName.Length - 2); break; // job's done } j++; } j = i + 1; // Find SETTABLE while (j < this.Decoder.File.Function.Instructions.Count) { if (this.Decoder.File.Function.Instructions[j].OpCode == LuaOpcode.CLOSURE) { break; // meh } if (this.Decoder.File.Function.Instructions[j].OpCode == LuaOpcode.MOVE) { // upvalues! if (this.Decoder.File.Function.Instructions[j].A == 0) // 0 = _ENV { LuaConstant cons; //if (this.Decoder.File.Function.Constants.Count > this.Decoder.File.Function.Instructions[j].B) // cons = this.Decoder.File.Function.Constants[this.Decoder.File.Function.Instructions[j].B]; //else cons = new StringConstant("unknown" + this.Decoder.File.Function.Instructions[j].B); this.Decoder.File.Function.Upvalues.Add(cons); } } else if (this.Decoder.File.Function.Instructions[j].OpCode == LuaOpcode.SETTABLE) { isGlobal = true; name = this.Decoder.File.Function.Constants[this.Decoder.File.Function.Instructions[j].C].ToString(); name = name.Substring(1, name.Length - 2); break; // job's done } else if (this.Decoder.File.Function.Instructions[j].OpCode == LuaOpcode.SETGLOBAL) { // is global! isGlobal = true; name = this.Decoder.File.Function.Constants[this.Decoder.File.Function.Instructions[j].C].ToString(); name = name.Substring(1, name.Length - 2); break; } j++; } if (globalName != "") { name = globalName + ":" + name; } names.Add(new KeyValuePair <string, bool>(name, isGlobal)); break; } } return(names); }
/// <summary> /// Initializes a new instance of the <see cref="Ldstr"/> class. /// </summary> /// <param name="result">The result.</param> /// <param name="value">The value.</param> public Ldstr(Register result, StringConstant value) : base("Ldstr", result, new Operand [] { value }) { }
public ExportSettingsCommand() { FileUri = new StringConstant(""); }
public ExportKeysCommand() { FileUri = new StringConstant(""); }
public virtual void VisitConstant(Constant c) { if (!c.IsValid) { writer.Write("<invalid>"); return; } var pt = c.DataType.ResolveAs <PrimitiveType>(); if (pt != null) { if (pt.Domain == Domain.Boolean) { writer.Write(Convert.ToBoolean(c.GetValue()) ? "true" : "false"); } else if (pt.Domain == Domain.Real) { string sr; if (pt.Size == 4) { sr = c.ToFloat().ToString("g", CultureInfo.InvariantCulture); } else { sr = c.ToReal64().ToString("g", CultureInfo.InvariantCulture); } if (sr.IndexOfAny(nosuffixRequired) < 0) { sr += ".0"; } if (pt.Size == 4) { sr += "F"; } writer.Write(sr); } else { object v = c.GetValue(); writer.Write(FormatString(pt, v), v); } return; } StringConstant s = c as StringConstant; if (s != null) { writer.Write('"'); foreach (var ch in (string)s.GetValue()) { switch (ch) { case '\0': writer.Write("\\0"); break; case '\a': writer.Write("\\a"); break; case '\b': writer.Write("\\b"); break; case '\f': writer.Write("\\f"); break; case '\n': writer.Write("\\n"); break; case '\r': writer.Write("\\r"); break; case '\t': writer.Write("\\t"); break; case '\v': writer.Write("\\v"); break; case '\"': writer.Write("\\\""); break; case '\\': writer.Write("\\\\"); break; default: // The awful hack allows us to reuse .NET encodings // while encoding the original untranslateable // code points into the Private use area. //$TODO: Clearly if the string was UTF8 or // UTF-16 to begin with, we want to preserve the // private use area points. if (0xE000 <= ch && ch <= 0xE100) { writer.Write("\\x{0:X2}", (ch - 0xE000)); } else if (0 <= ch && ch < ' ' || ch >= 0x7F) { writer.Write("\\x{0:X2}", (int)ch); } else { writer.Write(ch); } break; } } writer.Write('"'); } }
public RegisterUserCommand() { UserId = new StringConstant(""); Password = new StringConstant(""); }
private void CheckGenerateCode(String value, Word[] expectedWords, String message) { StringConstant target = new StringConstant(value); ICodeGeneratorTest.CheckGenerateCode(target, expectedWords, message); }
protected abstract void TranslateCastToList(List <string> output, StringConstant typeValue, Expression enumerableThing);
private void CheckValueToString(String value, String expected, String message) { String actual = StringConstant.ValueToString(value); Assert.AreEqual(expected, actual, message); }
protected abstract void TranslateConvertListToArray(List <string> output, StringConstant type, Expression list);
internal static void Check(StringConstant expected, StringConstant actual, String message) { Assert.AreEqual(expected.Value, actual.Value, "Value: " + message); }
protected abstract void TranslateNewDictionary(List <string> output, StringConstant keyType, StringConstant valueType);
private void CheckIsStart(Char firstChar, Boolean expected, String message) { Boolean actual = StringConstant.IsStart(firstChar); Assert.AreEqual(expected, actual, message); }
protected abstract void TranslateNewListOfSize(List <string> output, StringConstant type, Expression length);
/// <summary> /// Creates a new <c>LikeClause</c> instance /// </summary> /// <param name="left"></param> /// <param name="right"></param> public LikeClause(WherePart left, string right) { _left = left; _right = new StringConstant(right + "%"); }