Skip to content

Commit

Permalink
Struct field pointer arithmetics. Fixes #724 (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamphaus authored and elliotchance committed May 8, 2018
1 parent ef95d27 commit aaf7aa2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
19 changes: 18 additions & 1 deletion tests/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,25 @@ const Point2 p2[] = { { .y = 4, .x = 5 } };
const Point2* getPoint(int index) {
return &(p2[index]);
}
typedef unsigned char pcre_uchar;
typedef struct spu {
pcre_uchar *hvm;
} spu;

void pointer_arithm_in_struct() {
pcre_uchar str[] = "abcd";
spu s;
spu *ps = &s;
ps->hvm = &str[1];
is_true(ps->hvm == &str[1]);
ps->hvm += 2;
is_true(ps->hvm == &str[3]);

}

int main()
{
plan(69);
plan(71);

struct programming variable;
char *s = "Programming in Software Development.";
Expand Down Expand Up @@ -614,5 +629,7 @@ int main()

struct_inside_union();

pointer_arithm_in_struct();

done_testing();
}
7 changes: 1 addition & 6 deletions transpiler/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,8 @@ func transpileCompoundAssignOperator(
return nil, "", nil, nil, fmt.Errorf("Expr is nil")
}
preStmts, postStmts = combinePreAndPostStmts(preStmts, postStmts, newPre, newPost)
var name string
name, err = getName(p, n.Children()[0])
if err != nil {
return nil, "", nil, nil, err
}
v = &goast.BinaryExpr{
X: goast.NewIdent(name),
X: left,
Op: token.ASSIGN,
Y: v,
}
Expand Down

0 comments on commit aaf7aa2

Please sign in to comment.