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

Commitd8cf55a

Browse files
committed
Clean-up code-style
Remove redundant parenthesis, enforce brackets, use keywork types.
1 parent61536f3 commitd8cf55a

File tree

6 files changed

+91
-56
lines changed

6 files changed

+91
-56
lines changed

‎src/runtime/classobject.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ internal ClassObject(Type tp) : base(tp)
3232
internalIntPtrGetDocString()
3333
{
3434
MethodBase[]methods=binder.GetMethods();
35-
stringstr="";
35+
varstr="";
3636
foreach(MethodBasetinmethods)
3737
{
3838
if(str.Length>0)
39+
{
3940
str+=Environment.NewLine;
41+
}
4042
str+=t.ToString();
4143
}
4244
returnRuntime.PyString_FromString(str);
@@ -48,7 +50,7 @@ internal IntPtr GetDocString()
4850
/// </summary>
4951
publicstaticIntPtrtp_new(IntPtrtp,IntPtrargs,IntPtrkw)
5052
{
51-
ClassObjectself=GetManagedObject(tp)asClassObject;
53+
varself=GetManagedObject(tp)asClassObject;
5254

5355
// Sanity check: this ensures a graceful error if someone does
5456
// something intentially wrong like use the managed metatype for
@@ -72,7 +74,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
7274
}
7375

7476
IntPtrop=Runtime.PyTuple_GetItem(args,0);
75-
Objectresult;
77+
objectresult;
7678

7779
if(!Converter.ToManaged(op,type,outresult,true))
7880
{
@@ -94,7 +96,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
9496
returnIntPtr.Zero;
9597
}
9698

97-
Objectobj=self.binder.InvokeRaw(IntPtr.Zero,args,kw);
99+
objectobj=self.binder.InvokeRaw(IntPtr.Zero,args,kw);
98100
if(obj==null)
99101
{
100102
returnIntPtr.Zero;
@@ -119,8 +121,8 @@ public override IntPtr type_subscript(IntPtr idx)
119121
{
120122
returnExceptions.RaiseTypeError("type expected");
121123
}
122-
ClassBasec=GetManagedObject(idx)asClassBase;
123-
Typet=(c!=null)?c.type:Converter.GetTypeByAlias(idx);
124+
varc=GetManagedObject(idx)asClassBase;
125+
Typet=c!=null?c.type:Converter.GetTypeByAlias(idx);
124126
if(t==null)
125127
{
126128
returnExceptions.RaiseTypeError("type expected");
@@ -159,7 +161,7 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx)
159161
{
160162
//ManagedType self = GetManagedObject(ob);
161163
IntPtrtp=Runtime.PyObject_TYPE(ob);
162-
ClassBasecls=(ClassBase)GetManagedObject(tp);
164+
varcls=(ClassBase)GetManagedObject(tp);
163165

164166
if(cls.indexer==null||!cls.indexer.CanGet)
165167
{
@@ -171,7 +173,7 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx)
171173
// parameters. If so, use it directly, else make a new tuple
172174
// with the index arg (method binders expect arg tuples).
173175
IntPtrargs=idx;
174-
boolfree=false;
176+
varfree=false;
175177

176178
if(!Runtime.PyTuple_Check(idx))
177179
{
@@ -205,7 +207,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
205207
{
206208
//ManagedType self = GetManagedObject(ob);
207209
IntPtrtp=Runtime.PyObject_TYPE(ob);
208-
ClassBasecls=(ClassBase)GetManagedObject(tp);
210+
varcls=(ClassBase)GetManagedObject(tp);
209211

210212
if(cls.indexer==null||!cls.indexer.CanSet)
211213
{
@@ -217,7 +219,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
217219
// parameters. If so, use it directly, else make a new tuple
218220
// with the index arg (method binders expect arg tuples).
219221
IntPtrargs=idx;
220-
boolfree=false;
222+
varfree=false;
221223

222224
if(!Runtime.PyTuple_Check(idx))
223225
{
@@ -233,15 +235,15 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
233235
intnumOfDefaultArgs=Runtime.PyTuple_Size(defaultArgs);
234236
inttemp=i+numOfDefaultArgs;
235237
IntPtrreal=Runtime.PyTuple_New(temp+1);
236-
for(intn=0;n<i;n++)
238+
for(varn=0;n<i;n++)
237239
{
238240
IntPtritem=Runtime.PyTuple_GetItem(args,n);
239241
Runtime.XIncref(item);
240242
Runtime.PyTuple_SetItem(real,n,item);
241243
}
242244

243245
// Add Default Args if needed
244-
for(intn=0;n<numOfDefaultArgs;n++)
246+
for(varn=0;n<numOfDefaultArgs;n++)
245247
{
246248
IntPtritem=Runtime.PyTuple_GetItem(defaultArgs,n);
247249
Runtime.XIncref(item);
@@ -288,23 +290,23 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
288290
{
289291
//ManagedType self = GetManagedObject(ob);
290292
IntPtrtp=Runtime.PyObject_TYPE(ob);
291-
ClassBasecb=(ClassBase)GetManagedObject(tp);
293+
varcb=(ClassBase)GetManagedObject(tp);
292294

293295
if(cb.type!=typeof(Delegate))
294296
{
295297
Exceptions.SetError(Exceptions.TypeError,"object is not callable");
296298
returnIntPtr.Zero;
297299
}
298300

299-
CLRObjectco=(CLRObject)ManagedType.GetManagedObject(ob);
300-
Delegated=co.instasDelegate;
301+
varco=(CLRObject)GetManagedObject(ob);
302+
vard=co.instasDelegate;
301303
BindingFlagsflags=BindingFlags.Public|
302304
BindingFlags.NonPublic|
303305
BindingFlags.Instance|
304306
BindingFlags.Static;
305307

306308
MethodInfomethod=d.GetType().GetMethod("Invoke",flags);
307-
MethodBinderbinder=newMethodBinder(method);
309+
varbinder=newMethodBinder(method);
308310
returnbinder.Invoke(ob,args,kw);
309311
}
310312
}

‎src/runtime/converter.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ static Converter()
5252
/// </summary>
5353
internalstaticTypeGetTypeByAlias(IntPtrop)
5454
{
55-
if((op==Runtime.PyStringType)||
56-
(op==Runtime.PyUnicodeType))
55+
if(op==Runtime.PyStringType||
56+
op==Runtime.PyUnicodeType)
5757
{
5858
returnstringType;
5959
}
@@ -83,24 +83,24 @@ internal static IntPtr GetPythonTypeByAlias(Type op)
8383
returnRuntime.PyUnicodeType;
8484
}
8585

86-
elseif(Runtime.IsPython3&&((op==int16Type)||
87-
(op==int32Type)||
88-
(op==int64Type)))
86+
elseif(Runtime.IsPython3&&(op==int16Type||
87+
op==int32Type||
88+
op==int64Type))
8989
{
9090
returnRuntime.PyIntType;
9191
}
9292

93-
elseif((op==int16Type)||
94-
(op==int32Type))
93+
elseif(op==int16Type||
94+
op==int32Type)
9595
{
9696
returnRuntime.PyIntType;
9797
}
9898
elseif(op==int64Type)
9999
{
100100
returnRuntime.PyLongType;
101101
}
102-
elseif((op==doubleType)||
103-
(op==singleType))
102+
elseif(op==doubleType||
103+
op==singleType)
104104
{
105105
returnRuntime.PyFloatType;
106106
}
@@ -123,7 +123,7 @@ internal static IntPtr ToPython<T>(T value)
123123
returnToPython(value,typeof(T));
124124
}
125125

126-
internalstaticIntPtrToPython(Objectvalue,Typetype)
126+
internalstaticIntPtrToPython(objectvalue,Typetype)
127127
{
128128
if(valueisPyObject)
129129
{
@@ -144,7 +144,7 @@ internal static IntPtr ToPython(Object value, Type type)
144144

145145
// it the type is a python subclass of a managed type then return the
146146
// underlying python object rather than construct a new wrapper object.
147-
IPythonDerivedTypepyderived=valueasIPythonDerivedType;
147+
varpyderived=valueasIPythonDerivedType;
148148
if(null!=pyderived)
149149
{
150150
returnClassDerivedObject.ToPython(pyderived);
@@ -221,7 +221,9 @@ internal static IntPtr ToPython(Object value, Type type)
221221
foreach(objectoin(IEnumerable)value)
222222
{
223223
using(varp=newPyObject(ToPython(o,o?.GetType())))
224+
{
224225
resultlist.Append(p);
226+
}
225227
}
226228
Runtime.XIncref(resultlist.Handle);
227229
returnresultlist.Handle;
@@ -237,7 +239,7 @@ internal static IntPtr ToPython(Object value, Type type)
237239
/// In a few situations, we don't have any advisory type information
238240
/// when we want to convert an object to Python.
239241
/// </summary>
240-
internalstaticIntPtrToPythonImplicit(Objectvalue)
242+
internalstaticIntPtrToPythonImplicit(objectvalue)
241243
{
242244
if(value==null)
243245
{
@@ -266,7 +268,7 @@ internal static bool ToManaged(IntPtr value, Type type,
266268

267269

268270
internalstaticboolToManagedValue(IntPtrvalue,TypeobType,
269-
outObjectresult,boolsetError)
271+
outobjectresult,boolsetError)
270272
{
271273
if(obType==typeof(PyObject))
272274
{
@@ -290,8 +292,8 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
290292
result=tmp;
291293
returntrue;
292294
}
293-
stringerr="value cannot be converted to {0}";
294-
err=String.Format(err,obType);
295+
varerr="value cannot be converted to {0}";
296+
err=string.Format(err,obType);
295297
Exceptions.SetError(Exceptions.TypeError,err);
296298
returnfalse;
297299
}
@@ -474,7 +476,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
474476
}
475477
longll=(long)Runtime.PyLong_AsLongLong(op);
476478
Runtime.XDecref(op);
477-
if((ll==-1)&&Exceptions.ErrorOccurred())
479+
if(ll==-1&&Exceptions.ErrorOccurred())
478480
{
479481
gotooverflow;
480482
}
@@ -487,7 +489,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
487489
}
488490

489491
caseTypeCode.Boolean:
490-
result=(Runtime.PyObject_IsTrue(value)!=0);
492+
result=Runtime.PyObject_IsTrue(value)!=0;
491493
returntrue;
492494

493495
caseTypeCode.Byte:
@@ -791,9 +793,9 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
791793

792794
if(setError)
793795
{
794-
stringformat="'{0}' value cannot be converted to {1}";
796+
varformat="'{0}' value cannot be converted to {1}";
795797
stringtpName=Runtime.PyObject_GetTypeName(value);
796-
stringerror=String.Format(format,tpName,obType);
798+
stringerror=string.Format(format,tpName,obType);
797799
Exceptions.SetError(Exceptions.TypeError,error);
798800
}
799801

@@ -803,20 +805,20 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
803805

804806
if(setError)
805807
{
806-
stringerror="value too large to convert";
808+
varerror="value too large to convert";
807809
Exceptions.SetError(Exceptions.OverflowError,error);
808810
}
809811

810812
returnfalse;
811813
}
812814

813815

814-
staticvoidSetConversionError(IntPtrvalue,Typetarget)
816+
privatestaticvoidSetConversionError(IntPtrvalue,Typetarget)
815817
{
816818
IntPtrob=Runtime.PyObject_Repr(value);
817819
stringsrc=Runtime.GetManagedString(ob);
818820
Runtime.XDecref(ob);
819-
stringerror=String.Format("Cannot convert {0} to {1}",src,target);
821+
stringerror=string.Format("Cannot convert {0} to {1}",src,target);
820822
Exceptions.SetError(Exceptions.TypeError,error);
821823
}
822824

@@ -844,9 +846,9 @@ private static bool ToArray(IntPtr value, Type obType, out object result, bool s
844846
Arrayitems=Array.CreateInstance(elementType,size);
845847

846848
// XXX - is there a better way to unwrap this if it is a real array?
847-
for(inti=0;i<size;i++)
849+
for(vari=0;i<size;i++)
848850
{
849-
Objectobj=null;
851+
objectobj=null;
850852
IntPtritem=Runtime.PySequence_GetItem(value,i);
851853
if(item==IntPtr.Zero)
852854
{
@@ -899,7 +901,7 @@ private static bool ToEnum(IntPtr value, Type obType, out object result, bool se
899901

900902
if(setError)
901903
{
902-
stringerror="invalid enumeration value";
904+
varerror="invalid enumeration value";
903905
Exceptions.SetError(Exceptions.ValueError,error);
904906
}
905907

‎src/runtime/interop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ internal class ObjectOffset
7474
staticObjectOffset()
7575
{
7676
intsize=IntPtr.Size;
77-
intn=0;// Py_TRACE_REFS add two pointers to PyObject_HEAD
77+
varn=0;// Py_TRACE_REFS add two pointers to PyObject_HEAD
7878
#ifPy_DEBUG
7979
_ob_next=0;
8080
_ob_prev=1*size;

‎src/runtime/moduleobject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public ModuleObject(string name)
4343
IntPtrpyname=Runtime.PyString_FromString(moduleName);
4444
IntPtrpyfilename=Runtime.PyString_FromString(filename);
4545
IntPtrpydocstring=Runtime.PyString_FromString(docstring);
46-
IntPtrpycls=TypeManager.GetTypeHandle(this.GetType());
46+
IntPtrpycls=TypeManager.GetTypeHandle(GetType());
4747
Runtime.PyDict_SetItemString(dict,"__name__",pyname);
4848
Runtime.PyDict_SetItemString(dict,"__file__",pyfilename);
4949
Runtime.PyDict_SetItemString(dict,"__doc__",pydocstring);
@@ -318,7 +318,7 @@ public CLRModule() : base("clr")
318318
// import requires the module to pass PyModule_Check. :(
319319
if(!hacked)
320320
{
321-
IntPtrtype=this.tpHandle;
321+
IntPtrtype=tpHandle;
322322
IntPtrmro=Marshal.ReadIntPtr(type,TypeOffset.tp_mro);
323323
IntPtrext=Runtime.ExtendTuple(mro,Runtime.PyModuleType);
324324
Marshal.WriteIntPtr(type,TypeOffset.tp_mro,ext);

‎src/runtime/pyobject.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,9 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
895895
returntrue;
896896
}
897897
else
898+
{
898899
returnbase.TryGetMember(binder,outresult);
900+
}
899901
}
900902

901903
publicoverrideboolTrySetMember(SetMemberBinderbinder,objectvalue)
@@ -906,13 +908,18 @@ public override bool TrySetMember(SetMemberBinder binder, object value)
906908
returntrue;
907909
}
908910
else
911+
{
909912
returnbase.TrySetMember(binder,value);
913+
}
910914
}
911915

912916
privatevoidGetArgs(object[]inargs,outPyTupleargs,outPyDictkwargs)
913917
{
914918
intarg_count;
915-
for(arg_count=0;arg_count<inargs.Length&&!(inargs[arg_count]isPy.KeywordArguments);++arg_count);
919+
for(arg_count=0;arg_count<inargs.Length&&!(inargs[arg_count]isPy.KeywordArguments);++arg_count)
920+
{
921+
;
922+
}
916923
IntPtrargtuple=Runtime.PyTuple_New(arg_count);
917924
for(vari=0;i<arg_count;i++)
918925
{
@@ -975,7 +982,9 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o
975982
returntrue;
976983
}
977984
else
985+
{
978986
returnbase.TryInvokeMember(binder,args,outresult);
987+
}
979988
}
980989

981990
publicoverrideboolTryInvoke(InvokeBinderbinder,object[]args,outobjectresult)
@@ -1003,7 +1012,9 @@ public override bool TryInvoke(InvokeBinder binder, object[] args, out object re
10031012
returntrue;
10041013
}
10051014
else
1015+
{
10061016
returnbase.TryInvoke(binder,args,outresult);
1017+
}
10071018
}
10081019

10091020
publicoverrideboolTryConvert(ConvertBinderbinder,outobjectresult)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp