From: Jean Privat Date: Thu, 18 Sep 2014 14:58:01 +0000 (-0400) Subject: nitpreyty: remove the oldstyle syntax, there is still some fixme to fix X-Git-Tag: v0.6.9~32^2~1 X-Git-Url: http://nitlanguage.org nitpreyty: remove the oldstyle syntax, there is still some fixme to fix Signed-off-by: Jean Privat --- diff --git a/src/nitpretty.nit b/src/nitpretty.nit index 99834a8..e7a733a 100644 --- a/src/nitpretty.nit +++ b/src/nitpretty.nit @@ -616,7 +616,11 @@ redef class AAnnotation redef fun accept_pretty_printer(v) do v.visit n_atid if not n_args.is_empty then - v.visit n_opar + if n_opar == null then + v.adds + else + v.visit n_opar + end v.visit_list n_args v.visit n_cpar end @@ -928,8 +932,7 @@ redef class AAttrPropdef super v.visit n_kwvar v.adds - if n_id != null then v.visit n_id - if n_id2 != null then v.visit n_id2 + v.visit n_id2 if n_type != null then v.consume ":" @@ -937,16 +940,6 @@ redef class AAttrPropdef v.visit n_type end - if n_readable != null then - v.adds - v.visit n_readable - end - - if n_writable != null then - v.adds - v.visit n_writable - end - if n_expr != null then v.adds v.consume "=" @@ -987,6 +980,10 @@ end redef class AMethPropdef redef fun accept_pretty_printer(v) do + # TODO: Handle extern annotations + + var before = v.indent + var can_inline = v.can_inline(self) super if n_kwinit != null then v.visit n_kwinit if n_kwmeth != null then v.visit n_kwmeth @@ -1004,94 +1001,13 @@ redef class AMethPropdef else v.adds end - end - # Can be inlined if: - # * block is empty or can be inlined - # * contains no comments - redef fun is_inlinable do - if not super then return false - if n_annotations != null and not n_annotations.is_inlinable then return false - if n_block != null and not n_block.is_inlinable then return false - if not collect_comments.is_empty then return false - return true - end -end - -redef class AMainMethPropdef - redef fun accept_pretty_printer(v) do - v.visit n_block - v.addn - end -end - -redef class ADeferredMethPropdef - redef fun accept_pretty_printer(v) do - super - if n_annotations == null then - while not v.current_token isa TKwis do v.skip - v.consume "is" - v.adds - while not v.current_token isa TKwabstract do v.skip - v.consume "abstract" - end - v.finish_line - v.addn - end -end - -redef class AExternPropdef - redef fun accept_pretty_printer(v) do - super - while v.current_token isa TEol do v.skip - - if v.current_token isa TKwis then - v.consume "is" - v.adds - end - - if v.current_token isa TKwextern then - v.consume "extern" - v.adds + if n_extern_calls != null or n_extern_code_block != null then + if n_annotations != null then v.adds + if n_extern_calls != null then v.visit n_extern_calls + if n_extern_code_block != null then v.visit n_extern_code_block end - if n_extern != null then v.visit n_extern - if n_extern_calls != null then v.visit n_extern_calls - if n_extern_code_block != null then v.visit n_extern_code_block - v.finish_line - v.addn - end - - redef fun is_inlinable do - if not super then return false - if n_block != null and not n_block.is_inlinable then return false - if n_extern_calls != null and not n_extern_calls.is_inlinable then return false - if n_extern_code_block != null and not n_extern_code_block.is_inlinable then return false - return true - end - - redef fun must_be_inline do - if super then return true - return n_extern != null - end -end - -redef class AInternMethPropdef - redef fun accept_pretty_printer(v) do - super - v.consume "is" - v.adds - v.consume "intern" - v.finish_line - v.addn - end -end - -redef class AConcreteMethPropdef - redef fun accept_pretty_printer(v) do - var before = v.indent - var can_inline = v.can_inline(self) - super var n_block = self.n_block if n_block != null then @@ -1149,6 +1065,26 @@ redef class AConcreteMethPropdef v.addn assert v.indent == before end + + # Can be inlined if: + # * block is empty or can be inlined + # * contains no comments + redef fun is_inlinable do + if not super then return false + if n_annotations != null and not n_annotations.is_inlinable then return false + if n_block != null and not n_block.is_inlinable then return false + if n_extern_calls != null and not n_extern_calls.is_inlinable then return false + if n_extern_code_block != null and not n_extern_code_block.is_inlinable then return false + if not collect_comments.is_empty then return false + return true + end +end + +redef class AMainMethPropdef + redef fun accept_pretty_printer(v) do + v.visit n_block + v.addn + end end redef class ASignature @@ -1903,34 +1839,6 @@ redef class AAttrReassignExpr end end -redef class AAble - redef fun accept_pretty_printer(v) do - if n_kwredef != null then - v.visit n_kwredef - v.adds - end - - if not n_visibility isa APublicVisibility then - v.visit n_visibility - v.adds - end - end -end - -redef class AReadAble - redef fun accept_pretty_printer(v) do - super - v.visit n_kwreadable - end -end - -redef class AWriteAble - redef fun accept_pretty_printer(v) do - super - v.visit n_kwwritable - end -end - # Exprs redef class AVardeclExpr diff --git a/tests/sav/fixme/nitpretty_args21.res b/tests/sav/fixme/nitpretty_args21.res new file mode 100644 index 0000000..f4a3324 --- /dev/null +++ b/tests/sav/fixme/nitpretty_args21.res @@ -0,0 +1,87 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import end +intrude import standard::kernel +private import standard::string + +`{`} + +`{ +#ifdef truc + #undef truc +#endif +`} + +in "C headers" `{ + #include +`} + +fun err: Int is extern `{ return 1; `} + +fun errno: Int is extern `{ + return errno; +`} + +fun errnoooooooooooooooooooooooooooooooooooooooooooooooooooooooooo: Int is extern `{ + return errno; +`} + +private class A + var my_attr = 1234 + + fun baz(msg: String) import String.length, String.to_cstring, my_attr, my_attr= `{ + char *c_msg; + int msg_len; + + /* String_to_cstring isa a allback to msg.to_cstring */ + c_msg = String_to_cstring( msg ); + + /* String_length is a callback to msg.length */ + msg_len = String_length( msg ); + + printf( "received msg: %s, of length = %d\n", c_msg, msg_len ); + + /* A_my_attr is a callback to the getter of self.my_attr */ + printf( "old attr %d\n", A_my_attr(recv) ); + + if(chose) + truc; + else + chose; + + /* A_my_attr is a callback to the setter of self.my_attr= */ + A_my_attr__assign( recv, msg_len ); + `} +end + +extern class TimeT `{time_t`} + new `{ return time(NULL); `} + new from_i(i: Int) `{ return i; `} + fun update `{ time(&recv); `} + + fun ctime: String import NativeString.to_s_with_copy `{ + return NativeString_to_s_with_copy( ctime(&recv) ); + `} + + # Difference in secondes from start (self if the end time) + fun difftime(start: TimeT): Float `{ return difftime(recv, start); `} + + private fun intern_poll(in_fds: Array[Int], out_fds: Array[Int]): nullable Int is import + Array[Int].length, Array[Int].[], Int.as(nullable Int) `{`} +end + +fun address_is_null: Bool is extern "address_is_null" + +fun free `{ free(recv); `} diff --git a/tests/sav/nitpretty_args23.res b/tests/sav/nitpretty_args23.res index 5b727f7..08a4d49 100644 --- a/tests/sav/nitpretty_args23.res +++ b/tests/sav/nitpretty_args23.res @@ -13,10 +13,10 @@ # limitations under the License. class Foo - var _a: Int - private var _b: nullable Int - protected var _c = 10 - var _d: Int = 10 + var a: Int + private var b: nullable Int + protected var c = 10 + var d: Int = 10 end var foo = new Foo(1, 2) diff --git a/tests/test_pretty/test_attr2.nit b/tests/test_pretty/test_attr2.nit index 5b727f7..08a4d49 100644 --- a/tests/test_pretty/test_attr2.nit +++ b/tests/test_pretty/test_attr2.nit @@ -13,10 +13,10 @@ # limitations under the License. class Foo - var _a: Int - private var _b: nullable Int - protected var _c = 10 - var _d: Int = 10 + var a: Int + private var b: nullable Int + protected var c = 10 + var d: Int = 10 end var foo = new Foo(1, 2)