Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadOnly methods #93

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ce2ee1f
ReadOnly ABI
shargon Aug 23, 2019
aba233c
Rename ut
shargon Aug 23, 2019
8d2df69
Rename Contract class
shargon Aug 23, 2019
3e3c42c
Reduce ut
shargon Aug 23, 2019
28b2fce
Fix ut
shargon Aug 23, 2019
506122e
Unify process attribute
shargon Aug 23, 2019
cb10ef3
Centralize logic
shargon Aug 23, 2019
e2866af
Centralize neoEvent
shargon Aug 23, 2019
057f94c
Reorder code
shargon Aug 23, 2019
73fd565
dotnet format
shargon Aug 26, 2019
e50ba05
Fix format
shargon Aug 26, 2019
712f7a7
Reorder properties to top
shargon Aug 27, 2019
2ffc65a
Fix ABI
shargon Aug 27, 2019
3943611
Prepare TODO
shargon Aug 27, 2019
6e8161b
ReadOnly ABI
shargon Aug 23, 2019
0af4293
Rename ut
shargon Aug 23, 2019
7ae8d71
Rename Contract class
shargon Aug 23, 2019
9abf378
Reduce ut
shargon Aug 23, 2019
cf7e37c
Fix ut
shargon Aug 23, 2019
d957ad9
Unify process attribute
shargon Aug 23, 2019
0c15b8a
Centralize logic
shargon Aug 23, 2019
77d9a0e
Centralize neoEvent
shargon Aug 23, 2019
65e8461
Reorder code
shargon Aug 23, 2019
ec7751c
dotnet format
shargon Aug 26, 2019
ca3a6bf
Fix format
shargon Aug 26, 2019
4a38f65
Reorder properties to top
shargon Aug 27, 2019
716c2ac
Fix ABI
shargon Aug 27, 2019
236a26f
Prepare TODO
shargon Aug 27, 2019
75d7566
Fix
shargon Aug 28, 2019
c709cf4
Merge remote-tracking branch 'origin/readonly-abi' into readonly-abi
shargon Aug 28, 2019
a5e1585
Merge branch 'master' into readonly-abi
shargon Sep 9, 2019
aeefc1a
Change ABI
shargon Sep 9, 2019
690c101
Merge remote-tracking branch 'origin/readonly-abi' into readonly-abi
shargon Sep 9, 2019
f8103a8
Merge branch 'master' into readonly-abi
shargon Sep 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/Neo.Compiler.MSIL/FuncExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,35 @@ public static MyJson.JsonNode_Object Export(NeoModule module, byte[] script)
outjson.SetDictValue("hash", sb.ToString());

//entrypoint
outjson.SetDictValue("entrypoint", "Main");
var entryPoint = "Main";
var mainmethod = module.mapMethods[module.mainMethod];
if (mainmethod != null)
{
var name = mainmethod.displayName;
outjson.SetDictValue("entrypoint", name);
entryPoint = mainmethod.displayName;
}

//functions
var funcsigns = new MyJson.JsonNode_Array();
outjson["functions"] = funcsigns;
var methods = new MyJson.JsonNode_Array();
outjson["methods"] = methods;

List<string> names = new List<string>();

foreach (var function in module.mapMethods)
{
var mm = function.Value;
if (mm.inSmartContract == false)
continue;
if (mm.isPublic == false)
continue;
var ps = mm.name.Split(new char[] { ' ', '(' }, StringSplitOptions.RemoveEmptyEntries);
var funcsign = new MyJson.JsonNode_Object();

funcsigns.Add(funcsign);
var funcname = ps[1];
if (funcname.IndexOf("::") > 0)
var funcsign = new MyJson.JsonNode_Object();
if (function.Value.displayName == entryPoint)
{
var sps = funcname.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries);
funcname = sps.Last();
// This is the entryPoint
outjson.SetDictValue("entryPoint", funcsign);
}
else
{
methods.Add(funcsign);
}
funcsign.SetDictValue("name", function.Value.displayName);
if (names.Contains(function.Value.displayName))
Expand All @@ -133,7 +133,8 @@ public static MyJson.JsonNode_Object Export(NeoModule module, byte[] script)
}

var rtype = ConvType(mm.returntype);
funcsign.SetDictValue("returntype", rtype);
funcsign.SetDictValue("returnType", rtype);
funcsign.SetDictValue("readOnly", function.Value.isReadOnly);
}

//events
Expand All @@ -142,10 +143,7 @@ public static MyJson.JsonNode_Object Export(NeoModule module, byte[] script)
foreach (var events in module.mapEvents)
{
var mm = events.Value;

var ps = mm.name.Split(new char[] { ' ', '(' }, StringSplitOptions.RemoveEmptyEntries);
var funcsign = new MyJson.JsonNode_Object();

eventsigns.Add(funcsign);

funcsign.SetDictValue("name", events.Value.displayName);
Expand Down
17 changes: 2 additions & 15 deletions src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,6 @@ private bool TryInsertMethod(NeoModule outModule, Mono.Cecil.MethodDefinition me
var _method = type.methods[method.FullName];
try
{
NeoMethod nm = new NeoMethod();
if (method.FullName.Contains(".cctor"))
{
CctorSubVM.Parse(_method, this.outModule);
Expand All @@ -996,22 +995,10 @@ private bool TryInsertMethod(NeoModule outModule, Mono.Cecil.MethodDefinition me
return false;
//continue;
}
nm._namespace = method.DeclaringType.FullName;
nm.name = method.FullName;
nm.displayName = method.Name;
Mono.Collections.Generic.Collection<Mono.Cecil.CustomAttribute> ca = method.CustomAttributes;
foreach (var attr in ca)
{
if (attr.AttributeType.Name == "DisplayNameAttribute")
{
nm.displayName = (string)attr.ConstructorArguments[0].Value;
}
}
nm.inSmartContract = method.DeclaringType.BaseType.Name == "SmartContract";
nm.isPublic = method.IsPublic;

NeoMethod nm = new NeoMethod(method);
this.methodLink[_method] = nm;
outModule.mapMethods[nm.name] = nm;

ConvertMethod(_method, nm);
return true;
}
Expand Down
24 changes: 2 additions & 22 deletions src/Neo.Compiler.MSIL/MSIL/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,14 @@ public NeoModule Convert(ILModule _in, ConvOption option = null)
if (m.Value.method == null) continue;
if (m.Value.method.IsAddOn || m.Value.method.IsRemoveOn)
continue;//event 自动生成的代码,不要
NeoMethod nm = new NeoMethod();
if (m.Key.Contains(".cctor"))
{
CctorSubVM.Parse(m.Value, this.outModule);
continue;
}
if (m.Value.method.IsConstructor) continue;
nm._namespace = m.Value.method.DeclaringType.FullName;
nm.name = m.Value.method.FullName;
nm.displayName = m.Value.method.Name;

Mono.Collections.Generic.Collection<Mono.Cecil.CustomAttribute> ca = m.Value.method.CustomAttributes;
foreach (var attr in ca)
{
if (attr.AttributeType.Name == "DisplayNameAttribute")
{
nm.displayName = (string)attr.ConstructorArguments[0].Value;
}
}
nm.inSmartContract = m.Value.method.DeclaringType.BaseType.Name == "SmartContract";
nm.isPublic = m.Value.method.IsPublic;
NeoMethod nm = new NeoMethod(m.Value.method);
this.methodLink[m.Value] = nm;
outModule.mapMethods[nm.name] = nm;
}
Expand All @@ -114,14 +101,7 @@ public NeoModule Convert(ILModule _in, ConvOption option = null)
{
if (e.Value.isEvent)
{
NeoEvent ae = new NeoEvent
{
_namespace = e.Value.field.DeclaringType.FullName,
name = e.Value.field.DeclaringType.FullName + "::" + e.Key,
displayName = e.Value.displayName,
returntype = e.Value.returntype,
paramtypes = e.Value.paramtypes
};
NeoEvent ae = new NeoEvent(e.Value);
outModule.mapEvents[ae.name] = ae;
}
else if (e.Value.field.IsStatic)
Expand Down
2 changes: 0 additions & 2 deletions src/Neo.Compiler.MSIL/MSIL/ILModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void LoadModule(System.IO.Stream dllStream, System.IO.Stream pdbStream)

}
}

}
}
}
Expand Down Expand Up @@ -91,7 +90,6 @@ public ILType(ILModule module, Mono.Cecil.TypeDefinition type, ILogger logger)
}
}
}

}

public class ILField
Expand Down
111 changes: 68 additions & 43 deletions src/Neo.Compiler.MSIL/NeoModule.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
using Mono.Cecil;
using Neo.Compiler.MSIL;
using System.Collections.Generic;
using System.Text;

namespace Neo.Compiler
{
public class NeoModule
{
public NeoModule(ILogger logger)
{
}
public NeoModule(ILogger logger) { }

public string mainMethod;
public ConvOption option;
public Dictionary<string, NeoMethod> mapMethods = new Dictionary<string, NeoMethod>();
public Dictionary<string, NeoEvent> mapEvents = new Dictionary<string, NeoEvent>();
public Dictionary<string, NeoField> mapFields = new Dictionary<string, NeoField>();
public Dictionary<string, object> staticfields = new Dictionary<string, object>();
//小蚁没类型,只有方法
public SortedDictionary<int, NeoCode> total_Codes = new SortedDictionary<int, NeoCode>();

public byte[] Build()
{
List<byte> bytes = new List<byte>();
Expand All @@ -26,13 +33,7 @@ public byte[] Build()
return bytes.ToArray();
//将body链接,生成this.code byte[]
//并计算 this.codehash byte[]
}
public string mainMethod;
public ConvOption option;
public Dictionary<string, NeoMethod> mapMethods = new Dictionary<string, NeoMethod>();
public Dictionary<string, NeoEvent> mapEvents = new Dictionary<string, NeoEvent>();
public Dictionary<string, NeoField> mapFields = new Dictionary<string, NeoField>();
//public Dictionary<string, byte[]> codes = new Dictionary<string, byte[]>();
shargon marked this conversation as resolved.
Show resolved Hide resolved
} //public Dictionary<string, byte[]> codes = new Dictionary<string, byte[]>();
//public byte[] GetScript(byte[] script_hash)
//{
// string strhash = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to leave this here? Shouldn't we clean this up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I leave it because maybe @lightszero require it in the future, but a general clean will come later, i need to order this classes xD

Expand Down Expand Up @@ -71,28 +72,27 @@ public string GenJson()
methodinfo[m.Key] = m.Value.GenJson();
}


StringBuilder sb = new StringBuilder();
json.ConvertToStringWithFormat(sb, 4);
return sb.ToString();
}
public void FromJson(string json)
{

}

public Dictionary<string, object> staticfields = new Dictionary<string, object>();
}

public class NeoMethod
{
public string lastsfieldname = null;//最后一个加载的静态成员的名字,仅event使用

public int lastparam = -1;//最后一个加载的参数对应
public int lastCast = -1;

public bool isEntry = false;
public string _namespace;
public string name;
public string displayName;
public List<NeoParam> paramtypes = new List<NeoParam>();
public string returntype;
public bool isPublic = true;
public bool isReadOnly = false;
public bool inSmartContract;
//临时变量
public List<NeoParam> body_Variables = new List<NeoParam>();
Expand All @@ -118,10 +118,6 @@ public MyJson.JsonNode_Object GenJson()
return json;
}

public void FromJson(MyJson.JsonNode_Object json)
{
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This methods are not used

//public byte[] Build()
//{
// List<byte> bytes = new List<byte>();
Expand All @@ -138,10 +134,46 @@ public void FromJson(MyJson.JsonNode_Object json)
// //将body链接,生成this.code byte[]
// //并计算 this.codehash byte[]
//}
public string lastsfieldname = null;//最后一个加载的静态成员的名字,仅event使用

public int lastparam = -1;//最后一个加载的参数对应
public int lastCast = -1;
/// <summary>
/// Constructor
/// </summary>
public NeoMethod() { }

/// <summary>
/// Constructor
/// </summary>
/// <param name="method">Method</param>
public NeoMethod(MethodDefinition method)
{
_namespace = method.DeclaringType.FullName;
name = method.FullName;
displayName = method.Name;
inSmartContract = method.DeclaringType.BaseType.Name == "SmartContract";
isPublic = method.IsPublic;

foreach (var attr in method.CustomAttributes)
{
ProcessAttribute(attr);
}
}

private void ProcessAttribute(CustomAttribute attr)
{
switch (attr.AttributeType.Name)
{
case "DisplayNameAttribute":
{
displayName = (string)attr.ConstructorArguments[0].Value;
break;
}
case "ReadOnlyAttribute":
{
isReadOnly = (bool)attr.ConstructorArguments[0].Value;
break;
}
}
}
}
public class NeoEvent
{
Expand All @@ -150,6 +182,15 @@ public class NeoEvent
public string displayName;
public List<NeoParam> paramtypes = new List<NeoParam>();
public string returntype;

public NeoEvent(ILField value)
{
_namespace = value.field.DeclaringType.FullName;
name = value.field.DeclaringType.FullName + "::" + value.field.Name;
displayName = value.displayName;
returntype = value.returntype;
paramtypes = value.paramtypes;
}
}

public class NeoCode
Expand Down Expand Up @@ -224,41 +265,25 @@ public MyJson.JsonNode_ValueString GenJson()
}
return new MyJson.JsonNode_ValueString(info);
}

public void FromJson(MyJson.JsonNode_Object json)
{
}
shargon marked this conversation as resolved.
Show resolved Hide resolved
}
public class NeoField : NeoParam
{
public int index { get; private set; }
public NeoField(string name, string type, int index) : base(name, type)
{
this.index = index;
}
public int index
{
get;
private set;
}
}

public class NeoParam
{
public string name { get; private set; }
public string type { get; private set; }
public NeoParam(string name, string type)
{
this.name = name;
this.type = type;
}
public string name
{
get;
private set;
}
public string type
{
get;
private set;
}
public override string ToString()
{
return type + " " + name;
Expand Down
Loading