From b3b8e55b4164be50bb5c4126ab8157a63dc6d9f9 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 3 Sep 2014 14:04:19 -0400 Subject: [PATCH] pep8analysis: update and remove old-style attributes Signed-off-by: Jean Privat --- contrib/pep8analysis/src/parser/lexer.nit | 22 ++-- contrib/pep8analysis/src/parser/parser.nit | 24 ++-- contrib/pep8analysis/src/parser/parser_nodes.nit | 145 ++++++---------------- contrib/pep8analysis/src/parser/parser_prod.nit | 4 +- contrib/pep8analysis/src/pep8analysis_web.nit | 1 + 5 files changed, 65 insertions(+), 131 deletions(-) diff --git a/contrib/pep8analysis/src/parser/lexer.nit b/contrib/pep8analysis/src/parser/lexer.nit index f1a3c44..f5b910a 100644 --- a/contrib/pep8analysis/src/parser/lexer.nit +++ b/contrib/pep8analysis/src/parser/lexer.nit @@ -6,14 +6,14 @@ intrude import parser_nodes private import tables redef class Token - var _text: nullable String + var text_cache: nullable String redef fun text do - var res = _text + var res = _text_cache if res != null then return res res = location.text - _text = res + _text_cache = res return res end @@ -245,7 +245,7 @@ redef class EOF init(loc: Location) do - _text = "" + _text_cache = "" _location = loc end end @@ -266,25 +266,25 @@ end class Lexer super TablesCapable # Last peeked token - var _token: nullable Token + var token: nullable Token # Lexer current state - var _state: Int = 0 + var state: Int = 0 # The source file - var _file: SourceFile + var file: SourceFile # Current character in the stream - var _stream_pos: Int = 0 + var stream_pos: Int = 0 # Current line number in the input stream - var _line: Int = 0 + var line: Int = 0 # Current column in the input stream - var _pos: Int = 0 + var pos: Int = 0 # Was the last character a cariage-return? - var _cr: Bool = false + var cr: Bool = false # Constante state values private fun state_initial: Int do return 0 end diff --git a/contrib/pep8analysis/src/parser/parser.nit b/contrib/pep8analysis/src/parser/parser.nit index 1c6b68f..4fd6be1 100644 --- a/contrib/pep8analysis/src/parser/parser.nit +++ b/contrib/pep8analysis/src/parser/parser.nit @@ -23,13 +23,13 @@ end class Parser super TablesCapable # Associated lexer - var _lexer: Lexer + var lexer: Lexer # Stack of pushed states and productions - var _stack: Array[State] + private var stack: Array[State] # Position in the stack - var _stack_pos: Int + private var stack_pos: Int # Create a new parser based on a given lexer init(lexer: Lexer) @@ -148,10 +148,10 @@ class Parser end end - var _reduce_table: Array[ReduceAction] + private var reduce_table: Array[ReduceAction] private fun build_reduce_table do - _reduce_table = new Array[ReduceAction].with_items( + reduce_table = new Array[ReduceAction].with_items( new ReduceAction0(0), new ReduceAction1(0), new ReduceAction2(0), @@ -194,11 +194,11 @@ end redef class Prod # Location on the first token after the start of a production # So outside the production for epilon production - var _first_location: nullable Location + var first_location: nullable Location # Location of the last token before the end of a production # So outside the production for epilon production - var _last_location: nullable Location + var last_location: nullable Location end # Find location of production nodes @@ -206,16 +206,16 @@ end private class ComputeProdLocationVisitor super Visitor # Currenlty visited productions that need a first token - var _need_first_prods: Array[Prod] = new Array[Prod] + var need_first_prods: Array[Prod] = new Array[Prod] # Already visited epsilon productions that waits something after them - var _need_after_epsilons: Array[Prod] = new Array[Prod] + var need_after_epsilons: Array[Prod] = new Array[Prod] # Already visited epsilon production that waits something before them - var _need_before_epsilons: Array[Prod] = new Array[Prod] + var need_before_epsilons: Array[Prod] = new Array[Prod] # Location of the last visited token in the current production - var _last_location: nullable Location = null + var last_location: nullable Location = null redef fun visit(n: nullable ANode) do @@ -305,7 +305,7 @@ private abstract class ReduceAction l1.append(l2) return l1 end - var _goto: Int + var goto: Int init(g: Int) do _goto = g end diff --git a/contrib/pep8analysis/src/parser/parser_nodes.nit b/contrib/pep8analysis/src/parser/parser_nodes.nit index e1fb641..97530a4 100644 --- a/contrib/pep8analysis/src/parser/parser_nodes.nit +++ b/contrib/pep8analysis/src/parser/parser_nodes.nit @@ -1,16 +1,14 @@ # Raw AST node hierarchy. # This file was generated by SableCC (http://www.sablecc.org/). -module parser_nodes is old_style_init +module parser_nodes import location # Root of the AST hierarchy abstract class ANode - var _location: nullable Location = null - # Location is set during AST building. Once built, location cannon be null # However, manual instanciated nodes may need mode care - fun location: Location do return _location.as(not null) + var location: Location is writable, noinit end # Ancestor of all tokens @@ -23,7 +21,6 @@ end # Ancestor of all productions abstract class Prod super ANode - fun location=(loc: Location) do _location = loc end class TEol super Token @@ -81,192 +78,130 @@ class TId end class EOF super Token - #private init noinit do end end class AError super EOF - #private init noinit do end end class ALine super Prod - var _n_label_decl: nullable ALabelDecl = null - fun n_label_decl: nullable ALabelDecl do return _n_label_decl - var _n_comment: nullable TComment = null - fun n_comment: nullable TComment do return _n_comment + var n_label_decl: nullable ALabelDecl = null + var n_comment: nullable TComment = null end class AInstruction super Prod - var _n_id: TId - fun n_id: TId do return _n_id - fun n_id=(n_id: TId) do _n_id = n_id - init do end + var n_id: TId is noinit end class AOperand super Prod - var _n_value: AValue - fun n_value: AValue do return _n_value - init do end + var n_value: AValue is noinit end class AValue super Prod end class ADirective super Prod end class AListing super Prod - var _n_lines: List[ALine] = new List[ALine] - fun n_lines: List[ALine] do return _n_lines - var _n_label_decl: nullable ALabelDecl = null - fun n_label_decl: nullable ALabelDecl do return _n_label_decl - var _n_end_block: TEndBlock - fun n_end_block: TEndBlock do return _n_end_block - init do end + var n_lines: List[ALine] = new List[ALine] + var n_label_decl: nullable ALabelDecl = null + var n_end_block: TEndBlock is noinit end class AEmptyLine super ALine - var _n_eol: TEol - fun n_eol: TEol do return _n_eol - init do end + var n_eol: TEol is noinit end abstract class ANonEmptyLine super ALine end class AInstructionLine super ANonEmptyLine - var _n_instruction: AInstruction - fun n_instruction: AInstruction do return _n_instruction - var _n_eol: TEol - fun n_eol: TEol do return _n_eol - init do end + var n_instruction: AInstruction is noinit + var n_eol: TEol is noinit end class ADirectiveLine super ANonEmptyLine - var _n_directive: ADirective - fun n_directive: ADirective do return _n_directive - var _n_eol: TEol - fun n_eol: TEol do return _n_eol - init do end + var n_directive: ADirective is noinit + var n_eol: TEol is noinit end class ALabelDecl super Prod - var _n_id: TId - fun n_id: TId do return _n_id - var _n_colon: TColon - fun n_colon: TColon do return _n_colon - init do end + var n_id: TId is noinit + var n_colon: TColon is noinit end class AUnaryInstruction super AInstruction end class ABinaryInstruction super AInstruction - var _n_operand: AOperand - fun n_operand: AOperand do return _n_operand - init do end + var n_operand: AOperand is noinit end class AImmediateOperand super AOperand end class AAnyOperand super AOperand - var _n_comma: TComma - fun n_comma: TComma do return _n_comma - var _n_id: TId - fun n_id: TId do return _n_id - init do end + var n_comma: TComma is noinit + var n_id: TId is noinit end class ALabelValue super AValue - var _n_id: TId - fun n_id: TId do return _n_id - init do end + var n_id: TId is noinit end class ANumberValue super AValue - var _n_number: TNumber - fun n_number: TNumber do return _n_number - init do end + var n_number: TNumber is noinit end class ACharValue super AValue - var _n_char: TChar - fun n_char: TChar do return _n_char - init do end + var n_char: TChar is noinit end class AStringValue super AValue - var _n_string: TString - fun n_string: TString do return _n_string - init do end + var n_string: TString is noinit end class AHexValue super AValue - var _n_hex: THex - fun n_hex: THex do return _n_hex - init do end + var n_hex: THex is noinit end class AByteDirective super ADirective - var _n_tk_byte: TTkByte - fun n_tk_byte: TTkByte do return _n_tk_byte - var _n_value: AValue - fun n_value: AValue do return _n_value - init do end + var n_tk_byte: TTkByte is noinit + var n_value: AValue is noinit end class AWordDirective super ADirective - var _n_tk_word: TTkWord - fun n_tk_word: TTkWord do return _n_tk_word - var _n_value: AValue - fun n_value: AValue do return _n_value - init do end + var n_tk_word: TTkWord is noinit + var n_value: AValue is noinit end class ABlockDirective super ADirective - var _n_tk_block: TTkBlock - fun n_tk_block: TTkBlock do return _n_tk_block - var _n_value: AValue - fun n_value: AValue do return _n_value - init do end + var n_tk_block: TTkBlock is noinit + var n_value: AValue is noinit end class AAsciiDirective super ADirective - var _n_tk_ascii: TTkAscii - fun n_tk_ascii: TTkAscii do return _n_tk_ascii - var _n_value: AValue - fun n_value: AValue do return _n_value - init do end + var n_tk_ascii: TTkAscii is noinit + var n_value: AValue is noinit end class AAddrssDirective super ADirective - var _n_tk_addrss: TTkAddrss - fun n_tk_addrss: TTkAddrss do return _n_tk_addrss - var _n_value: AValue - fun n_value: AValue do return _n_value - init do end + var n_tk_addrss: TTkAddrss is noinit + var n_value: AValue is noinit end class AEquateDirective super ADirective - var _n_tk_equate: TTkEquate - fun n_tk_equate: TTkEquate do return _n_tk_equate - var _n_value: AValue - fun n_value: AValue do return _n_value - init do end + var n_tk_equate: TTkEquate is noinit + var n_value: AValue is noinit end class ABurnDirective super ADirective - var _n_tk_burn: TTkBurn - fun n_tk_burn: TTkBurn do return _n_tk_burn - var _n_value: AValue - fun n_value: AValue do return _n_value - init do end + var n_tk_burn: TTkBurn is noinit + var n_value: AValue is noinit end class Start super Prod - var _n_base: nullable AListing - fun n_base: nullable AListing do return _n_base - var _n_eof: EOF - fun n_eof: EOF do return _n_eof + var n_base: nullable AListing + var n_eof: EOF is noinit init(n_base: nullable AListing, n_eof: EOF) do super diff --git a/contrib/pep8analysis/src/parser/parser_prod.nit b/contrib/pep8analysis/src/parser/parser_prod.nit index 8f71631..f7fb2f7 100644 --- a/contrib/pep8analysis/src/parser/parser_prod.nit +++ b/contrib/pep8analysis/src/parser/parser_prod.nit @@ -8,9 +8,7 @@ private import tables redef class ANode # Parent of the node in the AST - var _parent: nullable ANode - fun parent: nullable ANode do return _parent - fun parent=(p: nullable ANode) do _parent = p + var parent: nullable ANode is writable # Remove a child from the AST fun remove_child(child: ANode) diff --git a/contrib/pep8analysis/src/pep8analysis_web.nit b/contrib/pep8analysis/src/pep8analysis_web.nit index 6167d47..30c0849 100644 --- a/contrib/pep8analysis/src/pep8analysis_web.nit +++ b/contrib/pep8analysis/src/pep8analysis_web.nit @@ -31,6 +31,7 @@ import ast import model import cfg import flow_analysis +intrude import standard::stream in "C++" `{ #include -- 1.7.9.5