Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
DanG100 committed Sep 28, 2023
1 parent c23c3ff commit 55c7dca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
10 changes: 6 additions & 4 deletions dataplane/standalone/apigen/ccgen/ccgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func Generate(doc *docparser.SAIInfo, sai *saiast.SAIAPI) (map[string]string, er
APIName: apiName,
ProtoInclude: apiName + ".pb",
}
if apiName == "switch" {
switch apiName {
case "switch":
ccData.Globals = append(ccData.Globals, "std::unique_ptr<PortStateReactor> port_state;")
}
if apiName == "hostif" {
case "hostif":
ccData.Globals = append(ccData.Globals, "int nextIdx = 1;")
}
for _, fn := range iface.Funcs {
Expand Down Expand Up @@ -76,7 +76,9 @@ func sanitizeProtoName(inName string) string {
return name
}

// createCCData returns a struct with the template data for the given function.
// createCCData returns a two structs with the template data for the given function.
// The first is the implementation of the API: CreateFoo.
// The second is the a conversion func from attribute list to the proto message. covert_create_foo.
func createCCData(meta *saiast.FuncMetadata, apiName string, sai *saiast.SAIAPI, info *docparser.SAIInfo, fn *saiast.TypeDecl) (*templateFunc, *templateFunc) {
if info.Attrs[meta.TypeName] == nil {
fmt.Printf("no doc info for type: %v\n", meta.TypeName)
Expand Down
6 changes: 3 additions & 3 deletions dataplane/standalone/apigen/docparser/docparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (

// SAIInfo contains all the info parsed from the doxygen.
type SAIInfo struct {
// attrs is a map from sai type (sai_port_t) to its attributes.
// Attrs is a map from sai type (sai_port_t) to its attributes.
Attrs map[string]*Attr
// attrs is a map from enum name (sai_port_media_type_t) to the values of the enum.
// Enums is a map from enum name (sai_port_media_type_t) to the values of the enum.
Enums map[string][]*Enum
}

Expand Down Expand Up @@ -173,7 +173,7 @@ func memberToAttrInfo(enum MemberDef) *Attr {

func memberToEnumValueStrings(enum MemberDef) []*Enum {
res := []*Enum{}
prev := -1
prev := -1 // Since enum values may repeat, store previous enum value. If the enum value isn't an assignment, then it is prev + 1.
for i, value := range enum.EnumValues {
val := prev + 1
value.Initializer = strings.TrimPrefix(value.Initializer, "= ")
Expand Down
1 change: 1 addition & 0 deletions dataplane/standalone/apigen/saiast/saiast.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (sai *SAIAPI) GetFuncMeta(fn *TypeDecl) *FuncMetadata {
if strings.Contains(param.Typ, "entry") {
meta.Entry = TrimSAIName(strings.TrimPrefix(param.Typ, "const "), true, false)
}
// The switch_id is either the first or second arguments to function.
if (i == 0 || i == 1) && param.Name == "switch_id" {
meta.IsSwitchScoped = true
}
Expand Down

0 comments on commit 55c7dca

Please sign in to comment.