Skip to content

Commit

Permalink
Multiple file generation support for python
Browse files Browse the repository at this point in the history
Signed-off-by: xaxys <tpnnghd@163.com>
  • Loading branch information
xaxys committed Dec 6, 2023
1 parent 03c0118 commit c7af254
Show file tree
Hide file tree
Showing 6 changed files with 1,118 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Targets:
c-single [c_single]
c_minimal [c-minimal, c_min, c-min]
c_minimal_single [c-minimal-single, c_min_single, c-min-single]
python [py]
python-single [python_single, py-single, py_single]
```

Expand All @@ -58,6 +59,7 @@ When selecting the target language, you can use the aliases inside `[]`. For exa
- `c-single`: C language, output one file that includes all definitions for all `.bb` files. The output file name (including the extension) is determined by the `-o` option.
- `c_minimal`: C language, output one `.bb.h` file and one `.bb.c` file for each `.bb` file. Do not generate getter/setter methods for fields.
- `c_minimal_single`: C language, output one file that includes all definitions for all `.bb` files. The output file name (including the extension) is determined by the `-o` option. Do not generate getter/setter methods for fields.
- `python`: Python language, output one `_bb.py` file for each `.bb` file.
- `python-single`: Python language, output one file that includes all definitions for all `.bb` files. The output file name (including the extension) is determined by the `-o` option.

## Protocol Syntax
Expand Down
2 changes: 2 additions & 0 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Targets:
c-single [c_single]
c_minimal [c-minimal, c_min, c-min]
c_minimal_single [c-minimal-single, c_min_single, c-min-single]
python [py]
python-single [python_single, py-single, py_single]
```

Expand All @@ -58,6 +59,7 @@ Targets:
- `c-single`:C 语言,为所有 `.bb` 文件输出一个包含所有定义的文件。输出文件名(包括扩展名)由 `-o` 选项确定。
- `c_minimal`:C 语言,为每个 `.bb` 文件输出一个 `.bb.h` 文件和一个 `.bb.c` 文件。不为字段生成 getter/setter 方法。
- `c_minimal_single`:C 语言,为所有 `.bb` 文件输出一个包含所有定义的文件。输出文件名(包括扩展名)由 `-o` 选项确定。不为字段生成 getter/setter 方法。
- `python`:Python 语言,为每个 `.bb` 文件输出一个 `_bb.py` 文件。
- `python-single`:Python 语言,为所有 `.bb` 文件输出一个包含所有定义的文件。输出文件名(包括扩展名)由 `-o` 选项确定。

## 协议语法
Expand Down
6 changes: 4 additions & 2 deletions definition/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ func (p Package) Difference(other *Package) (diff []string) {
// ToPath returns the path of this package
//
// sep must be a valid path separator (e.g. "/", ".")
func (p Package) ToPath(sep string) string {
return strings.Join(p.PackageFullPaths, sep)
//
// ext must start with a dot (e.g. ".h", ".c", ".py")
func (p Package) ToPath(sep, ext string) string {
return strings.Join(p.PackageFullPaths, sep) + ext
}

// ToFilePath returns the file path of this package
Expand Down
4 changes: 4 additions & 0 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/xaxys/bubbler/generator/target/c_minimal_single"
"github.com/xaxys/bubbler/generator/target/c_single"
"github.com/xaxys/bubbler/generator/target/dump"
"github.com/xaxys/bubbler/generator/target/python"
"github.com/xaxys/bubbler/generator/target/python_single"
"github.com/xaxys/bubbler/util"
)
Expand All @@ -23,6 +24,7 @@ func init() {
c_singleGen := c_single.NewCSingleGenerator()
c_minimalGen := c_minimal.NewCMinimalGenerator()
c_minimal_singleGen := c_minimal_single.NewCMinimalSingleGenerator()
pythonGen := python.NewPythonGenerator()
python_singleGen := python_single.NewPythonSingleGenerator()

TargetMap = util.NewOrderedMap[string, Generator]()
Expand All @@ -38,6 +40,8 @@ func init() {
TargetMap.Put("c-minimal-single", c_minimal_singleGen)
TargetMap.Put("c_min_single", c_minimal_singleGen)
TargetMap.Put("c-min-single", c_minimal_singleGen)
TargetMap.Put("python", pythonGen)
TargetMap.Put("py", pythonGen)
TargetMap.Put("python-single", python_singleGen)
TargetMap.Put("python_single", python_singleGen)
TargetMap.Put("py-single", python_singleGen)
Expand Down
Loading

0 comments on commit c7af254

Please sign in to comment.