mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Have WUFFS_INCLUDE_GUARD cover the IMPLEMENTATION
This commit is contained in:
1 parent
71e604a71a
commit
fa95380a23
2 files changed
+33
-32
No files matched your search
@@ -302,22 +302,23 @@ func (g *gen) generate() ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
includeGuard := "WUFFS_INCLUDE_GUARD__" + strings.ToUpper(g.pkgName)
|
||||||
|
b.printf("#ifndef %s\n#define %s\n\n", includeGuard, includeGuard)
|
||||||
|
|
||||||
if err := g.genHeader(b); err != nil {
|
if err := g.genHeader(b); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
b.writex(wiStart)
|
b.writex(wiStart)
|
||||||
b.writeb('\n')
|
|
||||||
if err := g.genImpl(b); err != nil {
|
if err := g.genImpl(b); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
b.writex(wiEnd)
|
b.writex(wiEnd)
|
||||||
|
|
||||||
|
b.printf("#endif // %s\n\n", includeGuard)
|
||||||
return *b, nil
|
return *b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *gen) genHeader(b *buffer) error {
|
func (g *gen) genHeader(b *buffer) error {
|
||||||
includeGuard := "WUFFS_INCLUDE_GUARD__" + strings.ToUpper(g.pkgName)
|
|
||||||
b.printf("#ifndef %s\n#define %s\n\n", includeGuard, includeGuard)
|
|
||||||
|
|
||||||
if err := insertBasePublicH(b); err != nil {
|
if err := insertBasePublicH(b); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -374,7 +375,6 @@ func (g *gen) genHeader(b *buffer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
b.writes("\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n")
|
b.writes("\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n")
|
||||||
b.printf("#endif // %s\n\n", includeGuard)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -781,8 +781,8 @@ func (g *gen) writeCppImpls(b *buffer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
wiStart = []byte("\n#ifdef WUFFS_IMPLEMENTATION\n")
|
wiStart = []byte("\n#ifdef WUFFS_IMPLEMENTATION\n\n")
|
||||||
wiEnd = []byte("\n#endif // WUFFS_IMPLEMENTATION\n")
|
wiEnd = []byte("\n#endif // WUFFS_IMPLEMENTATION\n\n")
|
||||||
|
|
||||||
wigbpStart = []byte("\n#ifndef WUFFS_INCLUDE_GUARD__BASE_PUBLIC\n")
|
wigbpStart = []byte("\n#ifndef WUFFS_INCLUDE_GUARD__BASE_PUBLIC\n")
|
||||||
wigbpEnd = []byte("\n#endif // WUFFS_INCLUDE_GUARD__BASE_PUBLIC\n")
|
wigbpEnd = []byte("\n#endif // WUFFS_INCLUDE_GUARD__BASE_PUBLIC\n")
|
||||||
@@ -815,10 +815,18 @@ func (g *gen) writeUse(b *buffer, n *a.Use) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if i := bytes.Index(usee, wiStart); i < 0 {
|
trimmed := []byte(nil)
|
||||||
|
if i := bytes.Index(usee, wiStart); i >= 0 {
|
||||||
|
remaining := usee[i+len(wiStart):]
|
||||||
|
if j := bytes.Index(remaining, wiEnd); j >= 0 {
|
||||||
|
trimmed = append(trimmed, usee[:i]...)
|
||||||
|
trimmed = append(trimmed, '\n')
|
||||||
|
trimmed = append(trimmed, remaining[j+len(wiEnd):]...)
|
||||||
|
usee = trimmed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(trimmed) == 0 {
|
||||||
return fmt.Errorf("use %q: previously generated code %q could not be inlined", useDirname, useeFilename)
|
return fmt.Errorf("use %q: previously generated code %q could not be inlined", useDirname, useeFilename)
|
||||||
} else {
|
|
||||||
usee = usee[:i]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b.printf("// ---------------- BEGIN USE %q\n\n", useDirname)
|
b.printf("// ---------------- BEGIN USE %q\n\n", useDirname)
|
||||||
|
|||||||
+15
-22
@@ -60,16 +60,26 @@ func doGenrelease(args []string) error {
|
|||||||
|
|
||||||
// First, cat all of the headers together, filtering out duplicate
|
// First, cat all of the headers together, filtering out duplicate
|
||||||
// WUFFS_INCLUDE_GUARD__FOO sections and overriding WUFFS_VERSION.
|
// WUFFS_INCLUDE_GUARD__FOO sections and overriding WUFFS_VERSION.
|
||||||
|
implementations := [][]byte(nil)
|
||||||
for _, filename := range args {
|
for _, filename := range args {
|
||||||
s, err := ioutil.ReadFile(filename)
|
s, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trimmed := []byte(nil)
|
||||||
if i := bytes.Index(s, grImplStartsHere); i >= 0 {
|
if i := bytes.Index(s, grImplStartsHere); i >= 0 {
|
||||||
s = s[:i]
|
remaining := s[i+len(grImplStartsHere):]
|
||||||
} else {
|
if j := bytes.Index(remaining, grImplEndsHere); j >= 0 {
|
||||||
return fmt.Errorf("could not find %q", grImplStartsHere)
|
implementations = append(implementations, remaining[:j])
|
||||||
|
trimmed = append(trimmed, s[:i]...)
|
||||||
|
trimmed = append(trimmed, '\n')
|
||||||
|
trimmed = append(trimmed, remaining[j+len(grImplEndsHere):]...)
|
||||||
|
s = trimmed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(trimmed) == 0 {
|
||||||
|
return fmt.Errorf("could not find %q or %q", grImplStartsHere, grImplEndsHere)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.gen(unformatted, s); err != nil {
|
if err := h.gen(unformatted, s); err != nil {
|
||||||
@@ -82,26 +92,9 @@ func doGenrelease(args []string) error {
|
|||||||
|
|
||||||
// Then, cat all of the implementations together, filtering out duplicate
|
// Then, cat all of the implementations together, filtering out duplicate
|
||||||
// WUFFS_INCLUDE_GUARD__BASE_PRIVATE sections.
|
// WUFFS_INCLUDE_GUARD__BASE_PRIVATE sections.
|
||||||
for _, filename := range args {
|
for i, s := range implementations {
|
||||||
s, err := ioutil.ReadFile(filename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if i := bytes.Index(s, grImplStartsHere); i >= 0 {
|
|
||||||
s = s[i+len(grImplStartsHere):]
|
|
||||||
} else {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if i := bytes.Index(s, grImplEndsHere); i >= 0 {
|
|
||||||
s = s[:i]
|
|
||||||
} else {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := h.gen(unformatted, s); err != nil {
|
if err := h.gen(unformatted, s); err != nil {
|
||||||
return fmt.Errorf("%v in %s", err, filename)
|
return fmt.Errorf("%v in %s", err, args[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user