Skip to content

Commit

Permalink
Add style checker
Browse files Browse the repository at this point in the history
Ref. #799
  • Loading branch information
treiher committed Oct 22, 2021
1 parent a2a50f8 commit 7b23bfd
Show file tree
Hide file tree
Showing 50 changed files with 647 additions and 290 deletions.
16 changes: 8 additions & 8 deletions examples/apps/dhcp_client/specs/dhcp.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ package DHCP is
with Size => 8;

type Len is range 1 .. 255 with Size => 8;
type Subnet_Mask is mod 2**32;
type Subnet_Mask is mod 2 ** 32;
type Routers is sequence of IPv4::Address;
type Time_Servers is sequence of IPv4::Address;
type Name_Servers is sequence of IPv4::Address;
type Domain_Name_Servers is sequence of IPv4::Address;
type Enabled_Disabled is (Enabled => 1, Disabled => 0) with Size => 8;
type MTU is range 68 .. 2**16 - 1 with Size => 16;
type MTU is range 68 .. 2 ** 16 - 1 with Size => 16;

type Static_Route is
message
Expand All @@ -66,7 +66,7 @@ package DHCP is

type X_Window_System_Font_Servers is sequence of IPv4::Address;
type X_Window_System_Display_Managers is sequence of IPv4::Address;
type Lease_Time is mod 2**32;
type Lease_Time is mod 2 ** 32;

type Option_Overload is
(File_Overload => 1,
Expand All @@ -88,8 +88,8 @@ package DHCP is
with Size => 8;

type Option_Codes is sequence of Code;
type Maximum_DHCP_Message_Size is range 576 .. 2**16 - 1 with Size => 16;
type Time_Interval is mod 2**32;
type Maximum_DHCP_Message_Size is range 576 .. 2 ** 16 - 1 with Size => 16;
type Time_Interval is mod 2 ** 32;

type Option is
message
Expand Down Expand Up @@ -184,9 +184,9 @@ package DHCP is
-- https://www.iana.org/assignments/arp-parameters/arp-parameters.xml#arp-parameters-2.
type Hardware_Address_Type is (HT_Reserved => 0, HT_Ethernet_10 => 1) with Size => 8, Always_Valid;
type Hardware_Address_Length is (HL_Ethernet => 6) with Size => 8;
type Hops is mod 2**8;
type Transaction_ID is mod 2**32;
type Secs is mod 2**16;
type Hops is mod 2 ** 8;
type Transaction_ID is mod 2 ** 32;
type Secs is mod 2 ** 16;
type Reserved_Flags is range 0 .. 0 with Size => 15;
type Magic_Cookie is range 16#63825363# .. 16#63825363# with Size => 32;
type Options is sequence of Option;
Expand Down
20 changes: 15 additions & 5 deletions examples/apps/dhcp_client/specs/dhcp_client.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ package DHCP_Client is
Offer_Message_Type : DHCP::DHCP_Message_Type;
begin
Channel'Read (Offer);
Offer_Message_Types := [for O in Offer.Options if O'Valid and O.Code = DHCP::DHCP_Message_Type_Option => O.DHCP_Message_Type];
Offer_Message_Types := [for O in Offer.Options
if O'Valid and O.Code = DHCP::DHCP_Message_Type_Option
=> O.DHCP_Message_Type];
Offer_Message_Type := Offer_Message_Types'Head;
transition
goto Send_Request
Expand All @@ -97,13 +99,19 @@ package DHCP_Client is
Offer_Yiaddr := Offer.Yiaddr;
Offer_Siaddr := Offer.Siaddr;
Options'Append (
DHCP::Option'(Code => DHCP::DHCP_Message_Type_Option, Len => DHCP::DHCP_Message_Type'Size / 8, DHCP_Message_Type => DHCP::DHCPREQUEST)
DHCP::Option'(Code => DHCP::DHCP_Message_Type_Option,
Len => DHCP::DHCP_Message_Type'Size / 8,
DHCP_Message_Type => DHCP::DHCPREQUEST)
);
Options'Append (
DHCP::Option'(Code => DHCP::Requested_IP_Address_Option, Len => IPv4::Address'Size / 8, Requested_IP_Address => Offer_Yiaddr)
DHCP::Option'(Code => DHCP::Requested_IP_Address_Option,
Len => IPv4::Address'Size / 8,
Requested_IP_Address => Offer_Yiaddr)
);
Options'Append (
DHCP::Option'(Code => DHCP::Server_Identifier_Option, Len => IPv4::Address'Size / 8, Server_Identifier => Offer_Siaddr)
DHCP::Option'(Code => DHCP::Server_Identifier_Option,
Len => IPv4::Address'Size / 8,
Server_Identifier => Offer_Siaddr)
);
Request := DHCP::Message'(
Op => DHCP::BOOTREQUEST,
Expand Down Expand Up @@ -140,7 +148,9 @@ package DHCP_Client is
Ack_Message_Type : DHCP::DHCP_Message_Type;
begin
Channel'Read (Ack);
Ack_Message_Types := [for O in Ack.Options if O'Valid and O.Code = DHCP::DHCP_Message_Type_Option => O.DHCP_Message_Type];
Ack_Message_Types := [for O in Ack.Options
if O'Valid and O.Code = DHCP::DHCP_Message_Type_Option
=> O.DHCP_Message_Type];
Ack_Message_Type := Ack_Message_Types'Head;
transition
goto Success
Expand Down
20 changes: 10 additions & 10 deletions examples/apps/dhcp_client/specs/ipv4.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package IPv4 is

type Version is range 4 .. 4 with Size => 4;
type IHL is range 5 .. 15 with Size => 4;
type DCSP is mod 2**6;
type ECN is mod 2**2;
type Total_Length is mod 2**16;
type Identification is mod 2**16;
type Fragment_Offset is mod 2**13;
type TTL is mod 2**8;
type DCSP is mod 2 ** 6;
type ECN is mod 2 ** 2;
type Total_Length is mod 2 ** 16;
type Identification is mod 2 ** 16;
type Fragment_Offset is mod 2 ** 13;
type TTL is mod 2 ** 8;
type Protocol is (PROTOCOL_ICMP => 1, PROTOCOL_UDP => 17) with Size => 8, Always_Valid;
type Header_Checksum is mod 2**16;
type Address is mod 2**32;
type Header_Checksum is mod 2 ** 16;
type Address is mod 2 ** 32;

type Option_Class is (CONTROL => 0, DEBUGGING_AND_MEASUREMENT => 2) with Size => 2;
type Option_Number is mod 2**5;
type Option_Length is range 2 .. 2**8 - 1 with Size => 8;
type Option_Number is mod 2 ** 5;
type Option_Length is range 2 .. 2 ** 8 - 1 with Size => 8;

type Option is
message
Expand Down
12 changes: 6 additions & 6 deletions examples/apps/ping/specs/icmp.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ package ICMP is
with Size => 8;

type Code_Zero is range 0 .. 0 with Size => 8;
type Checksum is mod 2**16;
type Identifier is mod 2**16;
type Sequence_Number is mod 2**16;
type Pointer is mod 2**8;
type Timestamp is mod 2**32;
type Gateway_Internet_Address is mod 2**32;
type Checksum is mod 2 ** 16;
type Identifier is mod 2 ** 16;
type Sequence_Number is mod 2 ** 16;
type Pointer is mod 2 ** 8;
type Timestamp is mod 2 ** 32;
type Gateway_Internet_Address is mod 2 ** 32;
type Unused_32 is range 0 .. 0 with Size => 32;
type Unused_24 is range 0 .. 0 with Size => 24;

Expand Down
16 changes: 8 additions & 8 deletions examples/apps/ping/specs/ipv4.rflx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ package IPv4 is

type Version is range 4 .. 4 with Size => 4;
type IHL is range 5 .. 15 with Size => 4;
type DCSP is mod 2**6;
type ECN is mod 2**2;
type Total_Length is mod 2**16;
type Identification is mod 2**16;
type Fragment_Offset is mod 2**13;
type TTL is mod 2**8;
type DCSP is mod 2 ** 6;
type ECN is mod 2 ** 2;
type Total_Length is mod 2 ** 16;
type Identification is mod 2 ** 16;
type Fragment_Offset is mod 2 ** 13;
type TTL is mod 2 ** 8;
type Protocol is (P_ICMP => 1, P_UDP => 17) with Size => 8, Always_Valid;
type Header_Checksum is mod 2**16;
type Address is mod 2**32;
type Header_Checksum is mod 2 ** 16;
type Address is mod 2 ** 32;
type Options is sequence of IPv4_Option::Option;

type Packet is
Expand Down
4 changes: 2 additions & 2 deletions examples/apps/ping/specs/ipv4_option.rflx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package IPv4_Option is

type Option_Class is (Control => 0, Debugging_And_Measurement => 2) with Size => 2;
type Option_Number is mod 2**5;
type Option_Length is range 2 .. 2**8 - 1 with Size => 8;
type Option_Number is mod 2 ** 5;
type Option_Length is range 2 .. 2 ** 8 - 1 with Size => 8;

type Option is
message
Expand Down
2 changes: 1 addition & 1 deletion examples/specs
Submodule specs updated 510 files
8 changes: 2 additions & 6 deletions ide/gnatstudio/recordflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,14 @@ def __on_gps_started():
r"(?P<filename>[^:]+):"
r"(?P<line>\d+):"
r"(?P<column>\d+): "
r"(?P<subsystem>core|parser|model|cli|internal|graph): "
r"(?P<subsystem>\w+): "
r"(?P<severity>info|warning|error): "
r"(?P<message>.*)"
r"$"
)

generic_message_re = re.compile(
r"^"
r"(?P<subsystem>core|parser|model|cli|internal|graph): "
r"(?P<severity>info|warning|error): "
r"(?P<message>.*)"
r"$"
r"^(?P<subsystem>\w+): (?P<severity>info|warning|error): (?P<message>.*)$"
)


Expand Down
1 change: 1 addition & 0 deletions rflx/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Subsystem(Enum):
PYRFLX = auto()
ID = auto()
VALIDATOR = auto()
STYLE = auto()

def __str__(self) -> str:
return str.lower(self.name)
Expand Down
2 changes: 1 addition & 1 deletion rflx/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ def simplified(self) -> Expr:

@property
def symbol(self) -> str:
return "**"
return " ** "

def ada_expr(self) -> ada.Expr:
return ada.Pow(self.left.ada_expr(), self.right.ada_expr())
Expand Down
2 changes: 2 additions & 0 deletions rflx/specification/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from rflx.model import declaration as decl, statement as stmt
from rflx.specification.const import RESERVED_WORDS

from . import style
from .cache import Cache

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -1541,6 +1542,7 @@ def parse(self, *specfiles: Path) -> None:

for f in specfiles:
error.extend(self.__parse_specfile(f))
error.extend(style.check(f))
self.__sort_specs_topologically()
error.propagate()

Expand Down
Loading

0 comments on commit 7b23bfd

Please sign in to comment.