-
Notifications
You must be signed in to change notification settings - Fork 0
/
declarations.go
54 lines (47 loc) · 1.21 KB
/
declarations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package vasker
import (
"github.com/golang/protobuf/proto"
cctpb "snowfrost.garden/vasker/cc_grammar"
)
func VarDecl(name string, ident *cctpb.Identifier) *cctpb.Declaration {
ds := &cctpb.DeclarationSpecifier{
Value: &cctpb.DeclarationSpecifier_TypeSpecifier{
&cctpb.TypeSpecifier{
Value: &cctpb.TypeSpecifier_SimpleTypeSpecifier{
&cctpb.SimpleTypeSpecifier{
Value: &cctpb.SimpleTypeSpecifier_DeclaredName{ident},
},
},
},
},
}
d := &cctpb.Declarator{
Value: &cctpb.Declarator_DeclaredName{
&cctpb.Identifier{
Id: proto.String(name),
},
},
}
sd := &cctpb.SimpleDeclaration{}
sd.Specifiers = append(sd.Specifiers, ds)
sd.Declarators = append(sd.Declarators, d)
return &cctpb.Declaration{
Value: &cctpb.Declaration_BlockDeclaration{
&cctpb.BlockDeclaration{
Value: &cctpb.BlockDeclaration_SimpleDeclaration{sd},
},
},
}
}
func DeclareAuto(name string) *cctpb.Declaration {
return VarDecl(name, Id("auto"))
}
func StdStringCtor(s string) *cctpb.Expression {
fc := &cctpb.FunctionCallExpression{
Name: IdExpr(NsId("std", "string")),
}
AddFuncArg(fc, StringLiteralExpr(s))
return &cctpb.Expression{
Value: &cctpb.Expression_FunctionCallExpression{fc},
}
}