Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8add8d1

Browse files
authored
Refactor converter.cs & methodbind*.cs (#375)
1 parentce40fb1 commit8add8d1

File tree

3 files changed

+97
-117
lines changed

3 files changed

+97
-117
lines changed

‎src/runtime/converter.cs

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -52,62 +52,53 @@ static Converter()
5252
/// </summary>
5353
internalstaticTypeGetTypeByAlias(IntPtrop)
5454
{
55-
if(op==Runtime.PyStringType||
56-
op==Runtime.PyUnicodeType)
57-
{
55+
if(op==Runtime.PyStringType)
5856
returnstringType;
59-
}
60-
elseif(op==Runtime.PyIntType)
61-
{
57+
58+
if(op==Runtime.PyUnicodeType)
59+
returnstringType;
60+
61+
if(op==Runtime.PyIntType)
6262
returnint32Type;
63-
}
64-
elseif(op==Runtime.PyLongType)
65-
{
63+
64+
if(op==Runtime.PyLongType)
6665
returnint64Type;
67-
}
68-
elseif(op==Runtime.PyFloatType)
69-
{
66+
67+
if(op==Runtime.PyFloatType)
7068
returndoubleType;
71-
}
72-
elseif(op==Runtime.PyBoolType)
73-
{
69+
70+
if(op==Runtime.PyBoolType)
7471
returnboolType;
75-
}
72+
7673
returnnull;
7774
}
7875

7976
internalstaticIntPtrGetPythonTypeByAlias(Typeop)
8077
{
8178
if(op==stringType)
82-
{
8379
returnRuntime.PyUnicodeType;
84-
}
8580

86-
elseif(Runtime.IsPython3&&(op==int16Type||
87-
op==int32Type||
88-
op==int64Type))
89-
{
81+
if(op==int16Type)
9082
returnRuntime.PyIntType;
91-
}
9283

93-
elseif(op==int16Type||
94-
op==int32Type)
95-
{
84+
if(op==int32Type)
9685
returnRuntime.PyIntType;
97-
}
98-
elseif(op==int64Type)
99-
{
86+
87+
if(op==int64Type&&Runtime.IsPython2)
10088
returnRuntime.PyLongType;
101-
}
102-
elseif(op==doubleType||
103-
op==singleType)
104-
{
89+
90+
if(op==int64Type)
91+
returnRuntime.PyIntType;
92+
93+
if(op==doubleType)
10594
returnRuntime.PyFloatType;
106-
}
107-
elseif(op==boolType)
108-
{
95+
96+
if(op==singleType)
97+
returnRuntime.PyFloatType;
98+
99+
if(op==boolType)
109100
returnRuntime.PyBoolType;
110-
}
101+
111102
returnIntPtr.Zero;
112103
}
113104

@@ -329,27 +320,27 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
329320
returnToPrimitive(value,stringType,outresult,setError);
330321
}
331322

332-
elseif(Runtime.PyBool_Check(value))
323+
if(Runtime.PyBool_Check(value))
333324
{
334325
returnToPrimitive(value,boolType,outresult,setError);
335326
}
336327

337-
elseif(Runtime.PyInt_Check(value))
328+
if(Runtime.PyInt_Check(value))
338329
{
339330
returnToPrimitive(value,int32Type,outresult,setError);
340331
}
341332

342-
elseif(Runtime.PyLong_Check(value))
333+
if(Runtime.PyLong_Check(value))
343334
{
344335
returnToPrimitive(value,int64Type,outresult,setError);
345336
}
346337

347-
elseif(Runtime.PyFloat_Check(value))
338+
if(Runtime.PyFloat_Check(value))
348339
{
349340
returnToPrimitive(value,doubleType,outresult,setError);
350341
}
351342

352-
elseif(Runtime.PySequence_Check(value))
343+
if(Runtime.PySequence_Check(value))
353344
{
354345
returnToArray(value,typeof(object[]),outresult,setError);
355346
}
@@ -371,31 +362,31 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
371362
returntrue;
372363
}
373364

374-
elseif(value==Runtime.PyBoolType)
365+
if(value==Runtime.PyBoolType)
375366
{
376367
result=boolType;
377368
returntrue;
378369
}
379370

380-
elseif(value==Runtime.PyIntType)
371+
if(value==Runtime.PyIntType)
381372
{
382373
result=int32Type;
383374
returntrue;
384375
}
385376

386-
elseif(value==Runtime.PyLongType)
377+
if(value==Runtime.PyLongType)
387378
{
388379
result=int64Type;
389380
returntrue;
390381
}
391382

392-
elseif(value==Runtime.PyFloatType)
383+
if(value==Runtime.PyFloatType)
393384
{
394385
result=doubleType;
395386
returntrue;
396387
}
397388

398-
elseif(value==Runtime.PyListType||value==Runtime.PyTupleType)
389+
if(value==Runtime.PyListType||value==Runtime.PyTupleType)
399390
{
400391
result=typeof(object[]);
401392
returntrue;

‎src/runtime/methodbinder.cs

Lines changed: 45 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ internal MethodBase[] GetMethods()
170170
/// Precedence algorithm largely lifted from jython - the concerns are
171171
/// generally the same so we'll start w/this and tweak as necessary.
172172
/// </summary>
173+
/// <remarks>
174+
/// TODO: Add link to specific Jython Section/Code/File
175+
/// </remarks>
173176
internalstaticintGetPrecedence(MethodBasemi)
174177
{
175178
ParameterInfo[]pi=mi.GetParameters();
@@ -198,61 +201,49 @@ internal static int ArgPrecedence(Type t)
198201

199202
TypeCodetc=Type.GetTypeCode(t);
200203
// TODO: Clean up
201-
if(tc==TypeCode.Object)
204+
switch(tc)
202205
{
203-
return1;
204-
}
205-
if(tc==TypeCode.UInt64)
206-
{
207-
return10;
208-
}
209-
if(tc==TypeCode.UInt32)
210-
{
211-
return11;
212-
}
213-
if(tc==TypeCode.UInt16)
214-
{
215-
return12;
216-
}
217-
if(tc==TypeCode.Int64)
218-
{
219-
return13;
220-
}
221-
if(tc==TypeCode.Int32)
222-
{
223-
return14;
224-
}
225-
if(tc==TypeCode.Int16)
226-
{
227-
return15;
228-
}
229-
if(tc==TypeCode.Char)
230-
{
231-
return16;
232-
}
233-
if(tc==TypeCode.SByte)
234-
{
235-
return17;
236-
}
237-
if(tc==TypeCode.Byte)
238-
{
239-
return18;
240-
}
241-
if(tc==TypeCode.Single)
242-
{
243-
return20;
244-
}
245-
if(tc==TypeCode.Double)
246-
{
247-
return21;
248-
}
249-
if(tc==TypeCode.String)
250-
{
251-
return30;
252-
}
253-
if(tc==TypeCode.Boolean)
254-
{
255-
return40;
206+
caseTypeCode.Object:
207+
return1;
208+
209+
caseTypeCode.UInt64:
210+
return10;
211+
212+
caseTypeCode.UInt32:
213+
return11;
214+
215+
caseTypeCode.UInt16:
216+
return12;
217+
218+
caseTypeCode.Int64:
219+
return13;
220+
221+
caseTypeCode.Int32:
222+
return14;
223+
224+
caseTypeCode.Int16:
225+
return15;
226+
227+
caseTypeCode.Char:
228+
return16;
229+
230+
caseTypeCode.SByte:
231+
return17;
232+
233+
caseTypeCode.Byte:
234+
return18;
235+
236+
caseTypeCode.Single:
237+
return20;
238+
239+
caseTypeCode.Double:
240+
return21;
241+
242+
caseTypeCode.String:
243+
return30;
244+
245+
caseTypeCode.Boolean:
246+
return40;
256247
}
257248

258249
if(t.IsArray)

‎src/runtime/methodbinding.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ public static IntPtr mp_subscript(IntPtr tp, IntPtr idx)
5555
returnExceptions.RaiseTypeError("No match found for given type params");
5656
}
5757

58-
varmb=newMethodBinding(self.m,self.target);
59-
mb.info=mi;
58+
varmb=newMethodBinding(self.m,self.target){info=mi};
6059
Runtime.XIncref(mb.pyHandle);
6160
returnmb.pyHandle;
6261
}
@@ -76,22 +75,21 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
7675
}
7776

7877
stringname=Runtime.GetManagedString(key);
79-
if(name=="__doc__")
78+
switch(name)
8079
{
81-
IntPtrdoc=self.m.GetDocString();
82-
Runtime.XIncref(doc);
83-
returndoc;
80+
case"__doc__":
81+
IntPtrdoc=self.m.GetDocString();
82+
Runtime.XIncref(doc);
83+
returndoc;
84+
// FIXME: deprecate __overloads__ soon...
85+
case"__overloads__":
86+
case"Overloads":
87+
varom=newOverloadMapper(self.m,self.target);
88+
Runtime.XIncref(om.pyHandle);
89+
returnom.pyHandle;
90+
default:
91+
returnRuntime.PyObject_GenericGetAttr(ob,key);
8492
}
85-
86-
// FIXME: deprecate __overloads__ soon...
87-
if(name=="__overloads__"||name=="Overloads")
88-
{
89-
varom=newOverloadMapper(self.m,self.target);
90-
Runtime.XIncref(om.pyHandle);
91-
returnom.pyHandle;
92-
}
93-
94-
returnRuntime.PyObject_GenericGetAttr(ob,key);
9593
}
9694

9795

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp