Skip to content

Commit

Permalink
Refactor generated metadata style (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Apr 26, 2018
1 parent 2bd3dfa commit 8fbda3a
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 81 deletions.
2 changes: 1 addition & 1 deletion inc/saisamplepacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <saitypes.h>

/**
* @defgroup SAISAMPLEPACKET SAI - samplepacket specific public APIs and data structures
* @defgroup SAISAMPLEPACKET SAI - Samplepacket specific public APIs and data structures
*
* @{
*/
Expand Down
4 changes: 2 additions & 2 deletions meta/cap.pm
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ sub ProcessCapCapability

for my $cap (@cap)
{
if (not $cap=~ /^(CREATE|GET|SET)$/)
if (not $cap =~ /^(CREATE|GET|SET)$/)
{
LogError "invalid capability tag value '$val' ($cap)";
return undef;
Expand All @@ -125,7 +125,7 @@ sub ProcessCapEnumCapability

for my $cap (@cap)
{
if (not $cap=~ /^SAI_[0-9A-Z_]+$/)
if (not $cap =~ /^SAI_[0-9A-Z_]+$/)
{
LogError "invalid enum capability tag value '$val' ($cap)";
return undef;
Expand Down
77 changes: 38 additions & 39 deletions meta/parse.pl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ sub ProcessTagType

return $val if $val =~ /^(bool|char)$/;

return $val if $val =~/^sai_\w+_t$/ and not $val =~ /_attr_(extensions_)?t/;
return $val if $val =~ /^sai_\w+_t$/ and not $val =~ /_attr_(extensions_)?t/;

return $val if $val =~ /^sai_pointer_t sai_\w+_notification_fn$/;

Expand Down Expand Up @@ -179,15 +179,15 @@ sub ProcessTagCondition

my @conditions = split/\s+(?:or|and)\s+/,$val;

if ($val =~/or.+and|and.+or/)
if ($val =~ /or.+and|and.+or/)
{
LogError "mixed conditions and/or is not supported: $val";
return undef;
}

for my $cond (@conditions)
{
if (not $cond =~/^(SAI_\w+) == (true|false|SAI_\w+|$NUMBER_REGEX)$/)
if (not $cond =~ /^(SAI_\w+) == (true|false|SAI_\w+|$NUMBER_REGEX)$/)
{
LogError "invalid condition tag value '$val' ($cond), expected SAI_ENUM == true|false|SAI_ENUM|number";
return undef;
Expand All @@ -207,20 +207,17 @@ sub ProcessTagDefault
{
my ($type, $value, $val) = @_;

return $val if $val =~/^(empty|internal|vendor|const)/;
return $val if $val =~ /^(empty|internal|vendor|const)/;

return $val if $val =~/^(attrvalue) SAI_\w+_ATTR_\w+$/;
return $val if $val =~ /^(attrvalue) SAI_\w+_ATTR_\w+$/;

return $val if $val =~/^(true|false|NULL|SAI_\w+|$NUMBER_REGEX)$/ and not $val =~ /_ATTR_|OBJECT_TYPE/;
return $val if $val =~ /^(true|false|NULL|SAI_\w+|$NUMBER_REGEX)$/ and not $val =~ /_ATTR_|OBJECT_TYPE/;

return $val if $val =~/^0\.0\.0\.0$/;
return $val if $val =~ /^0\.0\.0\.0$/;

return $val if $val eq "disabled";

if ($val eq "\"\"")
{
return $val;
}
return $val if $val eq "\"\"";

LogError "invalid default tag value '$val' on $type $value";
return undef;
Expand All @@ -237,7 +234,7 @@ sub ProcessTagIsVlan
{
my ($type, $value, $val) = @_;

return $val if $val =~/^(true|false)$/i;
return $val if $val =~ /^(true|false)$/i;

LogError "isvlan tag value '$val', expected true/false";
return undef;
Expand Down Expand Up @@ -316,8 +313,8 @@ sub ProcessDescription

my $order = join(":",@order);

return if $order =~/^$rightOrder$/;
return if $order =~/^ignore$/;
return if $order =~ /^$rightOrder$/;
return if $order =~ /^ignore$/;

LogWarning "metadata tags are not in right order: $order on $value";
LogWarning " correct order: $rightOrder or ignore";
Expand Down Expand Up @@ -395,7 +392,7 @@ sub ProcessEnumSection

my $eitemd = ExtractDescription($enumtypename, $enumvaluename, $ev->{detaileddescription}[0]);

if ($eitemd =~/\@ignore/)
if ($eitemd =~ /\@ignore/)
{
LogInfo "Ignoring $enumvaluename";
next;
Expand All @@ -407,14 +404,15 @@ sub ProcessEnumSection

LogWarning "Value $enumvaluename of $enumtypename is not prefixed as $enumprefix" if not $enumvaluename =~ /^$enumprefix/;

if (not $enumvaluename =~/^[A-Z0-9_]+$/)
if (not $enumvaluename =~ /^[A-Z0-9_]+$/)
{
LogError "enum $enumvaluename uses characters outside [A-Z0-9_]+";
}
}

# remove unnecessary attributes
my @values = @{ $SAI_ENUMS{$enumtypename}{values} };

@values = grep(!/^SAI_\w+_(START|END)$/, @values);
@values = grep(!/^SAI_\w+(CUSTOM_RANGE_BASE)$/, @values);

Expand Down Expand Up @@ -454,6 +452,7 @@ sub ProcessEnumSection
# remove unnecessary attributes
@values = @{ $SAI_ENUMS{$enumtypename}{values} };
@values = grep(!/^${prefix}(CUSTOM_RANGE_|FIELD_|ACTION_)?(START|END)$/, @values);

$SAI_ENUMS{$enumtypename}{values} = \@values;

# this is attribute
Expand Down Expand Up @@ -845,7 +844,6 @@ sub ProcessSingleEnum
}

WriteSource "-1"; # guard

WriteSource "};";

WriteSource "const char* const sai_metadata_${typedef}_enum_values_names[] = {";
Expand Down Expand Up @@ -981,6 +979,7 @@ sub CreateMetadataHeaderAndSource
WriteSource "SAI_OBJECT_TYPE_" . uc($objtype). ",";
}

WriteSource "-1";
WriteSource "};";
}

Expand Down Expand Up @@ -1120,6 +1119,7 @@ sub ProcessObjects
WriteSource "$obj,";
}

WriteSource "-1"; # guard
WriteSource "};";

return "sai_metadata_${attr}_allowed_objects";
Expand Down Expand Up @@ -1261,7 +1261,7 @@ sub ProcessStoreDefaultValue

# at this point we can't determine whether object is non object id

if (defined $value and $value =~/vendor|attrvalue/)
if (defined $value and $value =~ /vendor|attrvalue/)
{
return "true";
}
Expand All @@ -1270,7 +1270,7 @@ sub ProcessStoreDefaultValue

$flags = "@flags";

if ($flags =~/MANDATORY/ and $flags =~ /CREATE_AND_SET/)
if ($flags =~ /MANDATORY/ and $flags =~ /CREATE_AND_SET/)
{
return "true";
}
Expand Down Expand Up @@ -1442,7 +1442,6 @@ sub ProcessConditionsGeneric
}

WriteSource "NULL";

WriteSource "};";

return "sai_metadata_${name}s_${attr}";
Expand Down Expand Up @@ -1829,23 +1828,23 @@ sub CheckEnumNaming
{
my ($attr, $type) = @_;

LogError "can't match sai type on '$type'" if not $type =~/.*sai_(\w+)_t/;
LogError "can't match sai type on '$type'" if not $type =~ /.*sai_(\w+)_t/;

my $enumTypeName = uc($1);

return if $attr =~ /_${enumTypeName}_LIST$/;
return if $attr =~ /_$enumTypeName$/;

$attr =~/SAI_(\w+?)_ATTR(_\w+)/;
$attr =~ /SAI_(\w+?)_ATTR(_\w+)/;

my $attrObjectType = $1;
my $attrSuffix = $2;

if ($enumTypeName =~/^${attrObjectType}_(\w+)$/)
if ($enumTypeName =~ /^${attrObjectType}_(\w+)$/)
{
my $enumTypeNameSuffix = $1;

return if $attrSuffix =~/_$enumTypeNameSuffix$/;
return if $attrSuffix =~ /_$enumTypeNameSuffix$/;

LogError "enum starts by object type $attrObjectType but not ending on $enumTypeNameSuffix in $enumTypeName";
}
Expand Down Expand Up @@ -1966,7 +1965,7 @@ sub CreateMetadataForAttributes

WriteSectionComment "Define SAI_OBJECT_TYPE_EXTENSIONS_MAX";

WriteHeader "#define SAI_OBJECT_TYPE_EXTENSIONS_MAX $count";
WriteHeader "#define SAI_OBJECT_TYPE_EXTENSIONS_MAX ((sai_object_type_t)$count)";
}

sub CreateEnumHelperMethod
Expand All @@ -1982,7 +1981,7 @@ sub CreateEnumHelperMethod
WriteSource "}";

WriteHeader "extern const char* sai_metadata_get_$1_name(";
WriteHeader "_In_ $key value);";
WriteHeader "_In_ $key value);\n";
}

sub CreateEnumHelperMethods
Expand All @@ -1991,7 +1990,7 @@ sub CreateEnumHelperMethods

for my $key (sort keys %SAI_ENUMS)
{
next if $key =~/_attr_(extensions_)?t$/;
next if $key =~ /_attr_(extensions_)?t$/;

CreateEnumHelperMethod($key);
}
Expand Down Expand Up @@ -2267,7 +2266,7 @@ sub ProcessRevGraph
WriteSource "&$mn,";
}

WriteSource "NULL,";
WriteSource "NULL";

WriteSource "};";

Expand Down Expand Up @@ -2478,7 +2477,7 @@ sub CreateApisStruct

$api = lc($1);

next if $api =~/unspecified/;
next if $api =~ /unspecified/;

WriteHeader "sai_${api}_api_t* ${api}_api;";
}
Expand All @@ -2489,7 +2488,7 @@ sub CreateApisStruct

WriteSectionComment "Define SAI_API_EXTENSIONS_MAX";

WriteHeader "#define SAI_API_EXTENSIONS_MAX $count";
WriteHeader "#define SAI_API_EXTENSIONS_MAX ((sai_api_t)$count)";
}

sub CreateApisQuery
Expand Down Expand Up @@ -2872,7 +2871,7 @@ sub CheckApiDefines

for my $api (@apis)
{
my $short = lc($1) if $api =~/SAI_API_(\w+)/;
my $short = lc($1) if $api =~ /SAI_API_(\w+)/;

next if $short eq "unspecified";

Expand Down Expand Up @@ -3076,17 +3075,17 @@ sub ProcessStructItem
{
my ($type, $struct) = @_;

$type = $1 if $struct =~ /^sai_(\w+)_list_t$/ and $type =~/^(\w+)\*$/;
$type = $1 if $struct =~ /^sai_(\w+)_list_t$/ and $type =~ /^(\w+)\*$/;

return if defined $ProcessedItems{$type};

return if defined $SAI_ENUMS{$type}; # struct entry is enum

return if $type eq "bool";

return if $type =~/^sai_(u?int\d+|ip[46]|mac|cos|vlan_id|queue_index)_t/; # primitives, we could get that from defines
return if $type =~/^u?int\d+_t/;
return if $type =~/^sai_[su]\d+_list_t/;
return if $type =~ /^sai_(u?int\d+|ip[46]|mac|cos|vlan_id|queue_index)_t/; # primitives, we could get that from defines
return if $type =~ /^u?int\d+_t/;
return if $type =~ /^sai_[su]\d+_list_t/;

if ($type eq "sai_object_id_t" or $type eq "sai_object_list_t")
{
Expand Down Expand Up @@ -3150,8 +3149,8 @@ sub CheckAttributeValueUnion
my $type = $Union{$key}{type};

next if $type eq "char[32]";
next if $type =~/sai_u?int\d+_t/;
next if $type =~/sai_[su]\d+_list_t/;
next if $type =~ /sai_u?int\d+_t/;
next if $type =~ /sai_[su]\d+_list_t/;

next if grep(/^$type$/, @primitives);

Expand Down Expand Up @@ -3340,7 +3339,7 @@ sub ExtractUnionsInfo
$SAI_UNIONS{$name}{file} = $file;
$SAI_UNIONS{$name}{name} = $name;
$SAI_UNIONS{$name}{def} = $def;
$SAI_UNIONS{$name}{nested} = 1 if $def =~/::/;
$SAI_UNIONS{$name}{nested} = 1 if $def =~ /::/;

my %s = ExtractStructInfoEx($name, $file);

Expand Down Expand Up @@ -3380,7 +3379,7 @@ sub MergeExtensionsEnums

$SAI_ENUMS{$enum}{values} = \@values;

next if not $exenum =~/_attr_extensions_t/;
next if not $exenum =~ /_attr_extensions_t/;

for my $exvalue (@exvalues)
{
Expand Down
4 changes: 2 additions & 2 deletions meta/saisanitycheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -4240,7 +4240,7 @@ void check_graph_connected()

helper_check_graph_connected(SAI_OBJECT_TYPE_PORT, visited);

int i = 0;
size_t i = 0;

for (; i < SAI_OBJECT_TYPE_EXTENSIONS_MAX; ++i)
{
Expand Down Expand Up @@ -4270,7 +4270,7 @@ void check_get_attr_metadata()

int count = 0;

int ot = 0;
size_t ot = 0;

for (; ot < SAI_OBJECT_TYPE_EXTENSIONS_MAX; ++ot)
{
Expand Down
Loading

0 comments on commit 8fbda3a

Please sign in to comment.