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 })); }
private BoogieFunction GenerateConstToRefFunction() { //function for Int to Ref var inVar = new BoogieFormalParam(new BoogieTypedIdent("x", BoogieType.Int)); var outVar = new BoogieFormalParam(new BoogieTypedIdent("ret", BoogieType.Ref)); BoogieAttribute attr = new BoogieAttribute("smtdefined", "\"x\""); return(new BoogieFunction( "ConstantToRef", new List <BoogieVariable>() { inVar }, new List <BoogieVariable>() { outVar }, new List <BoogieAttribute>() { attr })); }