-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- New declaration element. - Refactoring existing code base to use explicit declaration calls.
- Loading branch information
Showing
20 changed files
with
654 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
cfile | ||
===== | ||
|
||
C code generator for python. | ||
C code generator for python. | ||
|
||
TBD. |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import cfile | ||
|
||
C = cfile.CFactory() | ||
|
||
code = C.sequence() | ||
mystruct = C.struct("mystruct", | ||
members=[C.struct_member("field_1", "int"), | ||
C.struct_member("field_2", "int")]) | ||
code.append(C.statement(mystruct)) # Forward declaration | ||
code.append(C.blank()) | ||
code.append(C.statement(C.declaration(mystruct))) # Struct declaration | ||
writer = cfile.Writer(cfile.StyleOptions()) | ||
print(writer.write_str(code)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
Typedef of a struct then declare a variable of that struct with initializer. | ||
Style: | ||
- new-line after opening brace | ||
""" | ||
import cfile | ||
|
||
C = cfile.CFactory() | ||
code = C.sequence() | ||
struct = C.struct("mystruct", | ||
members=[C.struct_member("field_1", "int"), | ||
C.struct_member("field_2", "int")]) | ||
struct_type = C.typedef("my_struct_t", C.declaration(struct)) | ||
code.append(C.statement(C.declaration(struct_type))) | ||
code.append(C.blank()) | ||
code.append(C.statement(C.declaration(C.variable("instance", struct_type), [0, 0]))) | ||
|
||
writer = cfile.Writer(cfile.StyleOptions(break_before_braces=cfile.BreakBeforeBraces.ATTACH)) | ||
print(writer.write_str(code)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
""" | ||
Example header file with some type declaration and formatting style | ||
- new-line after opening brace | ||
- pointer aligns to the right | ||
""" | ||
import cfile | ||
|
||
C = cfile.CFactory() | ||
|
||
INCLUDE_GUARD_TEXT = "INCLUDE_GUARD_H" | ||
|
||
code = C.sequence() | ||
code.append(C.ifndef(INCLUDE_GUARD_TEXT)) | ||
code.append(C.define(INCLUDE_GUARD_TEXT)) | ||
code.append(C.blank()) | ||
code.append(C.ifndef("__cplusplus")) | ||
code.append(C.line(C.extern("C"))) | ||
code.append(C.line("{")) | ||
code.append(C.endif(adjust=1)) | ||
code.append(C.blank()) | ||
code.append(C.sysinclude("stdint.h")) | ||
code.append(C.blank()) | ||
os_task_tag = C.struct("os_task_tag") | ||
code.append([C.statement(os_task_tag), C.line_comment("Forward declaration")]) | ||
code.append(C.blank()) | ||
struct = C.struct("os_alarm_cfg_tag", | ||
members=[C.struct_member("taskPtr", os_task_tag, pointer=True), | ||
C.struct_member("eventMask", "uint32_t"), | ||
C.struct_member("initDelayMs", "uint32_t"), | ||
C.struct_member("periodMs", "uint32_t")]) | ||
code.append(C.statement(C.declaration(C.typedef("os_alarm_cfg_t", C.declaration(struct))))) | ||
code.append(C.blank()) | ||
code.append(C.ifndef("__cplusplus")) | ||
code.append(C.line("}")) | ||
code.append([C.endif(), C.line_comment(" __cplusplus")]) | ||
code.append([C.endif(), C.line_comment(" " + INCLUDE_GUARD_TEXT)]) | ||
style = cfile.StyleOptions(break_before_braces=cfile.BreakBeforeBraces.ATTACH, | ||
pointer_alignment=cfile.Alignment.RIGHT) | ||
writer = cfile.Writer(style) | ||
print(writer.write_str(code)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import cfile | ||
|
||
C = cfile.CFactory() | ||
|
||
code = C.sequence() | ||
mystruct = C.struct("mystruct", | ||
members=[C.struct_member("field_1", "int"), | ||
C.struct_member("field_2", "int")]) | ||
code.append(C.statement(C.declaration(C.typedef("mystruct_t", C.declaration(mystruct))))) | ||
writer = cfile.Writer(cfile.StyleOptions(break_before_braces=cfile.BreakBeforeBraces.ATTACH)) | ||
print(writer.write_str(code)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
""" | ||
Variable declarations and access | ||
""" | ||
import cfile | ||
|
||
C = cfile.CFactory() | ||
code = C.sequence() | ||
var1 = C.variable("var1", "int") | ||
var2 = C.variable("var2", "int") | ||
code.append(C.statement(C.declaration(var1))) # int var1; | ||
code.append(C.statement(C.declaration(var2, 0))) # int var2 = 0; | ||
code.append(C.statement(var1)) # var1; | ||
code.append(C.statement(C.assignment(var1, 0))) # var1 = 0; | ||
writer = cfile.Writer(cfile.StyleOptions()) | ||
print(writer.write_str(code)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.