This module contains the code generation components for the Tau Interface Definition Language (IDL). It transforms Tau AST (Abstract Syntax Tree) into C++ code for distributed networking.
The Tau code generation system uses a clean, separated architecture:
- GenerateProcess - Base class providing common functionality for all generators
- AST traversal and transformation
- Code formatting utilities (StartBlock, EndBlock, etc.)
- Common parsing and error handling
-
GenerateProxy - Generates client-side proxy classes
- Methods that forward calls over the network
- Event registration/unregistration handlers
- Serialization of parameters using BinaryStreams
- Future-based return value handling
-
GenerateAgent - Generates server-side agent classes
- Handler methods for incoming network requests
- Deserialization of parameters from BinaryStreams
- Implementation method invocation
- Response serialization for non-void methods
-
GenerateStruct - Generates plain C++ struct definitions
- Simple data structures for DTOs (Data Transfer Objects)
- Preserves field ordering and types
- Supports nested structures
- Can include method declarations
- Separation of Concerns: Each generator has a single responsibility
- Type Safety: Generated code maintains full C++ type safety
- Network Transparency: Proxies look and feel like local objects
- Clean Inheritance: All generators properly inherit from GenerateProcess
The generation process happens in several stages:
- Parse Tau source code into an AST
- Process the AST to extract interfaces, methods, events, and types
- Generate code based on the extracted information
- Write the generated code to output files
This is handled by the NetworkGenerate application, which provides a command-line interface to the generator.
For a Tau interface:
namespace ChatApp {
interface IChatService {
void SendMessage(string user, string message);
string[] GetRecentMessages(int count = 10);
event MessageReceived(string user, string message, string timestamp);
}
}
The generator will produce:
-
A proxy class
ChatApp::IChatServiceProxywith:void SendMessage(string user, string message)methodstring[] GetRecentMessages(int count = 10)methodRegisterMessageReceivedHandler(std::function<void(string, string, string)>)method
-
An agent class
ChatApp::IChatServiceAgentwith:SendMessageandGetRecentMessageshandler implementationsTriggerMessageReceivedmethod to raise the event
- Support for C++17 nested namespace syntax (
namespace A::B::C) - Improved event handling with callback registration
- Enhanced error reporting during code generation
- Better support for complex type hierarchies and inheritance
For practical examples, see: