Skip to content

Commit

Permalink
wip update
Browse files Browse the repository at this point in the history
  • Loading branch information
gentijo committed May 20, 2023
1 parent 3b459e3 commit 0ed20cb
Show file tree
Hide file tree
Showing 28 changed files with 1,622 additions and 125 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,4 @@ $RECYCLE.BIN/

build/**
archive/**
msgs/**
32 changes: 32 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/uros-rtidl",
"args": [
"-baseType",
"Twist",
"-typeDir",
"${workspaceFolder}/test/msg",
"-outDir",
"${workspaceFolder}/test/output",
"-pyTemplate",
"./test/pythonTypeTemplate.j2"

],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"MIMode": "gdb",
"externalConsole": false,
"setupCommands": [
]
}
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files.associations": {
"parser.h": "c",
"datatypecatalog.h": "c",
"string": "cpp"
}
}
26 changes: 20 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
cmake_minimum_required(VERSION 3.21)

project(uros-rtidl VERSION 1.0 LANGUAGES C)
cmake_minimum_required(VERSION 3.5)
set(CMAKE_BUILD_TYPE Debug)

project(uros-rtidl VERSION 1.0 LANGUAGES C CXX)

set(SRC_DIR "src")

set(PARSER_DIR "${CMAKE_CURRENT_BINARY_DIR}")

find_package(FLEX 2.6 REQUIRED)
Expand All @@ -11,9 +14,20 @@ find_package(BISON 3.0 REQUIRED)
set(LEXER_OUT "${PARSER_DIR}/lexer.c")
set(PARSER_OUT "${PARSER_DIR}/parser.c")

flex_target(LEXER "${SRC_DIR}/lexer.l" "${LEXER_OUT}" COMPILE_FLAGS "--debug --verbose" DEFINES_FILE "${PARSER_DIR}/lexer.h" )
bison_target(PARSER "${SRC_DIR}/parser.y" "${PARSER_OUT}" COMPILE_FLAGS "--debug --verbose -Dparse.trace " DEFINES_FILE "${PARSER_DIR}/parser.h")
#flex_target(LEXER "${SRC_DIR}/lexer.l" "${LEXER_OUT}" COMPILE_FLAGS "--debug --verbose" DEFINES_FILE "${PARSER_DIR}/lexer.h" )
#bison_target(PARSER "${SRC_DIR}/parser.y" "${PARSER_OUT}" COMPILE_FLAGS "-d --debug --verbose -Dparse.trace " DEFINES_FILE "${PARSER_DIR}/parser.h" )
flex_target(LEXER "${SRC_DIR}/lexer.l" "${LEXER_OUT}" COMPILE_FLAGS "" DEFINES_FILE "${PARSER_DIR}/lexer.h" )
bison_target(PARSER "${SRC_DIR}/parser.y" "${PARSER_OUT}" COMPILE_FLAGS "" DEFINES_FILE "${PARSER_DIR}/parser.h" )
add_flex_bison_dependency(LEXER PARSER)

add_executable(uros-rtidl "${SRC_DIR}/main.c" "${LEXER_OUT}" "${PARSER_OUT}")
target_include_directories(uros-rtidl PRIVATE "${PARSER_DIR}")
add_executable(uros-rtidl
"${SRC_DIR}/main.cpp"
"${SRC_DIR}/DataTypeCatalog.cpp"
"${SRC_DIR}/DataTypeFunc.cpp"
"${SRC_DIR}/TypeParser.c"
"${SRC_DIR}/Jinja2CppLight.cpp"
"${SRC_DIR}/stringhelper.cpp"
"${LEXER_OUT}"
"${PARSER_OUT}")

target_include_directories(uros-rtidl PRIVATE "${PARSER_DIR}" "src")
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:22.04

RUN apt -y update && \
apt -y upgrade && \
apt -y install \
build-essential \
antlr \
python3 pip \
bison flex \
emacs nano \
cmake git \
gdb gdbserver && \
pip3 install ampy rshell
1 change: 1 addition & 0 deletions buildNode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -t mros-rtidl-img .
22 changes: 22 additions & 0 deletions src/CustomTemplate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#include "CustomTemplate.h"

std::string DataTypeValue::render() {

std::string name = "dataTypeMode";
std::shared_ptr<Jinja2CppLight::Value> mode = this->tpl->valueByName[name];
std::string val;
if (mode) val = mode->render();
return val;
};

bool DataTypeValue::isTrue() const {
return true; //!values.empty();
};

DataTypeTemplate &DataTypeTemplate::setValue( std::string name, DataTypeValue value ) {

valueByName[ name ] = std::make_shared<DataTypeValue>( std::move(value) );
std::shared_ptr<Jinja2CppLight::Value> value = valueByName["dataTypeMode"];
return *this;
} ;
28 changes: 28 additions & 0 deletions src/CustomTemplate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

#ifndef __CUSTOM_TEMPLATE_H__
#define __CUSTOM_TEMPLATE_H__

#include "Jinja2CppLight.h"
#include "DataTypeCatalog.h"

class DataTypeTemplate;

class DataTypeValue : public Jinja2CppLight::Value {
public:
DataTypeDefinition *data;
DataTypeTemplate *tpl;

DataTypeValue( DataTypeDefinition* _data ) {
this->data = _data;
}

virtual std::string render();
bool isTrue() const;
};

class DataTypeTemplate : public Jinja2CppLight::Template {

DataTypeTemplate &setValue( std::string name, DataTypeValue value );
};

#endif
52 changes: 52 additions & 0 deletions src/DataTypeCatalog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef __DATATYPE_CATALOG_H__
#define __DATATYPE_CATALOG_H__

#include <iostream>
#include <list>

#include "DataTypeCatalog.h"

DataTypeCatalog g_DataTypeCatalog;

void DataTypeDefinition::addField(sIdent *left, sIdent *right) {
DataField field;

field.typeName = left->name;

if (left->name_prefix != 0x00) {
field.typePrefix = left->name_prefix;
}

field.valueName = right->name;
field.valueType = left->type;
this->fields.push_back(field);
}

void DataTypeDefinition::print() {
std::cout << "\r\nType Name: [" << typeName << "] Type Prefix: [" << typePrefix << "]\r\n Fields:\r\n";
for (DataField field : fields) {
std::cout << " Name: [" << field.typeName << "] Prefix: [" << field.typePrefix << "] Value Name: [" << field.valueName << "] Value Type: [" << field.valueType << "]\r\n";
}
}

void DataTypeCatalog::addDataTypeDefinition(DataTypeDefinition* type){
m_TypeMap[type->getTypeName()] = type;
m_currentDataType = type;
}


DataTypeDefinition* DataTypeCatalog::getDataType(std::string name) {
if (m_TypeMap.count(name)) return m_TypeMap[name];
else return NULL;
}

void DataTypeCatalog::print() {

std::cout << "\r\n\r\nData Type Catalog\r\n";
for (auto entry : m_TypeMap) {
DataTypeDefinition* def = entry.second;
def->print();
}
}

#endif
65 changes: 65 additions & 0 deletions src/DataTypeCatalog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#ifndef __DATACATALOG_H__
#define __DATACATALOG_H__

#include "types.h"

#include "lexer.h"
#include "parser.h"
#include <ctype.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

#include <string>
#include <map>
#include <list>

struct DataField {
std::string typeName;
std::string typePrefix;
std::string valueName;
int valueType;
};

typedef struct DataField DataField;

class DataTypeDefinition {

public:
DataTypeDefinition(std::string typeName, std::string typePrefix) {
this->typeName = typeName;
this->typePrefix = typePrefix;
};

void addField(sIdent *left, sIdent *right);
const std::string getTypeName() { return typeName; }
const std::string getTypePrefix() { return typePrefix; }
std::list<DataField> getFields() { return fields; }
void print();

private:
std::string typeName;
std::string typePrefix;
std::list<DataField> fields;
};


class DataTypeCatalog {

public:
void addDataTypeDefinition(DataTypeDefinition* type);
DataTypeDefinition* getActiveDataType() { return m_currentDataType;}
DataTypeDefinition* getDataType(std::string name);
std::map<std::string, DataTypeDefinition*> getDataTypeCatalog() {return m_TypeMap;}
void print();

private:
std::map<std::string, DataTypeDefinition*> m_TypeMap;
DataTypeDefinition *m_currentDataType = NULL;


};

extern DataTypeCatalog g_DataTypeCatalog;

#endif
9 changes: 9 additions & 0 deletions src/DataTypeFunc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "DataTypeCatalog.h"
#include "DataTypeFunc.h"


extern "C" void addField(sIdent *left, sIdent *right) {
DataTypeDefinition* type = g_DataTypeCatalog.getActiveDataType();
if (type != NULL) type->addField(left, right);
}

17 changes: 17 additions & 0 deletions src/DataTypeFunc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef __DATA_TYPE_FUNC_H__
#define __DATA_TYPE_FUNC_H__
#include "types.h"


#ifdef __cplusplus
extern "C"
{
#endif

void addField(sIdent* left, sIdent* right);

#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit 0ed20cb

Please sign in to comment.