!649 add missed '-o' option and reformat hc-gen code

Merge pull request !649 from yuanbo/master
This commit is contained in:
openharmony_ci
2022-02-18 03:42:31 +00:00
committed by Gitee
26 changed files with 266 additions and 281 deletions
+25 -36
View File
@@ -6,16 +6,17 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include <iomanip>
#include <sstream>
#include <set>
#include "ast.h"
#include <iomanip>
#include <set>
#include <sstream>
#include "logger.h"
using namespace OHOS::Hardware;
AstObject::AstObject(AstObject &obj) :
AstObject(obj.name_, obj.type_, obj.stringValue_)
AstObject::AstObject(AstObject &obj) : AstObject(obj.name_, obj.type_, obj.stringValue_)
{
integerValue_ = obj.integerValue_;
}
@@ -150,19 +151,19 @@ std::ostream &OHOS::Hardware::operator<<(std::ostream &stream, const AstObject &
}
switch (t.type_) {
case PARSEROP_UINT8:
stream << "uint8 " << "0x" << std::hex << t.integerValue_;
stream << "uint8 0x" << std::hex << t.integerValue_;
break;
case PARSEROP_UINT16:
stream << "uint16 " << "0x" << std::hex << t.integerValue_;
stream << "uint16 0x" << std::hex << t.integerValue_;
break;
case PARSEROP_UINT32:
stream << "uint32 " << "0x" << std::hex << t.integerValue_;
stream << "uint32 0x" << std::hex << t.integerValue_;
break;
case PARSEROP_UINT64:
stream << "uint64 " << "0x" << std::hex << t.integerValue_;
stream << "uint64 0x" << std::hex << t.integerValue_;
break;
case PARSEROP_STRING:
stream << "string " << "\"" << t.stringValue_ << "\"";
stream << "string \"" << t.stringValue_ << "\"";
break;
case PARSEROP_ARRAY:
stream << "array";
@@ -254,7 +255,7 @@ std::shared_ptr<AstObject> AstObject::Lookup(const std::string &name, uint32_t t
bool AstObject::IsNumber() const
{
return type_ >= PARSEROP_UINT8 && type_ <= PARSEROP_UINT64;;
return type_ >= PARSEROP_UINT8 && type_ <= PARSEROP_UINT64;
}
bool AstObject::IsNode() const
@@ -409,7 +410,6 @@ ConfigNode::ConfigNode(std::string name, uint32_t nodeType, std::string refName)
inheritCount_(0),
templateSignNum_(0)
{
}
ConfigNode::ConfigNode(Token &name, uint32_t nodeType, std::string refName) :
@@ -425,12 +425,12 @@ ConfigNode::ConfigNode(Token &name, uint32_t nodeType, std::string refName) :
const std::string &ConfigNode::NodeTypeToStr(uint32_t type)
{
static std::map<uint32_t, std::string> type2StringMap = {
{NODE_NOREF, ""},
{NODE_COPY, "NodeCopy"},
{NODE_REF, "NodeReference"},
{NODE_DELETE, "NodeDelete"},
{NODE_INHERIT, "NodeInherit"},
{NODE_TEMPLATE, "NodeTemplate"},
{NODE_NOREF, "" },
{ NODE_COPY, "NodeCopy" },
{ NODE_REF, "NodeReference"},
{ NODE_DELETE, "NodeDelete" },
{ NODE_INHERIT, "NodeInherit" },
{ NODE_TEMPLATE, "NodeTemplate" },
};
return type2StringMap[type];
}
@@ -592,7 +592,7 @@ bool ConfigNode::NodeRefExpand(const std::shared_ptr<AstObject> &ref)
Logger().Error() << SourceInfo() << "reference node '" << refNodePath_ << "' not exist";
return false;
}
return ref->Move(std::shared_ptr<AstObject>(this, [](AstObject *p) { (void) p; }));
return ref->Move(std::shared_ptr<AstObject>(this, [](AstObject *p) { (void)p; }));
}
bool ConfigNode::NodeCopyExpand(const std::shared_ptr<AstObject> &ref)
@@ -654,8 +654,7 @@ ConfigTerm::ConfigTerm(ConfigTerm &term) : ConfigTerm(term.name_, nullptr)
}
ConfigTerm::ConfigTerm(std::string name, const std::shared_ptr<AstObject> &value) :
AstObject(std::move(name), PARSEROP_CONFTERM, 0),
signNum_(0)
AstObject(std::move(name), PARSEROP_CONFTERM, 0), signNum_(0)
{
if (value != nullptr) {
child_ = value;
@@ -664,8 +663,7 @@ ConfigTerm::ConfigTerm(std::string name, const std::shared_ptr<AstObject> &value
}
ConfigTerm::ConfigTerm(Token &name, const std::shared_ptr<AstObject> &value) :
AstObject(name.strval, PARSEROP_CONFTERM, 0, name),
signNum_(0)
AstObject(name.strval, PARSEROP_CONFTERM, 0, name), signNum_(0)
{
if (value != nullptr) {
child_ = value;
@@ -709,8 +707,7 @@ bool ConfigTerm::RefExpand(std::shared_ptr<AstObject> refObj)
return true;
}
if (refObj == nullptr || !refObj->IsNode() ||
ConfigNode::CastFrom(refObj)->GetNodeType() == NODE_REF ||
if (refObj == nullptr || !refObj->IsNode() || ConfigNode::CastFrom(refObj)->GetNodeType() == NODE_REF ||
ConfigNode::CastFrom(refObj)->GetNodeType() == NODE_TEMPLATE ||
ConfigNode::CastFrom(refObj)->GetNodeType() == NODE_DELETE) {
Logger().Error() << SourceInfo() << "reference invalid node '" << child_->StringValue() << '\'';
@@ -753,10 +750,7 @@ uint32_t ConfigTerm::SigNum()
return signNum_;
}
ConfigArray::ConfigArray() :
AstObject("", PARSEROP_ARRAY, 0),
arrayType_(0),
arraySize_(0)
ConfigArray::ConfigArray() : AstObject("", PARSEROP_ARRAY, 0), arrayType_(0), arraySize_(0)
{
}
@@ -772,11 +766,7 @@ ConfigArray::ConfigArray(ConfigArray &array) : ConfigArray()
}
ConfigArray::ConfigArray(const Token &bindToken) :
AstObject("", PARSEROP_ARRAY, 0, bindToken),
arrayType_(0),
arraySize_(0)
{
};
AstObject("", PARSEROP_ARRAY, 0, bindToken), arrayType_(0), arraySize_(0) {};
bool ConfigArray::AddChild(const std::shared_ptr<AstObject> &childObj)
{
@@ -908,7 +898,7 @@ bool Ast::Expand()
bool Ast::NodeExpand()
{
return WalkBackward([this](const std::shared_ptr<AstObject> &current, int32_t walkDepth) -> int32_t {
(void) walkDepth;
(void)walkDepth;
if (current->IsNode()) {
auto node = ConfigNode::CastFrom(current);
if (node->GetNodeType() == NODE_DELETE) {
@@ -958,7 +948,6 @@ bool Ast::InheritExpand()
});
}
bool Ast::RedefineCheck()
{
if (redefineChecked_) {
+14 -14
View File
@@ -10,11 +10,12 @@
#define HC_GEN_AST_H
#include <cstdint>
#include <string>
#include <memory>
#include <list>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "token.h"
#include "types.h"
@@ -283,7 +284,7 @@ public:
std::shared_ptr<AstObject> Lookup(const std::shared_ptr<AstObject> &startObj, const std::string &path);
template<typename T>
template <typename T>
static bool WalkForward(const std::shared_ptr<AstObject> &startObject, T callback)
{
std::shared_ptr<AstObject> forwardWalkObj = startObject;
@@ -319,7 +320,7 @@ public:
return true;
}
template<typename T>
template <typename T>
static bool WalkBackward(const std::shared_ptr<AstObject> &startObject, T callback)
{
std::shared_ptr<AstObject> backWalkObj = startObject;
@@ -360,7 +361,7 @@ public:
return true;
}
template<typename T1, typename T2>
template <typename T1, typename T2>
static bool WalkRound(const std::shared_ptr<AstObject> &startObject, T1 forwardCallback, T2 backwardCallback)
{
std::shared_ptr<AstObject> roundWalkObj = startObject;
@@ -400,20 +401,19 @@ public:
return true;
}
template<typename T>
template <typename T>
bool WalkForward(T callback)
{
return WalkForward(astRoot_, callback);
}
template<typename T>
template <typename T>
bool WalkBackward(T callback)
{
return WalkBackward(astRoot_, callback);
}
template<typename T1, typename T2>
template <typename T1, typename T2>
bool WalkRound(T1 forwardCallback, T2 backwardCallback)
{
return WalkRound(astRoot_, forwardCallback, backwardCallback);
@@ -434,11 +434,11 @@ private:
bool redefineChecked_;
};
std::ostream& operator<<(std::ostream &s, const AstObject &obj);
std::ostream& operator<<(std::ostream &s, const ConfigNode &obj);
std::ostream& operator<<(std::ostream &s, const ConfigTerm &obj);
std::ostream &operator<<(std::ostream &s, const AstObject &obj);
std::ostream &operator<<(std::ostream &s, const ConfigNode &obj);
std::ostream &operator<<(std::ostream &s, const ConfigTerm &obj);
} // Hardware
} // OHOS
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_AST_H
+21 -21
View File
@@ -7,15 +7,15 @@
*/
#include "bytecode_gen.h"
#include <string>
#include "file.h"
#include "logger.h"
#include "opcode.h"
#include <string>
using namespace OHOS::Hardware;
ByteCodeGen::ByteCodeGen(std::shared_ptr<Ast> ast) : Generator(ast),
needAlign_(false), dummyOutput_(false), writeSize_(0)
ByteCodeGen::ByteCodeGen(std::shared_ptr<Ast> ast) :
Generator(ast), needAlign_(false), dummyOutput_(false), writeSize_(0)
{
}
@@ -94,14 +94,14 @@ uint32_t ByteCodeGen::Align(uint32_t size) const
const OpCode &ByteCodeGen::ToOpCode(uint32_t objectType)
{
static std::map<uint32_t, OpCode> byteCodeMap = {
{PARSEROP_UINT8, {HCS_BYTE_OP, BYTE_SIZE, "Uint8"}},
{PARSEROP_UINT16, {HCS_WORD_OP, WORD_SIZE, "Uint16"}},
{PARSEROP_UINT32, {HCS_DWORD_OP, DWORD_SIZE, "Uint32"}},
{PARSEROP_UINT64, {HCS_QWORD_OP, QWORD_SIZE, "Uint64"}},
{PARSEROP_STRING, {HCS_STRING_OP, 0, "String"}},
{PARSEROP_ARRAY, {HCS_ARRAY_OP, WORD_SIZE, "Array"}}, /* ElementCount - WORD */
{PARSEROP_CONFNODE, {HCS_NODE_OP, DWORD_SIZE, "ConfigNode"}}, /* SubSize - DWORD */
{PARSEROP_CONFTERM, {HCS_TERM_OP, 0, "ConfigTerm"}},
{PARSEROP_UINT8, {HCS_BYTE_OP, BYTE_SIZE, "Uint8"} },
{PARSEROP_UINT16, {HCS_WORD_OP, WORD_SIZE, "Uint16"} },
{PARSEROP_UINT32, {HCS_DWORD_OP, DWORD_SIZE, "Uint32"} },
{PARSEROP_UINT64, {HCS_QWORD_OP, QWORD_SIZE, "Uint64"} },
{PARSEROP_STRING, {HCS_STRING_OP, 0, "String"} },
{PARSEROP_ARRAY, {HCS_ARRAY_OP, WORD_SIZE, "Array"} }, /* ElementCount - WORD */
{PARSEROP_CONFNODE, {HCS_NODE_OP, DWORD_SIZE, "ConfigNode"}}, /* SubSize - DWORD */
{PARSEROP_CONFTERM, {HCS_TERM_OP, 0, "ConfigTerm"} },
{PARSEROP_NODEREF, {HCS_NODEREF_OP, DWORD_SIZE, "NodeRef"}}, /* RefHashCode - DWORD */
};
return byteCodeMap[objectType];
@@ -112,7 +112,7 @@ void ByteCodeGen::Write(const std::string &data)
Write(data.c_str(), static_cast<uint32_t>(data.size() + 1));
}
template<typename T>
template <typename T>
void ByteCodeGen::Write(T &data)
{
auto p = &data;
@@ -172,8 +172,8 @@ bool ByteCodeGen::ByteCodeWrite(bool dummy)
.versionMajor = 0,
.versionMinor = 0,
.checkSum = 0,
.totalSize = static_cast<int32_t>(Option::Instance().ShouldAlign() ? -ast_->GetAstRoot()->GetSize()
: ast_->GetAstRoot()->GetSize()),
.totalSize = static_cast<int32_t>(
Option::Instance().ShouldAlign() ? -ast_->GetAstRoot()->GetSize() : ast_->GetAstRoot()->GetSize()),
};
Option::Instance().GetVersion(header.versionMinor, header.versionMajor);
Write(header);
@@ -299,7 +299,7 @@ bool ByteCodeGen::HexdumpOutput(FILE *in, FILE *out)
int32_t byte;
while ((byte = getc(in)) != EOF) {
if (fprintf(out, "%s0x%02x", (writeCount % NUMS_PER_LINE) ? ", " : &",\n "[PRINT_SKIP_STEP * !writeCount],
byte) < 0) {
byte) < 0) {
return false;
}
writeCount++;
@@ -312,12 +312,12 @@ bool ByteCodeGen::HexdumpOutput(FILE *in, FILE *out)
return false;
}
if (fprintf(out,
"void HdfGetBuildInConfigData(const unsigned char** data, unsigned int* size)\n"
"{\n"
" *data = g_%s%s;\n"
" *size = g_%s%sLen;\n"
"}",
prefix.data(), HCS_HEXDUMP_ENTRY_SYMBOL, prefix.data(), HCS_HEXDUMP_ENTRY_SYMBOL) < 0) {
"void HdfGetBuildInConfigData(const unsigned char** data, unsigned int* size)\n"
"{\n"
" *data = g_%s%s;\n"
" *size = g_%s%sLen;\n"
"}",
prefix.data(), HCS_HEXDUMP_ENTRY_SYMBOL, prefix.data(), HCS_HEXDUMP_ENTRY_SYMBOL) < 0) {
return false;
}
return true;
+6 -10
View File
@@ -6,24 +6,20 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HC_GEN_BYTECODE_GEN_H
#define HC_GEN_BYTECODE_GEN_H
#include "generator.h"
#include <fstream>
#include <utility>
#include "generator.h"
namespace OHOS {
namespace Hardware {
struct OpCode {
OpCode() : opCode(0),
size(0) {}
OpCode() : opCode(0), size(0) {}
OpCode(uint8_t code, uint32_t s, std::string str) : opCode(code),
size(s),
opStr(std::move(str)) {}
OpCode(uint8_t code, uint32_t s, std::string str) : opCode(code), size(s), opStr(std::move(str)) {}
~OpCode() = default;
@@ -53,7 +49,7 @@ private:
bool ByteCodeWriteWalk();
template<typename T>
template <typename T>
void Write(T &data);
void Write(const char *data, uint32_t size);
@@ -78,6 +74,6 @@ private:
bool dummyOutput_;
uint32_t writeSize_;
};
} // Hardware
} // OHOS
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_BYTECODE_GEN_H
+16 -17
View File
@@ -7,21 +7,19 @@
*/
#include "decompile.h"
#include <cctype>
#include "decompile_gen.h"
#include "logger.h"
#include "opcode.h"
#include <cctype>
using namespace OHOS::Hardware;
Decompile::Decompile(std::string fileName) : isAlign_(false), fileName_(std::move(fileName))
{
}
Decompile::Decompile(std::string fileName) : isAlign_(false), fileName_(std::move(fileName)) {}
bool Decompile::InitDecompileFile()
{
file_.open(fileName_.data(), std::ios::binary);
if(!file_.is_open()) {
if (!file_.is_open()) {
Logger().Error() << "Failed to open decompile file: " << fileName_;
return false;
}
@@ -30,7 +28,7 @@ bool Decompile::InitDecompileFile()
bool Decompile::ReadFile(char *buffer, size_t readSize)
{
if(!file_.read(buffer, static_cast<std::streamsize>(readSize))) {
if (!file_.read(buffer, static_cast<std::streamsize>(readSize))) {
Logger().Error() << "read file failed, read size is: " << readSize;
return false;
}
@@ -44,15 +42,16 @@ void Decompile::SetAlign(bool isAlign)
bool Decompile::VerifyDecompileFile()
{
HcbHeader header{0};
HcbHeader header {0};
if (!ReadFile(reinterpret_cast<char *>(&header), sizeof(header))) {
Logger().Error() << "read header failed";
return false;
}
Logger().Debug() << "read Header: magic is: " << header.magicNumber << " version major: " << header.versionMajor <<
" version minor: " << header.versionMinor << " checksum: " << header.checkSum << " totalSize: " << header.totalSize;
Logger().Debug() << "read Header: magic is: " << header.magicNumber << " version major: " << header.versionMajor
<< " version minor: " << header.versionMinor << " checksum: " << header.checkSum
<< " totalSize: " << header.totalSize;
if (header.magicNumber != HCB_MAGIC_NUM) {
Logger().Error() << "magic number is: " << header.magicNumber << ", check failed!";
Logger().Error() << "magic number is: " << header.magicNumber << ", check failed!";
return false;
}
if (header.totalSize < 0) {
@@ -102,7 +101,7 @@ bool Decompile::ReadString(std::string &value)
{
value.clear();
char c;
while(ReadFile(&c, sizeof(c))) {
while (ReadFile(&c, sizeof(c))) {
if (c == '\0') {
break;
}
@@ -124,10 +123,10 @@ bool Decompile::ReadString(std::string &value)
bool Decompile::GetNextByteCode(uint32_t &byteCode)
{
if (GetAlignSize(OPCODE_BYTE_WIDTH) == OPCODE_BYTE_WIDTH) {
uint8_t value = 0;
bool ret = ReadUint8(value);
byteCode = value;
return ret;
uint8_t value = 0;
bool ret = ReadUint8(value);
byteCode = value;
return ret;
} else {
return ReadUint32(byteCode);
}
@@ -143,7 +142,7 @@ std::shared_ptr<AstObject> Decompile::RebuildNode()
auto node = std::make_shared<ConfigNode>(nodeName, NODE_NOREF, "");
uint32_t nodeSize = 0;
if(!ReadUint32(nodeSize)) {
if (!ReadUint32(nodeSize)) {
return nullptr;
}
node->SetSize(nodeSize);
@@ -309,7 +308,7 @@ std::shared_ptr<Ast> Decompile::RebuildAst()
bool Decompile::DoDecompile()
{
if(!InitDecompileFile()) {
if (!InitDecompileFile()) {
return false;
}
+3 -2
View File
@@ -11,6 +11,7 @@
#include <fstream>
#include <string>
#include "ast.h"
namespace OHOS {
@@ -74,6 +75,6 @@ private:
std::ifstream file_;
};
} // OHOS
} // Hardware
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_DECOMPILE_H
+11 -11
View File
@@ -7,9 +7,9 @@
*/
#include "decompile_gen.h"
#include <sstream>
#include "file.h"
#include "logger.h"
#include <sstream>
using namespace OHOS::Hardware;
@@ -68,7 +68,7 @@ std::string DecompileGen::GetNodeRefPath(uint32_t value)
return std::string();
}
int32_t DecompileGen::PrintArrayType(const std::shared_ptr<AstObject>& astObj)
int32_t DecompileGen::PrintArrayType(const std::shared_ptr<AstObject> &astObj)
{
WriteFile("[");
auto arrayElement = astObj->Child();
@@ -88,7 +88,7 @@ int32_t DecompileGen::PrintArrayType(const std::shared_ptr<AstObject>& astObj)
return NOERR;
}
int32_t DecompileGen::PrintBaseType(const std::shared_ptr<AstObject>& astObj)
int32_t DecompileGen::PrintBaseType(const std::shared_ptr<AstObject> &astObj)
{
std::stringstream outStr;
std::string refPath;
@@ -120,7 +120,7 @@ int32_t DecompileGen::PrintBaseType(const std::shared_ptr<AstObject>& astObj)
return NOERR;
}
int32_t DecompileGen::OutPutWalk(const std::shared_ptr<AstObject>& astObj, int32_t walkDepth)
int32_t DecompileGen::OutPutWalk(const std::shared_ptr<AstObject> &astObj, int32_t walkDepth)
{
if (astObj->Type() != PARSEROP_CONFNODE && astObj->Type() != PARSEROP_CONFTERM) {
return NOERR;
@@ -155,7 +155,7 @@ int32_t DecompileGen::OutPutWalk(const std::shared_ptr<AstObject>& astObj, int32
return 0;
}
int32_t DecompileGen::CloseBrace(const std::shared_ptr<AstObject>& astObj, int32_t walkDepth)
int32_t DecompileGen::CloseBrace(const std::shared_ptr<AstObject> &astObj, int32_t walkDepth)
{
if (astObj->Type() != PARSEROP_CONFNODE) {
return NOERR;
@@ -176,12 +176,12 @@ bool DecompileGen::OutPut()
}
WriteFile(fileHeader_);
if (!ast_->WalkRound(
[this](std::shared_ptr<AstObject> &current, int32_t walkDepth) -> int32_t {
return OutPutWalk(current, walkDepth);
},
[this](std::shared_ptr<AstObject> &current, int32_t walkDepth) -> int32_t {
return CloseBrace(current, walkDepth);
})) {
[this](std::shared_ptr<AstObject> &current, int32_t walkDepth) -> int32_t {
return OutPutWalk(current, walkDepth);
},
[this](std::shared_ptr<AstObject> &current, int32_t walkDepth) -> int32_t {
return CloseBrace(current, walkDepth);
})) {
return false;
}
+7 -6
View File
@@ -11,6 +11,7 @@
#include <fstream>
#include <string>
#include "ast.h"
namespace OHOS {
@@ -29,15 +30,15 @@ private:
void WriteFile(const std::string &str);
int32_t PrintBaseType(const std::shared_ptr<AstObject>& astObj);
int32_t PrintBaseType(const std::shared_ptr<AstObject> &astObj);
std::string GetNodeRefPath(uint32_t hash);
int32_t PrintArrayType(const std::shared_ptr<AstObject>& astObj);
int32_t PrintArrayType(const std::shared_ptr<AstObject> &astObj);
int32_t OutPutWalk(const std::shared_ptr<AstObject>& astObj, int32_t walkDepth);
int32_t OutPutWalk(const std::shared_ptr<AstObject> &astObj, int32_t walkDepth);
int32_t CloseBrace(const std::shared_ptr<AstObject>& astObj, int32_t walkDepth);
int32_t CloseBrace(const std::shared_ptr<AstObject> &astObj, int32_t walkDepth);
const std::string fileHeader_ = "/*\n * HDF decompile hcs file\n */\n\n";
std::string outPutFileName_;
@@ -45,6 +46,6 @@ private:
std::shared_ptr<Ast> ast_;
};
} // OHOS
} // Hardware
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_DECOMPILE_GEN_H
+4 -3
View File
@@ -6,15 +6,16 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include "file.h"
#include <climits>
#include <cstdlib>
#include <unistd.h>
#include "file.h"
#include "types.h"
using namespace OHOS::Hardware::Util;
std::string File::AbsPath(const std::string& path)
std::string File::AbsPath(const std::string &path)
{
char realPath[PATH_MAX];
#ifdef MINGW32
@@ -48,7 +49,7 @@ std::string File::GetDir(std::string path)
return path.substr(0, separatorPos + 1);
}
std::string File::FileNameBase(const std::string& path)
std::string File::FileNameBase(const std::string &path)
{
auto sepPos = path.rfind(OS_SEPARATOR);
auto dotPos = path.rfind('.');
+5 -5
View File
@@ -16,12 +16,12 @@ namespace Hardware {
namespace Util {
class File {
public:
static std::string AbsPath(const std::string& path);
static std::string AbsPath(const std::string &path);
static std::string StripSuffix(std::string path);
static std::string GetDir(std::string path);
static std::string FileNameBase(const std::string& path);
static std::string FileNameBase(const std::string &path);
};
} // Util
} //Hardware
} //OHOS
} // namespace Util
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_FILE_H
+3 -2
View File
@@ -11,6 +11,7 @@
#include <memory>
#include <string>
#include "ast.h"
namespace OHOS {
@@ -26,7 +27,7 @@ public:
protected:
std::shared_ptr<Ast> ast_;
};
} // Hardware
} // OHOS
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_GENERATOR_H
+11 -16
View File
@@ -6,21 +6,20 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include "lexer.h"
#include <sstream>
#include <string>
#include "lexer.h"
#include "logger.h"
using namespace OHOS::Hardware;
Lexer::Lexer() : lineno_(0), lineLoc_(0)
{
}
Lexer::Lexer() : lineno_(0), lineLoc_(0) {}
std::map<std::string, TokenType> Lexer::keyWords_ = {
{"#include", INCLUDE},
{"root", ROOT},
{"delete", DELETE},
{"#include", INCLUDE },
{"root", ROOT },
{"delete", DELETE },
{"template", TEMPLATE},
};
@@ -172,15 +171,14 @@ bool Lexer::FillBuffer()
bool Lexer::ProcessComment()
{
char c = 0;
ConsumeChar();// skip first '/'
ConsumeChar(); // skip first '/'
if (!GetChar(c)) {
Logger().Error() << *this << "unterminated comment";
return false;
}
if (c == '/') {
while (c != '\n' && GetChar(c)) {
}
while (c != '\n' && GetChar(c)) {}
if (c != '\n' && c != EOF) {
Logger().Error() << *this << "unterminated signal line comment";
return false;
@@ -277,8 +275,7 @@ bool Lexer::LexFromNumber(Token &token)
case 'x': // fall-through
case 'X': // hex number
ConsumeChar();
while (PeekChar(c, false) && (IsNum(c) || (c >= 'a' && c <= 'f')
|| (c >= 'A' && c <= 'F'))) {
while (PeekChar(c, false) && (IsNum(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
value.push_back(c);
ConsumeChar();
}
@@ -297,7 +294,7 @@ bool Lexer::LexFromNumber(Token &token)
break;
case '+': // fall-through
case '-': // fall-through, signed decimal number
default: // unsigned decimal number
default: // unsigned decimal number
value.push_back(c);
while (PeekChar(c, true) && IsNum(c)) {
ConsumeChar();
@@ -353,7 +350,6 @@ void Lexer::LexFromLiteral(Token &token)
}
} while (false);
token.strval = std::move(value);
token.lineNo = lineno_;
}
@@ -361,7 +357,7 @@ void Lexer::LexFromLiteral(Token &token)
void Lexer::ConsumeChar()
{
char c;
(void) GetChar(c, false);
(void)GetChar(c, false);
}
bool Lexer::IsNum(char c)
@@ -380,4 +376,3 @@ bool Lexer::LexInclude(Token &token)
token.type = INCLUDE;
return true;
}
+7 -6
View File
@@ -13,6 +13,7 @@
#include <iostream>
#include <map>
#include <string>
#include "token.h"
namespace OHOS {
@@ -69,16 +70,16 @@ private:
std::ifstream src_;
std::shared_ptr<std::string> srcName_;
char buffer_[BUFFER_SIZE]{0};
const char *bufferStart_{nullptr};
const char *bufferEnd_{nullptr};
char buffer_[BUFFER_SIZE] {0};
const char *bufferStart_ {nullptr};
const char *bufferEnd_ {nullptr};
int32_t lineno_;
int32_t lineLoc_;
};
std::ostream& operator<<(std::ostream &s, const Lexer &lexer);
std::ostream &operator<<(std::ostream &s, const Lexer &lexer);
} // Hardware
} // OHOS
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_LEXER_H
+9 -9
View File
@@ -6,13 +6,13 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#ifndef HC_GEN_LOG_H
#define HC_GEN_LOG_H
#include <iostream>
#include <map>
#include <string>
#include "option.h"
namespace OHOS {
@@ -33,7 +33,7 @@ public:
::std::cout << ::std::endl;
}
template<typename T>
template <typename T>
inline Logger &operator<<(const T &v)
{
if (level_ <= DEBUG && !Option::Instance().VerboseLog()) {
@@ -93,12 +93,12 @@ private:
void ShowLevel()
{
static ::std::map<LogLevel, ::std::string> levelStrMap = {
{NONE, ""},
{DEBUG, "Debug"},
{INFO, "Info"},
{NONE, "" },
{DEBUG, "Debug" },
{INFO, "Info" },
{WARNING, "Warning"},
{ERROR, "Error"},
{FATAL, "Fatal"}
{ERROR, "Error" },
{FATAL, "Fatal" }
};
if (level_ > INFO) {
::std::cout << ERROR_COLOR_PREFIX;
@@ -115,6 +115,6 @@ private:
#endif
};
} // OHOS
} // Hardware
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_LOG_H
+16 -18
View File
@@ -6,21 +6,20 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include "macro_gen.h"
#include <string>
#include "file.h"
#include "logger.h"
#include "macro_gen.h"
using namespace OHOS::Hardware;
constexpr static const char *FILE_HEAD_COMMENT = \
"/*\n" \
" * This is an automatically generated HDF config file. Do not modify it manually.\n" \
constexpr static const char *FILE_HEAD_COMMENT =
"/*\n"
" * This is an automatically generated HDF config file. Do not modify it manually.\n"
" */\n\n";
MacroGen::MacroGen(std::shared_ptr<Ast> ast) : Generator(ast)
{
}
MacroGen::MacroGen(std::shared_ptr<Ast> ast) : Generator(ast) {}
const std::string &MacroGen::ToUpperString(std::string &str)
{
@@ -115,8 +114,8 @@ std::string MacroGen::GenFullName(int32_t depth, const std::shared_ptr<AstObject
return name;
}
bool MacroGen::GenArray(const std::string &arrName, uint32_t &arrSize, uint32_t type,
const std::shared_ptr<AstObject> &node)
bool MacroGen::GenArray(
const std::string &arrName, uint32_t &arrSize, uint32_t type, const std::shared_ptr<AstObject> &node)
{
static uint32_t index = 0;
const uint32_t ELEMENT_PER_LINE = 8;
@@ -157,10 +156,11 @@ bool MacroGen::GenNodeForeach(int32_t depth, const std::shared_ptr<AstObject> &n
auto child = node->Child();
uint32_t count = 0;
Logger().Debug() << "node:" << node->Name() << " child:" << " depth:" << depth;
Logger().Debug() << "node:" << node->Name() << " child:"
<< " depth:" << depth;
while (child != nullptr) {
if (child->IsNode()) {
Logger().Debug() << " " << child->Name();
Logger().Debug() << " " << child->Name();
subList.push_back(GenFullName(depth + 1, child, "_"));
count++;
}
@@ -221,8 +221,7 @@ bool MacroGen::NodeWalk()
auto type = current->Type();
static uint32_t arraySize = 0;
Logger().Debug() << "name,type:[" << current->Name() << "," << type \
<< "] depth:" << depth \
Logger().Debug() << "name,type:[" << current->Name() << "," << type << "] depth:" << depth
<< " arraySize:" << std::dec << arraySize << '\n';
SetTypeData(type, current, arraySize, depth);
@@ -230,8 +229,7 @@ bool MacroGen::NodeWalk()
});
}
void MacroGen::SetTypeData(uint32_t type, const std::shared_ptr<AstObject> &current,
uint32_t &arraySize, int32_t depth)
void MacroGen::SetTypeData(uint32_t type, const std::shared_ptr<AstObject> &current, uint32_t &arraySize, int32_t depth)
{
static std::string nodeName;
static std::string arrayName;
@@ -248,7 +246,7 @@ void MacroGen::SetTypeData(uint32_t type, const std::shared_ptr<AstObject> &curr
if (arraySize != 0) {
GenArray(arrayName, arraySize, arrayType, current);
} else {
ofs_ << " " << '"' << current->StringValue() << '"' << std::endl;
ofs_ << " " << '"' << current->StringValue() << '"' << std::endl;
}
break;
case PARSEROP_CONFTERM:
@@ -281,8 +279,8 @@ void MacroGen::SetTypeData(uint32_t type, const std::shared_ptr<AstObject> &curr
}
}
void MacroGen::SetTypeDataUinit64(const std::string &arrayName, uint32_t &arraySize, uint32_t arrayType,
const std::shared_ptr<AstObject> &current)
void MacroGen::SetTypeDataUinit64(
const std::string &arrayName, uint32_t &arraySize, uint32_t arrayType, const std::shared_ptr<AstObject> &current)
{
if (arraySize != 0) {
GenArray(arrayName, arraySize, arrayType, current);
+4 -3
View File
@@ -9,10 +9,11 @@
#ifndef HC_GEN_MACRO_GEN_H
#define HC_GEN_MACRO_GEN_H
#include "generator.h"
#include <fstream>
#include <map>
#include "generator.h"
namespace OHOS {
namespace Hardware {
class MacroGen : public Generator {
@@ -53,6 +54,6 @@ private:
std::string outFileName_;
std::map<int, std::string> nodeNameMap_;
};
} // Hardware
} // OHOS
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_MACRO_GEN_H
+3 -2
View File
@@ -11,6 +11,7 @@
#include <cstdint>
#include <string>
#include "ast.h"
namespace OHOS {
@@ -37,7 +38,7 @@ struct HcbHeader {
int32_t totalSize;
};
} // OHOS
} // Hardware
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_OPCODE_H
+11 -9
View File
@@ -6,13 +6,14 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include "option.h"
#include <cstring>
#include <getopt.h>
#include <iostream>
#include <iomanip>
#include "logger.h"
#include <iostream>
#include "file.h"
#include "logger.h"
#include "option.h"
using namespace OHOS::Hardware;
static constexpr int HCS_COMPILER_VERSION_MAJOR = 00;
@@ -59,6 +60,9 @@ bool Option::ParseOptions(int argc, char **argv)
while (op != OPTION_END) {
op = getopt(argc, argv, HCS_SUPPORT_ARGS);
SetOptionData(op);
if (ShouldShowUsage() || ShouldShowVersion()) {
return false;
}
}
return true;
@@ -105,8 +109,6 @@ void Option::SetOptionData(char op)
showUsage_ = true;
break;
case '?':
showUsage_ = true;
optionError_ = true;
SetOptionError();
break;
default:
@@ -116,9 +118,9 @@ void Option::SetOptionData(char op)
void Option::ShowUsage()
{
Logger() <<
"Usage: hc-gen [Options] [File]\n" <<
"options:";
Logger() << "Usage: hc-gen [Options] [File]\n"
<< "options:";
ShowOption("-o <file>", "output file name, default same as input");
ShowOption("-a", "hcb align with four bytes");
ShowOption("-b", "output binary output, default enable");
ShowOption("-t", "output config in C language source file style");
@@ -234,7 +236,7 @@ bool Option::SetSourceOption(const char *srcName)
}
sourceName_ = srcAbsPath;
sourceNameBase_ = Util::File::FileNameBase(srcAbsPath) ;
sourceNameBase_ = Util::File::FileNameBase(srcAbsPath);
return true;
}
+4 -3
View File
@@ -62,11 +62,12 @@ public:
std::string GetSourceDir();
static std::string RealPathSourcePath(const char *path);
private:
static void ShowOption(const std::string &option, const std::string &helpInfo);
bool ParseOptions(int argc, char *argv[]);
void SetOptionError(bool shouldShowUsage = true);
bool SetSourceOption(const char* srcName);
bool SetSourceOption(const char *srcName);
bool showUsage_ = false;
bool showVersion_ = false;
@@ -86,6 +87,6 @@ private:
void SetOptionData(char op);
};
} // Hardware
} // OHOS
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_OPTION_H
+5 -5
View File
@@ -6,10 +6,11 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include "parser.h"
#include <memory>
#include "file.h"
#include "logger.h"
#include "parser.h"
using namespace OHOS::Hardware;
@@ -54,7 +55,6 @@ bool Parser::Parse()
return true;
}
std::shared_ptr<Ast> Parser::ParseOne(const std::string &src, std::list<std::string> &includeList)
{
if (!lexer_.Initialize(src)) {
@@ -156,8 +156,8 @@ std::shared_ptr<AstObject> Parser::ParseNode(Token &name, bool bracesStart)
child = ParseNodeAndTerm();
break;
default:
Logger().Error() << lexer_
<< "syntax error, except '}' or TEMPLATE or LITERAL for node '" << name.strval << '\'';
Logger().Error() << lexer_ << "syntax error, except '}' or TEMPLATE or LITERAL for node '"
<< name.strval << '\'';
return nullptr;
}
if (child == nullptr) {
@@ -180,7 +180,7 @@ std::shared_ptr<AstObject> Parser::ParseTerm(Token &name)
Logger().Error() << lexer_ << "syntax error, miss value of config term";
return nullptr;
}
auto term = std::shared_ptr<AstObject>(new(std::nothrow) ConfigTerm(name, nullptr));
auto term = std::shared_ptr<AstObject>(new (std::nothrow) ConfigTerm(name, nullptr));
if (term == nullptr) {
return nullptr;
}
+3 -3
View File
@@ -10,13 +10,13 @@
#define HC_GEN_PARSER_H
#include <memory>
#include "ast.h"
#include "lexer.h"
namespace OHOS {
namespace Hardware {
class Parser {
public:
Parser() = default;
@@ -58,6 +58,6 @@ private:
std::list<std::string> srcQueue_;
};
} // OHOS
} // Hardware
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_PARSER_H
+37 -37
View File
@@ -7,6 +7,7 @@
*/
#include <set>
#include "file.h"
#include "logger.h"
#include "opcode.h"
@@ -14,14 +15,12 @@
using namespace OHOS::Hardware;
constexpr static const char *FILE_HEAD_COMMENT = \
"/*\n" \
" * This is an automatically generated HDF config file. Do not modify it manually.\n" \
constexpr static const char *FILE_HEAD_COMMENT =
"/*\n"
" * This is an automatically generated HDF config file. Do not modify it manually.\n"
" */\n\n";
TextGen::TextGen(std::shared_ptr<Ast> ast) : Generator(ast)
{
}
TextGen::TextGen(std::shared_ptr<Ast> ast) : Generator(ast) {}
bool TextGen::Output()
{
@@ -99,8 +98,8 @@ bool TextGen::HeaderOutputTraversal()
return false;
}
ofs_ << "const struct " << ToUpperCamelString(prefix_) << moduleName_ << "Root* HdfGet"
<< moduleName_ << "ModuleConfigRoot(void);\n";
ofs_ << "const struct " << ToUpperCamelString(prefix_) << moduleName_ << "Root* HdfGet" << moduleName_
<< "ModuleConfigRoot(void);\n";
return ofs_.good();
}
@@ -122,8 +121,9 @@ bool TextGen::ImplOutput()
return ret;
}
ofs_ << "\nconst struct " << ToUpperCamelString(prefix_) << moduleName_ << "Root* HdfGet" << moduleName_ << "ModuleConfigRoot(void)\n"
<< "{\n"
ofs_ << "\nconst struct " << ToUpperCamelString(prefix_) << moduleName_ << "Root* HdfGet" << moduleName_
<< "ModuleConfigRoot(void)\n"
<< "{\n"
<< Indent() << "return &" << rootVariableName_ << ";\n"
<< "}\n";
@@ -248,7 +248,7 @@ std::string TextGen::GenConfigStructName(const std::shared_ptr<AstObject> &node)
return ToUpperCamelString(prefix_).append(ToUpperCamelString(moduleName_)).append(ToUpperCamelString(node->Name()));
}
bool TextGen::GenObjectDefinitionGen(const std::shared_ptr<AstObject>& object)
bool TextGen::GenObjectDefinitionGen(const std::shared_ptr<AstObject> &object)
{
if (!object->IsNode() && !object->IsTerm()) {
return true;
@@ -289,8 +289,8 @@ bool TextGen::GenTermDefinition(const std::shared_ptr<AstObject> &term)
ofs_ << TAB << "const " << TypeToStr(array->ArrayType()) << "* " << term->Name() << ";\n";
ofs_ << TAB << "uint32_t " << term->Name() << "Size;\n";
} else {
ofs_ << TAB << TypeToStr(array->ArrayType()) << " " << term->Name() << "["
<< array->ArraySize() << "];\n";
ofs_ << TAB << TypeToStr(array->ArrayType()) << " " << term->Name() << "[" << array->ArraySize()
<< "];\n";
}
break;
}
@@ -304,8 +304,7 @@ bool TextGen::GenTermDefinition(const std::shared_ptr<AstObject> &term)
case PARSEROP_NODEREF: {
auto structName = GenConfigStructName(ConfigTerm::CastFrom(term)->RefNode().lock());
ofs_ << TAB << "const struct " << structName << "* " << term->Name() << ";\n";
}
break;
} break;
default:
break;
}
@@ -328,10 +327,10 @@ bool TextGen::IsInTemplate(const std::shared_ptr<AstObject> &object)
const std::string &TextGen::TypeToStr(uint32_t type)
{
static std::map<uint32_t, std::string> typeMap = {
{PARSEROP_UINT8, "uint8_t"},
{PARSEROP_UINT16, "uint16_t"},
{PARSEROP_UINT32, "uint32_t"},
{PARSEROP_UINT64, "uint64_t"},
{PARSEROP_UINT8, "uint8_t" },
{PARSEROP_UINT16, "uint16_t" },
{PARSEROP_UINT32, "uint32_t" },
{PARSEROP_UINT64, "uint64_t" },
{PARSEROP_STRING, "const char*"},
};
return typeMap[type];
@@ -339,11 +338,11 @@ const std::string &TextGen::TypeToStr(uint32_t type)
bool TextGen::OutputImplGlobalVariables()
{
auto forwardWalkFunc = [this](const std::shared_ptr<AstObject>& current, int32_t depth) -> uint32_t {
auto forwardWalkFunc = [this](const std::shared_ptr<AstObject> &current, int32_t depth) -> uint32_t {
return ImplementGenTraversal(current, depth);
};
auto backwardWalkFunc = [this](const std::shared_ptr<AstObject>& current, int32_t depth) -> uint32_t {
auto backwardWalkFunc = [this](const std::shared_ptr<AstObject> &current, int32_t depth) -> uint32_t {
return ImplementCloseBraceGen(current, depth);
};
@@ -468,8 +467,8 @@ std::string TextGen::GenTemplateVariableName(const std::shared_ptr<AstObject> &o
}
return node->TemplateSignNum() != 0 ?
std::string("g_").append(prefix_).append(name).append(std::to_string(node->TemplateSignNum())) :
std::string("g_").append(prefix_).append(name);
std::string("g_").append(prefix_).append(name).append(std::to_string(node->TemplateSignNum())) :
std::string("g_").append(prefix_).append(name);
}
std::shared_ptr<TextGen::Symbol> TextGen::SymbolFind(const std::string &name)
@@ -612,8 +611,7 @@ bool TextGen::OutputTemplateImpl()
}
return ast_->WalkBackward([this](const std::shared_ptr<AstObject> &object, int32_t) -> uint32_t {
if (!object->IsNode() ||
(object->IsNode() && ConfigNode::CastFrom(object)->GetNodeType() != NODE_TEMPLATE)) {
if (!object->IsNode() || (object->IsNode() && ConfigNode::CastFrom(object)->GetNodeType() != NODE_TEMPLATE)) {
return NOERR;
}
auto node = ConfigNode::CastFrom(object);
@@ -621,8 +619,8 @@ bool TextGen::OutputTemplateImpl()
return NOERR;
}
ofs_ << "static const struct " << GenConfigStructName(object) << ' '
<< GenTemplateVariableName(object) << "[] = {\n";
ofs_ << "static const struct " << GenConfigStructName(object) << ' ' << GenTemplateVariableName(object)
<< "[] = {\n";
auto subClass = node->SubClasses();
for (auto nodeObj : subClass) {
std::shared_ptr<AstObject> obj = std::shared_ptr<AstObject>(nodeObj, [](auto p) {});
@@ -644,7 +642,7 @@ bool TextGen::OutputTemplateVariablesDeclare()
if (object->IsTerm() && object->Child()->IsArray()) {
return ArrayVariablesDeclareGen(object);
} else if (!object->IsNode() ||
(object->IsNode() && ConfigNode::CastFrom(object)->GetNodeType() != NODE_TEMPLATE)) {
(object->IsNode() && ConfigNode::CastFrom(object)->GetNodeType() != NODE_TEMPLATE)) {
return NOERR;
}
auto node = ConfigNode::CastFrom(object);
@@ -669,7 +667,8 @@ uint32_t TextGen::ArrayVariablesDeclareGen(const std::shared_ptr<AstObject> &obj
auto arrayName = GenArrayName(object);
auto array = ConfigArray::CastFrom(object->Child());
ofs_ << "static const " << TypeToStr(array->ArrayType()) << ' ' << arrayName << '[' << array->ArraySize()
<< "] = {\n" << Indent();
<< "] = {\n"
<< Indent();
HcsPrintArrayContent(object->Child(), 1);
ofs_ << "\n};\n\n";
@@ -685,7 +684,7 @@ std::string TextGen::GenArrayName(const std::shared_ptr<AstObject> &term)
if (sym == nullptr) {
SymbolAdd(arrayName, term);
t->SetSigNum(1);
} else if (t->SigNum() == 0){
} else if (t->SigNum() == 0) {
t->SetSigNum(sym->duplicateCount + 1);
sym->duplicateCount++;
}
@@ -698,12 +697,13 @@ uint32_t TextGen::TemplateVariableGen(const std::shared_ptr<AstObject> &nodeObje
{
auto child = nodeObject->Child();
while (child != nullptr) {
auto res = Ast::WalkRound(child,
[this](const std::shared_ptr<AstObject>& object, uint32_t depth) -> uint32_t {
return ObjectImplementGen(object, depth + 2);
auto res = Ast::WalkRound(
child,
[this](const std::shared_ptr<AstObject> &object, uint32_t depth) -> uint32_t {
return ObjectImplementGen(object, depth + 2);
},
[this](const std::shared_ptr<AstObject>& object, uint32_t depth) -> uint32_t {
return ImplementCloseBraceGen(object, depth + 2);
[this](const std::shared_ptr<AstObject> &object, uint32_t depth) -> uint32_t {
return ImplementCloseBraceGen(object, depth + 2);
});
if (!res) {
return false;
@@ -717,7 +717,7 @@ bool TextGen::DuplicateNodeNameCheck()
{
std::map<std::string, std::shared_ptr<AstObject>> nodeMap;
return ast_->WalkForward([&](const std::shared_ptr<AstObject>& current, uint32_t) -> uint32_t {
return ast_->WalkForward([&](const std::shared_ptr<AstObject> &current, uint32_t) -> uint32_t {
if (!current->IsNode() || IsInSubClassNode(current)) {
return NOERR;
}
@@ -729,7 +729,7 @@ bool TextGen::DuplicateNodeNameCheck()
}
Logger().Error() << current->SourceInfo() << "duplicate node name at " << node->second->SourceInfo() << "\n"
<< "To avoid redefining structures, not allow duplicate node name at text config mode";
<< "To avoid redefining structures, not allow duplicate node name at text config mode";
return EFAIL;
});
}
+11 -10
View File
@@ -12,6 +12,7 @@
#include <fstream>
#include <map>
#include <utility>
#include "generator.h"
namespace OHOS {
@@ -51,7 +52,7 @@ private:
std::string GenConfigStructName(const std::shared_ptr<AstObject> &node);
bool GenObjectDefinitionGen(const std::shared_ptr<AstObject>& object);
bool GenObjectDefinitionGen(const std::shared_ptr<AstObject> &object);
bool GenTermDefinition(const std::shared_ptr<AstObject> &term);
@@ -65,7 +66,7 @@ private:
uint32_t ImplementCloseBraceGen(const std::shared_ptr<AstObject> &object, int32_t depth);
static const std::string & Indent(uint32_t times = 1);
static const std::string &Indent(uint32_t times = 1);
static bool IsInSubClassNode(const std::shared_ptr<AstObject> &object);
@@ -84,7 +85,7 @@ private:
std::shared_ptr<Symbol> SymbolFind(const std::string &name);
void SymbolAdd(const std::string &name, const std::shared_ptr<AstObject>& object);
void SymbolAdd(const std::string &name, const std::shared_ptr<AstObject> &object);
std::ofstream ofs_;
std::string outputFileName_;
@@ -96,13 +97,13 @@ private:
uint32_t PrintTermImplement(const std::shared_ptr<AstObject> &object, int32_t depth);
bool PrintBaseTypeValue(const std::shared_ptr<AstObject>& object);
bool PrintBaseTypeValue(const std::shared_ptr<AstObject> &object);
uint32_t PrintArrayImplement(const std::shared_ptr<AstObject> &object, int32_t depth);
bool PrintArrayImplInSubClass(const std::shared_ptr<AstObject> &object, int32_t depth);
bool HcsPrintArrayContent(const std::shared_ptr<AstObject>& object, uint32_t indent);
bool HcsPrintArrayContent(const std::shared_ptr<AstObject> &object, uint32_t indent);
std::string HcsBuildObjectPath(std::shared_ptr<AstObject> object);
@@ -110,13 +111,13 @@ private:
bool OutputTemplateVariablesDeclare();
uint32_t ArrayVariablesDeclareGen(const std::shared_ptr<AstObject>& object);
uint32_t ArrayVariablesDeclareGen(const std::shared_ptr<AstObject> &object);
std::string GenArrayName(const std::shared_ptr<AstObject>& term);
std::string GenArrayName(const std::shared_ptr<AstObject> &term);
uint32_t TemplateVariableGen(const std::shared_ptr<AstObject>& nodeObject);
uint32_t TemplateVariableGen(const std::shared_ptr<AstObject> &nodeObject);
};
} // Hardware
} // OHOS
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_TEXT_GENERATOR_H
+11 -12
View File
@@ -6,24 +6,25 @@
* See the LICENSE file in the root of this repository for complete details.
*/
#include "token.h"
#include <iomanip>
#include <map>
#include "token.h"
using namespace OHOS::Hardware;
std::string OHOS::Hardware::TokenType2String(int32_t type)
{
static std::map<int32_t, std::string> tokenTypeMap = {
{NUMBER, "NUMBER"},
{TEMPLATE, "TEMPLATE"},
{LITERAL, "LITERAL"},
{ROOT, "ROOT"},
{INCLUDE, "INCLUDE"},
{DELETE, "DELETE"},
{STRING, "STRING"},
{REF_PATH, "REF_PATH"},
{FILE_PATH, "FILE_PATH"}
{NUMBER, "NUMBER" },
{TEMPLATE, "TEMPLATE" },
{LITERAL, "LITERAL" },
{ROOT, "ROOT" },
{INCLUDE, "INCLUDE" },
{DELETE, "DELETE" },
{STRING, "STRING" },
{REF_PATH, "REF_PATH" },
{FILE_PATH, "FILE_PATH"}
};
std::string str;
@@ -65,5 +66,3 @@ bool Token::operator!=(Token &t) const
{
return t.type != type || t.numval != numval || t.strval != strval;
}
+3 -5
View File
@@ -42,13 +42,11 @@ struct Token {
friend std::ostream &operator<<(std::ostream &stream, const Token &t);
};
std::ostream& operator<<(std::ostream &s, const Token &t);
std::ostream &operator<<(std::ostream &s, const Token &t);
std::string TokenType2String(int32_t type);
} // Hardware
} // OHOS
} // namespace Hardware
} // namespace OHOS
#endif // HC_GEN_TOKEN_H
+16 -16
View File
@@ -9,18 +9,18 @@
#ifndef HC_GEN_TYPES_H
#define HC_GEN_TYPES_H
#define ALIGN_SIZE 4
#define TAB " "
#define TAB_SIZE 4
#define ALIGN_SIZE 4
#define TAB " "
#define TAB_SIZE 4
#define OPCODE_BYTE_WIDTH 1
#define BYTE_SIZE 1
#define WORD_SIZE 2
#define BYTE_SIZE 1
#define WORD_SIZE 2
#define DWORD_SIZE 4
#define QWORD_SIZE 8
#define UNIX_SEPARATOR '/'
#define WIN_SEPARATOR '\\'
#define WIN_SEPARATOR '\\'
#ifdef OS_WIN
#define OS_SEPARATOR WIN_SEPARATOR
@@ -29,16 +29,16 @@
#endif
enum HcsErrorNo {
NOERR = 0, /* No error */
EFAIL, /* Process fail */
EOOM, /* Out of memory */
EOPTION, /* Option error */
EREOPENF, /* Reopen argument */
EINVALF, /* Invalid file */
EINVALARG, /* Invalid argument */
EDECOMP, /* Decompile error */
EOUTPUT, /* Output error */
EASTWALKBREAK, /* Break ast walk */
NOERR = 0, /* No error */
EFAIL, /* Process fail */
EOOM, /* Out of memory */
EOPTION, /* Option error */
EREOPENF, /* Reopen argument */
EINVALF, /* Invalid file */
EINVALARG, /* Invalid argument */
EDECOMP, /* Decompile error */
EOUTPUT, /* Output error */
EASTWALKBREAK, /* Break ast walk */
};
#endif // HC_GEN_TYPES_H