protected override void WrapCodeImpl(ProjectConfig config, List <string> lines, bool isForStruct) { if (!isForStruct && config.WrappingClassNameForFunctions != null) { PastelUtil.IndentLines(this.TabChar, lines); lines.InsertRange(0, new string[] { "public static class " + config.WrappingClassNameForFunctions, "{" }); lines.Add("}"); } string nsValue = isForStruct ? config.NamespaceForStructs : config.NamespaceForFunctions; if (nsValue != null) { PastelUtil.IndentLines(this.TabChar, lines); lines.InsertRange(0, new string[] { "namespace " + nsValue, "{" }); lines.Add("}"); } if (config.Imports.Count > 0) { lines.InsertRange(0, config.Imports .OrderBy(t => t) .Select(t => "using " + t + ";") .Concat(new string[] { "" })); } }
protected override void WrapCodeImpl(ProjectConfig config, List <string> lines, bool isForStruct) { if (!isForStruct && config.WrappingClassNameForFunctions != null) { PastelUtil.IndentLines(this.TabChar, lines); lines.InsertRange(0, new string[] { "public final class " + config.WrappingClassNameForFunctions + " {", "" }); lines.Add("}"); } List <string> prefixData = new List <string>(); string nsValue = isForStruct ? config.NamespaceForStructs : config.NamespaceForFunctions; if (nsValue != null) { prefixData.AddRange(new string[] { "package " + nsValue + ";", "" }); } if (config.Imports.Count > 0) { prefixData.AddRange( config.Imports .OrderBy(t => t) .Select(t => "import " + t + ";") .Concat(new string[] { "" })); } if (prefixData.Count > 0) { lines.InsertRange(0, prefixData); } }
public string GenerateGlobalDictionaryLookup() { StringBuilder dictionaryBuilder = new StringBuilder(); dictionaryBuilder.Append(this.DictionaryGlobalName); dictionaryBuilder.Append(" = { "); bool isInteger = false; bool first = true; foreach (InlineConstant ic in this.expressionsToChunkIds.Keys) { if (first) { isInteger = ic.ResolvedType.RootValue == "int"; first = false; } else { dictionaryBuilder.Append(", "); } int id = this.expressionsToChunkIds[ic]; if (isInteger) { dictionaryBuilder.Append((int)ic.Value); } else { dictionaryBuilder.Append(PastelUtil.ConvertStringValueToCode((string)ic.Value)); } dictionaryBuilder.Append(": "); dictionaryBuilder.Append(this.expressionsToChunkIds[ic]); } dictionaryBuilder.Append(" }"); return(dictionaryBuilder.ToString()); }
public override void TranslateCharConstant(TranspilerContext sb, char value) { sb.Append(PastelUtil.ConvertCharToCharConstantCode(value)); }
public override void TranslateCharConstant(TranspilerContext sb, char value) { sb.Append(PastelUtil.ConvertStringValueToCode(value.ToString())); }
protected override void WrapCodeImpl(ProjectConfig config, List <string> lines, bool isForStruct) { if (!isForStruct) { PastelUtil.IndentLines(this.TabChar + this.TabChar, lines); List <string> prefixes = config.IncludePublicPastelUtil ? new List <string>() { "// ensures array's pointer behavior behaves according to Pastel standards.", "class PastelPtrArray {", this.TabChar + "var $arr = array();", "}", "class PastelPtr {", this.TabChar + "var $value = null;", this.TabChar + "function __constructor($value) { $this->value = $value; }", "}", "function _pastelWrapValue($value) { $o = new PastelPtrArray(); $o->arr = $value; return $o; }", "// redundant-but-pleasantly-named helper methods for external callers", "function pastelWrapList($arr) { return _pastelWrapValue($arr); }", "function pastelWrapDictionary($arr) { return _pastelWrapValue($arr); }", "", } : new List <string>(); string className = config.WrappingClassNameForFunctions ?? "PastelGeneratedCode"; prefixes.Add("class " + className + " {"); PastelUtil.IndentLines(this.TabChar, prefixes); prefixes.InsertRange(0, new string[] { "<?php", "" }); lines.InsertRange(0, prefixes); bool hasIntBuffer = false; foreach (string line in lines) { if (line.Contains("PST_intBuffer16")) { hasIntBuffer = true; } } lines.Add(this.TabChar + "}"); if (hasIntBuffer) { lines.Add(this.TabChar + "PastelGeneratedCode::$PST_intBuffer16 = pastelWrapList(array_fill(0, 16, 0));"); } foreach (string phpFileInclude in config.PhpFileIncludes) { if (!System.IO.File.Exists(phpFileInclude)) { if (config.PhpFileIncludeIsOptional.Contains(phpFileInclude)) { continue; } throw new InvalidOperationException(phpFileInclude + " does not exist"); } string fileContents = System.IO.File.ReadAllText(phpFileInclude); IList <string> phpLines = GetPhpLinesWithoutWrapper(phpFileInclude, fileContents); lines.Add(""); lines.AddRange(phpLines); } lines.Add(""); lines.Add("?>"); } }
public override void TranslateFloatConstant(TranspilerContext sb, double value) { sb.Append(PastelUtil.FloatToString(value)); }
public override void TranslateStringConstant(TranspilerContext sb, string value) { sb.Append(PastelUtil.ConvertStringValueToCode(value)); }