Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #36 from abeaumont/feature/new-roles
Browse files Browse the repository at this point in the history
New roles
  • Loading branch information
abeaumont authored Oct 11, 2017
2 parents 0e92b0b + 90f6c91 commit 6ede4c4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
17 changes: 8 additions & 9 deletions scripts/generate-roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import "gopkg.in/bblfsh/sdk.v1/uast"
import "fmt"

func main() {
lastRole := uast.Visibility + 1
fmt.Println(
`////////////////////////////////////////////////////
// Automatically generated by "generate-roles.go" //
Expand All @@ -16,19 +15,19 @@ func main() {
static const char *id_to_roles[] = {`)

for i := 0; i < int(lastRole); i++ {
var name string
if i == 0 {
name = "roleInvalid"
} else {
roleID := uast.Role(i)
name = "role" + roleID.String()
var lastRole int
for i := 0;; i++ {
role := uast.Role(i).String()
if role == fmt.Sprintf("Role(%d)", i) {
break;
}
lastRole = i
name := "role" + role
fmt.Printf(" \"%s\",\n", name)
}
fmt.Println("};")

fmt.Println("#define TOTAL_ROLES", int(lastRole))
fmt.Println("#define TOTAL_ROLES", lastRole)

fmt.Println(`
const char *RoleNameForId(uint16_t id) {
Expand Down
8 changes: 7 additions & 1 deletion src/roles.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ static const char *id_to_roles[] = {
"roleIncomplete",
"roleUnannotated",
"roleVisibility",
"roleAnnotation",
"roleAnonymous",
"roleEnumeration",
"roleArithmetic",
"roleRelational",
"roleVariable",
};
#define TOTAL_ROLES 112
#define TOTAL_ROLES 117

const char *RoleNameForId(uint16_t id) {
if (id >= TOTAL_ROLES) {
Expand Down
2 changes: 1 addition & 1 deletion tests/roles_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static void TestRoleNameForId(void) {
CU_ASSERT_FATAL(strcmp(RoleNameForId(1), "roleIdentifier") == 0);

// Automatically test the rest of names
int nu_roles = 112;
int nu_roles = 117;
for (int i = 0; i < nu_roles; i++) {
const char *role = RoleNameForId(i);
CU_ASSERT_FATAL(strlen(role) > 4);
Expand Down

0 comments on commit 6ede4c4

Please sign in to comment.