protected override void TranslateCast(List<string> output, StringConstant typeValue, Expression expression) { CSharpPlatform platform = (CSharpPlatform)this.Platform; string typeString = platform.GetTypeStringFromAnnotation(typeValue.FirstToken, ((StringConstant)typeValue).Value); output.Add("("); output.Add(typeString); output.Add(")"); this.Translator.TranslateExpression(output, expression); }
protected override void TranslateNewDictionary(List<string> output, StringConstant keyType, StringConstant valueType) { output.Add("{}"); }
protected override void TranslateConvertListToArray(List<string> output, StringConstant type, Expression list) { this.Translator.TranslateExpression(output, list); }
protected override void TranslateCastToList(List<string> output, StringConstant typeValue, Expression enumerableThing) { this.Translator.TranslateExpression(output, enumerableThing); }
protected override void TranslateStringAsChar(List<string> output, StringConstant stringConstant) { output.Add("TODO_string_as_char("); this.Translator.TranslateExpression(output, stringConstant); output.Add(")"); }
protected override void TranslateNewDictionary(List<string> output, StringConstant keyType, StringConstant valueType) { switch (keyType.Value) { case "int": output.Add("TODO_new_int_dictionary()"); break; case "string": output.Add("TODO_new_string_dictionary()"); break; default: throw new NotImplementedException(); } }
protected override void TranslateComment(List<string> output, StringConstant commentValue) { output.Add("// "); output.Add(commentValue.Value); }
protected override void TranslateCast(List<string> output, StringConstant typeValue, Expression expression) { output.Add("(("); output.Add(((COpenGLPlatform)this.Platform).GetTypeStringFromAnnotation(typeValue.FirstToken, typeValue.Value, false, true)); output.Add(") "); this.Translator.TranslateExpression(output, expression); output.Add(")"); }
protected override void TranslateNewListOfSize(List<string> output, StringConstant type, Expression length) { this.TranslateNewPythonList(output, length); }
protected override void TranslateNewArray(List<string> output, StringConstant type, Expression size) { this.TranslateNewPythonList(output, size); }
protected override void TranslateComment(List<string> output, StringConstant commentValue) { #if DEBUG output.Add("# " + commentValue.Value); #endif }
protected override void TranslateNewList(List<string> output, StringConstant type) { output.Add("new ArrayList<"); output.Add(this.JavaPlatform.GetTypeStringFromString(type.Value, true, false)); output.Add(">()"); }
protected override void TranslateNewDictionary(List<string> output, StringConstant keyType, StringConstant valueType) { output.Add("new HashMap<"); output.Add(this.JavaPlatform.GetTypeStringFromString(keyType.Value, true, false)); output.Add(", "); output.Add(this.JavaPlatform.GetTypeStringFromString(valueType.Value, true, false)); output.Add(">()"); }
protected override void TranslateNewArray(List<string> output, StringConstant type, Expression size) { string javaType = this.JavaPlatform.GetTypeStringFromAnnotation(type.FirstToken, type.Value, false, true); List<string> sizeValue = new List<string>(); this.Translator.TranslateExpression(sizeValue, size); CreateNewArrayOfSize(output, javaType, string.Join("", sizeValue)); }
protected override void TranslateNewListOfSize(List<string> output, StringConstant type, Expression length) { output.Add("create_list_of_size("); this.Translator.TranslateExpression(output, length); output.Add(")"); }
protected override void TranslateConvertListToArray(List<string> output, StringConstant type, Expression list) { string typeString = this.JavaPlatform.GetTypeStringFromString(type.Value, false, true); if (typeString == "int") { output.Add("TranslationHelper.createIntArray("); this.Translator.TranslateExpression(output, list); output.Add(")"); } else { this.Translator.TranslateExpression(output, list); output.Add(".toArray("); List<string> sizeValue = new List<string>(); this.Translator.TranslateExpression(sizeValue, list); sizeValue.Add(".size()"); this.CreateNewArrayOfSize(output, typeString, string.Join("", sizeValue)); output.Add(")"); } }
internal override Expression Resolve(Parser parser) { string className = this.NameToken.Value; if (parser.IsTranslateMode) { StructDefinition structDefinition = parser.GetStructDefinition(className); if (structDefinition != null) { if (this.Args.Length != structDefinition.Fields.Length) { throw new ParserException(this.FirstToken, "Args length did not match struct field count for '" + structDefinition.Name.Value + "'."); } StructInstance si = new StructInstance(this.FirstToken, this.NameToken, this.Args, this.FunctionOrClassOwner); si = (StructInstance)si.Resolve(parser); return(si); } } for (int i = 0; i < this.Args.Length; ++i) { this.Args[i] = this.Args[i].Resolve(parser); } if (this.Class == null) { throw new ParserException(this.FirstToken, "No class named '" + this.Name + "'"); } if (this.Class.StaticToken != null) { throw new ParserException(this.FirstToken, "Cannot instantiate a static class."); } ConstructorDefinition cons = this.Class.Constructor; if (cons.PrivateAnnotation != null) { if (this.Class != this.FunctionOrClassOwner.FunctionOrClassOwner) { string errorMessage = "The constructor for " + this.Class.NameToken.Value + " is private and cannot be invoked from outside the class."; if (cons.PrivateAnnotation.Args.Length > 0) { StringConstant stringMessage = cons.PrivateAnnotation.Args[0] as StringConstant; if (stringMessage != null) { errorMessage += " " + stringMessage.Value.Trim(); } } throw new ParserException(this.FirstToken, errorMessage); } } if (this.Args.Length < cons.MinArgCount || this.Args.Length > cons.MaxArgCount) { string message = "This constructor has the wrong number of arguments. "; if (cons.MinArgCount == cons.MaxArgCount) { message += "Expected " + cons.MinArgCount + " but found " + this.Args.Length; } else if (this.Args.Length < cons.MinArgCount) { message += " At least " + cons.MinArgCount + " are required but found only " + this.Args.Length + "."; } else { message += " At most " + cons.MaxArgCount + " are allowed but found " + this.Args.Length + "."; } throw new ParserException(this.FirstToken, message); } return(this); }
protected override void TranslateCastToList(List<string> output, StringConstant typeValue, Expression enumerableThing) { output.Add("TODO_cast_to_list("); this.Translator.TranslateExpression(output, enumerableThing); output.Add(")"); }
protected override void TranslateStringConstant(List<string> output, StringConstant stringConstant) { output.Add("\""); string value = stringConstant.Value; foreach (char c in value) { string nc = "" + c; switch (c) { case '\\': nc = "\\\\"; break; case '"': nc = "\\\""; break; case '\0': nc = "\\0"; break; case '\t': nc = "\\t"; break; case '\n': nc = "\\n"; break; case '\r': nc = "\\r"; break; default: break; } output.Add(nc); } output.Add("\""); }
protected override void TranslateConvertListToArray(List<string> output, StringConstant type, Expression list) { output.Add("TODO_convert_list_to_array("); this.Translator.TranslateExpression(output, list); output.Add(")"); }
internal override Expression Resolve(Parser parser) { for (int i = 0; i < this.Args.Length; ++i) { this.Args[i] = this.Args[i].Resolve(parser); } if (this.Class == null) { throw new ParserException(this.FirstToken, "No class named '" + this.Name + "'"); } if (this.Class.StaticToken != null) { throw new ParserException(this.FirstToken, "Cannot instantiate a static class."); } ConstructorDefinition cons = this.Class.Constructor; if (cons.PrivateAnnotation != null) { bool isValidUsage = this.Class == this.FunctionOrClassOwner || this.Class == this.FunctionOrClassOwner.FunctionOrClassOwner; if (!isValidUsage) { string errorMessage = "The constructor for " + this.Class.NameToken.Value + " is private and cannot be invoked from outside the class."; if (cons.PrivateAnnotation.Args.Length > 0) { StringConstant stringMessage = cons.PrivateAnnotation.Args[0] as StringConstant; if (stringMessage != null) { errorMessage += " " + stringMessage.Value.Trim(); } } throw new ParserException(this.FirstToken, errorMessage); } } if (this.Args.Length < cons.MinArgCount || this.Args.Length > cons.MaxArgCount) { string message = "This constructor has the wrong number of arguments. "; if (cons.MinArgCount == cons.MaxArgCount) { message += "Expected " + cons.MinArgCount + " but found " + this.Args.Length; } else if (this.Args.Length < cons.MinArgCount) { message += " At least " + cons.MinArgCount + " are required but found only " + this.Args.Length + "."; } else { message += " At most " + cons.MaxArgCount + " are allowed but found " + this.Args.Length + "."; } throw new ParserException(this.FirstToken, message); } return(this); }
protected override void TranslateNewListOfSize(List<string> output, StringConstant type, Expression length) { throw new NotImplementedException(); }
protected override void TranslateNewArray(List<string> output, StringConstant type, Expression size) { CSharpPlatform platform = (CSharpPlatform)this.Platform; string csharpType = platform.GetTypeStringFromAnnotation(type.FirstToken, type.Value); output.Add("new "); // Delightful hack... int padding = 0; while (csharpType.EndsWith("[]")) { padding++; csharpType = csharpType.Substring(0, csharpType.Length - 2); } output.Add(csharpType); output.Add("["); this.Translator.TranslateExpression(output, size); output.Add("]"); while (padding-- > 0) { output.Add("[]"); } }
protected override void TranslateCast(List<string> output, StringConstant typeValue, Expression expression) { this.Translator.TranslateExpression(output, expression); }
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 TranslateComment(List<string> output, StringConstant commentValue) { #if DEBUG if (!this.IsMin) { output.Add("// " + commentValue.Value); } #endif }
protected override void TranslateNewList(List<string> output, StringConstant type) { CSharpPlatform platform = (CSharpPlatform)this.Platform; string csharpType = platform.GetTypeStringFromAnnotation(type.FirstToken, ((StringConstant)type).Value); output.Add("new List<"); output.Add(csharpType); output.Add(">()"); }
protected override void TranslateNewArray(List<string> output, StringConstant type, Expression size) { output.Add("create_new_array("); this.Translator.TranslateExpression(output, size); output.Add(")"); }
protected override void TranslateNewListOfSize(List<string> output, StringConstant type, Expression length) { CSharpPlatform platform = (CSharpPlatform)this.Platform; output.Add("TranslationHelper.NewListOfSize<"); output.Add(platform.GetTypeStringFromAnnotation(type.FirstToken, type.Value)); output.Add(">("); this.Translator.TranslateExpression(output, length); output.Add(")"); }
protected override void TranslateNewList(List<string> output, StringConstant type) { output.Add("[]"); }
protected override void TranslateStringAsChar(List<string> output, StringConstant stringConstant) { char c = stringConstant.Value[0]; string value; switch (c) { case '\'': value = "'\\''"; break; case '\\': value = "'\\\\'"; break; case '\n': value = "'\\n'"; break; case '\r': value = "'\\r'"; break; case '\0': value = "'\\0'"; break; case '\t': value = "'\\t'"; break; default: value = "'" + c + "'"; break; } output.Add(value); }
protected override void TranslateStringAsChar(List<string> output, StringConstant stringConstant) { this.Translator.TranslateExpression(output, stringConstant); }
public SwitchStatementUnsafeBlotchy(SwitchStatement switchStatement, bool useExplicitMax, int explicitMax, Executable owner) : base(switchStatement.FirstToken, owner) { this.OriginalSwitchStatement = switchStatement; this.Condition = switchStatement.Condition; this.UsesStrings = switchStatement.UsesStrings; this.UseExplicitMax = useExplicitMax; this.ExplicitMax = explicitMax; if (this.UsesStrings) { this.StringUnsafeToSafeMapping = new Dictionary <string, int>(); } else { this.IntegerUnsafeToSafeMapping = new Dictionary <int, int>(); } this.codeMapping = new Dictionary <int, Executable[]>(); this.tokenMapping = new Dictionary <int, Token>(); this.max = switchStatement.Chunks.Length - 1; for (int i = 0; i < switchStatement.Chunks.Length; ++i) { SwitchStatement.Chunk chunk = switchStatement.Chunks[i]; this.codeMapping[i] = chunk.Code; this.tokenMapping[i] = chunk.CaseOrDefaultToken; foreach (Expression expression in chunk.Cases) { if (expression == null) { this.DefaultCaseId = i; } else { IntegerConstant ic = expression as IntegerConstant; StringConstant sc = expression as StringConstant; if (ic == null && sc == null) { throw new Exception("This shouldn't happen."); } if (ic != null) { int c = ic.Value; this.IntegerUnsafeToSafeMapping[c] = i; } else { string s = sc.Value; this.StringUnsafeToSafeMapping[s] = i; } } } } if (useExplicitMax) { if (this.UsesStrings) { throw new Exception("Cannot use explicit max on string switch statements."); } } }