public static BoogieFunction GenerateMultiDimZeroFunction(VariableDeclaration decl) { TypeName curType = decl.TypeName; List <BoogieType> boogieType = new List <BoogieType>(); while (curType is Mapping || curType is ArrayTypeName) { if (curType is Mapping map) { boogieType.Insert(0, TransUtils.GetBoogieTypeFromSolidityTypeName(map.KeyType)); curType = map.ValueType; } else if (curType is ArrayTypeName arr) { boogieType.Insert(0, BoogieType.Int); curType = arr.BaseType; } } BoogieType valType = TransUtils.GetBoogieTypeFromSolidityTypeName(curType); BoogieExpr boogieInit = TransUtils.GetDefaultVal(valType); string smtType = GetSmtType(valType); string smtInit = boogieInit.ToString().Equals("null") ? "0" : boogieInit.ToString(); BoogieType mapType = valType; string fnName = $"{valType.ToString()}Arr"; foreach (BoogieType type in boogieType) { smtType = $"(Array {GetSmtType(type)} {smtType})"; mapType = new BoogieMapType(type, mapType); smtInit = $"((as const {smtType}) {smtInit})"; fnName = $"{type.ToString()}{fnName}"; } var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", mapType)); var smtDefinedAttr = new BoogieAttribute("smtdefined", $"\"{smtInit}\""); return(new BoogieFunction($"zero{fnName}", new List <BoogieVariable>(), new List <BoogieVariable>() { outVar }, new List <BoogieAttribute>() { smtDefinedAttr })); }
public static BoogieFunction GenerateMultiDimInitFunction(BoogieMapType type) { BoogieType curType = type; List <BoogieType> boogieType = new List <BoogieType>(); while (curType is BoogieMapType map) { if (map.Arguments.Count != 1) { throw new Exception("Boogie map must have one argument"); } boogieType.Insert(0, map.Arguments[0]); curType = map.Result; } BoogieVariable arg = new BoogieFormalParam(new BoogieTypedIdent("n", curType)); string smtInit = "n"; string smtType = GetSmtType(curType); string fnName = $"{curType.ToString()}Arr"; foreach (BoogieType dimType in boogieType) { smtType = $"(Array {GetSmtType(dimType)} {smtType})"; smtInit = $"((as const {smtType}) {smtInit})"; fnName = $"{dimType.ToString()}{fnName}"; } var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", type)); var smtDefinedAttr = new BoogieAttribute("smtdefined", $"\"{smtInit}\""); return(new BoogieFunction($"init{fnName}", new List <BoogieVariable>() { arg }, new List <BoogieVariable>() { outVar }, new List <BoogieAttribute>() { smtDefinedAttr })); }
public static BoogieFunction GenerateMultiDimZeroFunction(BoogieType keyType, BoogieType valType) { BoogieExpr boogieInit = TransUtils.GetDefaultVal(valType); string smtType = GetSmtType(valType); BoogieType mapType = new BoogieMapType(keyType, valType); string fnName = $"zero{keyType.ToString()}{valType.ToString()}Arr"; string smtInit = boogieInit.ToString().Equals("null") ? "0" : boogieInit.ToString(); smtInit = $"((as const (Array {GetSmtType(keyType)} {smtType})) {smtInit})"; var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", mapType)); var smtDefinedAttr = new BoogieAttribute("smtdefined", $"\"{smtInit}\""); return(new BoogieFunction(fnName, new List <BoogieVariable>(), new List <BoogieVariable>() { outVar }, new List <BoogieAttribute>() { smtDefinedAttr })); }
public static string GetCanonicalMemName(BoogieType keyType, BoogieType valType) { return("M_" + keyType.ToString() + "_" + valType.ToString()); }
public static BoogieFuncCallExpr GetCallExprForZeroInit(BoogieType key, BoogieType value) { /*var keyStr = char.ToUpper(key.ToString()[0]) + key.ToString().Substring(1); * var valStr = char.ToUpper(value.ToString()[0]) + value.ToString().Substring(1);*/ return(new BoogieFuncCallExpr("zero" + key.ToString() + value.ToString() + "Arr", new List <BoogieExpr>())); }
// mapping (uint => uint[]) does not have storage/memory in Typestring // private static Regex arrayRegex = new Regex(@"(.+)\[\w*\]$"); public static string GetMemoryMapName(BoogieType keyType, BoogieType valType) { return("M_" + keyType.ToString() + "_" + valType.ToString()); }