mirror of
https://gitee.com/openharmony/ability_idl_tool
synced 2024-11-23 07:20:29 +00:00
告警清理
Signed-off-by: zhangjidong <873721519@qq.com>
This commit is contained in:
parent
125eb45ab5
commit
25d2e70c9e
@ -13,10 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "codegen/cpp_code_emitter.h"
|
||||
|
||||
#include <sstream>
|
||||
#include "securec.h"
|
||||
#include "util/file.h"
|
||||
#include "codegen/cpp_code_emitter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
@ -995,7 +995,7 @@ void CppCodeEmitter::EmitWriteVariableComplex(
|
||||
switch (mt->kind_) {
|
||||
case TypeKind::Array:
|
||||
case TypeKind::List: {
|
||||
sb.Append(prefix).AppendFormat("if (%s.size() > VECTOR_MAX_SIZE) {\n", name.c_str());
|
||||
sb.Append(prefix).AppendFormat("if (%s.size() > static_cast<size_t>(VECTOR_MAX_SIZE)) {\n", name.c_str());
|
||||
if (logOn_) {
|
||||
if (mt != nullptr && mt->kind_ == TypeKind::Array) {
|
||||
sb.Append(prefix).Append(TAB).Append(
|
||||
@ -1018,7 +1018,7 @@ void CppCodeEmitter::EmitWriteVariableComplex(
|
||||
break;
|
||||
}
|
||||
case TypeKind::Map: {
|
||||
sb.Append(prefix).AppendFormat("if (%s.size() > MAP_MAX_SIZE) {\n", name.c_str());
|
||||
sb.Append(prefix).AppendFormat("if (%s.size() > static_cast<size_t>(MAP_MAX_SIZE)) {\n", name.c_str());
|
||||
if (logOn_) {
|
||||
sb.Append(prefix).Append(TAB).AppendFormat(
|
||||
"HiLog::Error(LABEL, \"The map size exceeds the security limit!\");\n");
|
||||
@ -1201,20 +1201,26 @@ void CppCodeEmitter::EmitReadVariableList(const String& parcelName, const std::s
|
||||
sb.Append(prefix).AppendFormat("%s %s;\n", EmitType(mt, ATTR_IN, true).string(), name.c_str());
|
||||
}
|
||||
sb.Append(prefix).AppendFormat("int32_t %sSize = %sReadInt32();\n", name.c_str(), parcelName.string());
|
||||
sb.Append(prefix).AppendFormat("if (%sSize > VECTOR_MAX_SIZE) {\n", name.c_str());
|
||||
sb.Append(prefix).AppendFormat("if (%sSize > static_cast<int32_t>(VECTOR_MAX_SIZE)) {\n", name.c_str());
|
||||
if (logOn_) {
|
||||
sb.Append(prefix + TAB)
|
||||
.Append("HiLog::Error(LABEL, \"The vector/array size exceeds the security limit!\");\n");
|
||||
}
|
||||
sb.Append(prefix + TAB).Append("return ERR_INVALID_DATA;\n");
|
||||
sb.Append(prefix).Append("}\n");
|
||||
sb.Append(prefix).AppendFormat("for (int32_t i = 0; i < %sSize; ++i) {\n", name.c_str());
|
||||
circleCount++;
|
||||
std::stringstream circleCountStr;
|
||||
circleCountStr << circleCount;
|
||||
std::string iStr = "i" + circleCountStr.str();
|
||||
std::string valueStr = "value" + circleCountStr.str();
|
||||
sb.Append(prefix).AppendFormat("for (int32_t %s = 0; %s < %sSize; ++%s) {\n",
|
||||
iStr.c_str(), iStr.c_str(), name.c_str(), iStr.c_str());
|
||||
MetaType* innerType = metaComponent_->types_[mt->nestedTypeIndexes_[0]];
|
||||
EmitReadVariable(parcelName, "value", innerType, sb, prefix + TAB);
|
||||
EmitReadVariable(parcelName, valueStr.c_str(), innerType, sb, prefix + TAB);
|
||||
if (innerType->kind_ == TypeKind::Sequenceable) {
|
||||
sb.Append(prefix + TAB).AppendFormat("%s.push_back(*value);\n", name.c_str());
|
||||
sb.Append(prefix + TAB).AppendFormat("%s.push_back(*%s);\n", name.c_str(), valueStr.c_str());
|
||||
} else {
|
||||
sb.Append(prefix + TAB).AppendFormat("%s.push_back(value);\n", name.c_str());
|
||||
sb.Append(prefix + TAB).AppendFormat("%s.push_back(%s);\n", name.c_str(), valueStr.c_str());
|
||||
}
|
||||
sb.Append(prefix).Append("}\n");
|
||||
break;
|
||||
|
@ -192,6 +192,8 @@ private:
|
||||
String ConstantName(const String& name);
|
||||
|
||||
const std::string UnderlineAdded(const String& name);
|
||||
|
||||
int circleCount = 0;
|
||||
};
|
||||
} // namespace Idl
|
||||
} // namespace OHOS
|
||||
|
@ -384,12 +384,13 @@ void TsCodeEmitter::EmitInterfaceMethodCallback(MetaMethod* metaMethod, int meth
|
||||
}
|
||||
}
|
||||
for (size_t index = 0; index < methods_[methodIndex].parameters_.size(); index++) {
|
||||
if ((methods_[methodIndex].parameters_[index].attr_ & ATTR_OUT) != 0) {
|
||||
stringBuilder.AppendFormat("%s",
|
||||
SuffixAdded(methods_[methodIndex].parameters_[index].name_.c_str()).c_str());
|
||||
if (index != methods_[methodIndex].parameters_.size() - 1) {
|
||||
stringBuilder.Append(", ");
|
||||
}
|
||||
if ((methods_[methodIndex].parameters_[index].attr_ & ATTR_OUT) == 0) {
|
||||
continue;
|
||||
}
|
||||
stringBuilder.AppendFormat("%s",
|
||||
SuffixAdded(methods_[methodIndex].parameters_[index].name_.c_str()).c_str());
|
||||
if (index != methods_[methodIndex].parameters_.size() - 1) {
|
||||
stringBuilder.Append(", ");
|
||||
}
|
||||
}
|
||||
stringBuilder.Append(");\n");
|
||||
|
@ -56,7 +56,7 @@ std::string SaArrayTypeEmitter::EmitTsType(TypeMode mode) const
|
||||
void SaArrayTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb,
|
||||
const std::string &prefix) const
|
||||
{
|
||||
sb.Append(prefix).AppendFormat("if (%s.size() > VECTOR_MAX_SIZE) {\n", name.c_str());
|
||||
sb.Append(prefix).AppendFormat("if (%s.size() > static_cast<size_t>(VECTOR_MAX_SIZE)) {\n", name.c_str());
|
||||
if (logOn_) {
|
||||
sb.Append(prefix).Append(TAB).Append(
|
||||
"HiLog::Error(LABEL, \"The vector/array size exceeds the security limit!\");\n");
|
||||
@ -76,7 +76,7 @@ void SaArrayTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std
|
||||
sb.Append(prefix).AppendFormat("%s %s;\n", EmitCppType(TypeMode::LOCAL_VAR).c_str(), name.c_str());
|
||||
}
|
||||
sb.Append(prefix).AppendFormat("int32_t %sSize = %sReadInt32();\n", name.c_str(), parcelName.c_str());
|
||||
sb.Append(prefix).AppendFormat("if (%sSize > VECTOR_MAX_SIZE) {\n", name.c_str());
|
||||
sb.Append(prefix).AppendFormat("if (%sSize > static_cast<int32_t>(VECTOR_MAX_SIZE)) {\n", name.c_str());
|
||||
if (logOn_) {
|
||||
sb.Append(prefix + TAB).Append("HiLog::Error(LABEL, \"The vector/array size exceeds the security limit!\");\n");
|
||||
}
|
||||
@ -173,7 +173,7 @@ std::string SaListTypeEmitter::EmitTsType(TypeMode mode) const
|
||||
void SaListTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb,
|
||||
const std::string &prefix) const
|
||||
{
|
||||
sb.Append(prefix).AppendFormat("if (%s.size() > VECTOR_MAX_SIZE) {\n", name.c_str());
|
||||
sb.Append(prefix).AppendFormat("if (%s.size() > static_cast<size_t>(VECTOR_MAX_SIZE)) {\n", name.c_str());
|
||||
if (logOn_) {
|
||||
sb.Append(prefix).Append(TAB).Append(
|
||||
"HiLog::Error(LABEL, \"The list size exceeds the security limit!\");\n");
|
||||
|
@ -61,7 +61,7 @@ std::string SaMapTypeEmitter::EmitTsType(TypeMode mode) const
|
||||
void SaMapTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb,
|
||||
const std::string &prefix) const
|
||||
{
|
||||
sb.Append(prefix).AppendFormat("if (%s.size() > MAP_MAX_SIZE) {\n", name.c_str());
|
||||
sb.Append(prefix).AppendFormat("if (%s.size() > static_cast<size_t>(MAP_MAX_SIZE)) {\n", name.c_str());
|
||||
if (logOn_) {
|
||||
sb.Append(prefix).Append(TAB).AppendFormat(
|
||||
"HiLog::Error(LABEL, \"The map size exceeds the security limit!\");\n");
|
||||
|
35
main.cpp
35
main.cpp
@ -26,10 +26,8 @@ using namespace OHOS::Idl;
|
||||
|
||||
static const char* TAG = "idl";
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int DoOptionsCheck(Options& options)
|
||||
{
|
||||
Options options(argc, argv);
|
||||
|
||||
if (options.DoShowUsage()) {
|
||||
options.ShowUsage();
|
||||
return 0;
|
||||
@ -51,9 +49,11 @@ int main(int argc, char** argv)
|
||||
options.ShowWarning();
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::shared_ptr<MetaComponent> metadata;
|
||||
|
||||
int DoCompile(Options& options, std::shared_ptr<MetaComponent>& metadata)
|
||||
{
|
||||
if (options.DoCompile()) {
|
||||
Parser parser(options);
|
||||
if (!parser.Parse(options.GetSourceFile())) {
|
||||
@ -90,7 +90,11 @@ int main(int argc, char** argv)
|
||||
metadataFile.Flush();
|
||||
metadataFile.Close();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DoGenerage(Options& options, std::shared_ptr<MetaComponent>& metadata)
|
||||
{
|
||||
if (options.DoGenerateCode()) {
|
||||
if (metadata == nullptr) {
|
||||
String metadataFile = options.GetMetadataFile();
|
||||
@ -108,6 +112,27 @@ int main(int argc, char** argv)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Options options(argc, argv);
|
||||
int checkOffRes = DoOptionsCheck(options);
|
||||
if (!checkOffRes) {
|
||||
return checkOffRes;
|
||||
}
|
||||
|
||||
std::shared_ptr<MetaComponent> metadata;
|
||||
int compileRes = DoCompile(options, metadata);
|
||||
if (compileRes) {
|
||||
return compileRes;
|
||||
}
|
||||
|
||||
int generateRes = DoGenerage(options, metadata);
|
||||
if (generateRes) {
|
||||
return generateRes;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -25,11 +25,11 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
const char* MetadataBuilder::TAG = "MetadataBuilder";
|
||||
const char* MetadataBuilder::tag = "MetadataBuilder";
|
||||
std::shared_ptr<MetaComponent> MetadataBuilder::Build()
|
||||
{
|
||||
if (!module_->IsValid()) {
|
||||
Logger::E(TAG, "The module is not validate.");
|
||||
Logger::E(tag, "The module is not validate.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ std::shared_ptr<MetaComponent> MetadataBuilder::Build()
|
||||
if (size_ > 0) {
|
||||
void* metadata = calloc(size_, 1);
|
||||
if (metadata == nullptr) {
|
||||
Logger::E(TAG, "Out of memory.");
|
||||
Logger::E(tag, "Out of memory.");
|
||||
return nullptr;
|
||||
}
|
||||
metaComponent_.reset(
|
||||
|
@ -74,7 +74,7 @@ private:
|
||||
|
||||
TypeKind Type2Kind(ASTType* type);
|
||||
|
||||
static const char* TAG;
|
||||
static const char* tag;
|
||||
AutoPtr<ASTModule> module_;
|
||||
std::shared_ptr<MetaComponent> metaComponent_;
|
||||
uintptr_t baseAddr_ = 0;
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
const char* MetadataDumper::TAB = " ";
|
||||
const char* MetadataDumper::tab = " ";
|
||||
void MetadataDumper::Dump(const String& prefix)
|
||||
{
|
||||
if (metaComponent_ == nullptr) {
|
||||
@ -34,54 +34,54 @@ String MetadataDumper::DumpMetaComponent(MetaComponent* mc, const String& prefix
|
||||
|
||||
sb.Append(prefix).Append("MetaComponent\n");
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"magic_\" : \"0x%x\",\n", mc->magic_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"size_\" : \"%d\",\n", mc->size_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mc->name_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"namespaceNumber_\" : \"%d\",\n", mc->namespaceNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"sequenceableNumber_\" : \"%d\",\n", mc->sequenceableNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"interfaceNumber_\" : \"%d\",\n", mc->interfaceNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"typeNumber_\" : \"%d\",\n", mc->typeNumber_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"magic_\" : \"0x%x\",\n", mc->magic_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"size_\" : \"%d\",\n", mc->size_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"name_\" : \"%s\",\n", mc->name_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"namespaceNumber_\" : \"%d\",\n", mc->namespaceNumber_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"sequenceableNumber_\" : \"%d\",\n", mc->sequenceableNumber_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"interfaceNumber_\" : \"%d\",\n", mc->interfaceNumber_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"typeNumber_\" : \"%d\",\n", mc->typeNumber_);
|
||||
|
||||
if (mc->namespaceNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"namespaces_\" : [],\n");
|
||||
sb.Append(prefix + tab).Append("\"namespaces_\" : [],\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"namespaces_\" : [\n");
|
||||
sb.Append(prefix + tab).Append("\"namespaces_\" : [\n");
|
||||
for (int i = 0; i < mc->namespaceNumber_; i++) {
|
||||
DumpMetaNamespace(sb, mc->namespaces_[i], prefix + TAB + TAB);
|
||||
DumpMetaNamespace(sb, mc->namespaces_[i], prefix + tab + tab);
|
||||
if (i != mc->namespaceNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("],\n");
|
||||
sb.Append("\n" + prefix + tab).Append("],\n");
|
||||
}
|
||||
|
||||
if (mc->sequenceableNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"sequenceables_\" : [],\n");
|
||||
sb.Append(prefix + tab).Append("\"sequenceables_\" : [],\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"sequenceables_\" : [\n");
|
||||
sb.Append(prefix + tab).Append("\"sequenceables_\" : [\n");
|
||||
for (int i = 0; i < mc->sequenceableNumber_; i++) {
|
||||
DumpMetaSequenceable(sb, mc->sequenceables_[i], prefix + TAB + TAB);
|
||||
DumpMetaSequenceable(sb, mc->sequenceables_[i], prefix + tab + tab);
|
||||
if (i != mc->sequenceableNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("],\n");
|
||||
sb.Append("\n" + prefix + tab).Append("],\n");
|
||||
}
|
||||
|
||||
if (mc->interfaceNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"interfaces_\" : [],\n");
|
||||
sb.Append(prefix + tab).Append("\"interfaces_\" : [],\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"interfaces_\" : [\n");
|
||||
sb.Append(prefix + tab).Append("\"interfaces_\" : [\n");
|
||||
for (int i = 0; i < mc->interfaceNumber_; i++) {
|
||||
DumpMetaInterface(sb, mc->interfaces_[i], prefix + TAB + TAB);
|
||||
DumpMetaInterface(sb, mc->interfaces_[i], prefix + tab + tab);
|
||||
if (i != mc->interfaceNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("],\n");
|
||||
sb.Append("\n" + prefix + tab).Append("],\n");
|
||||
}
|
||||
|
||||
sb.Append(prefix + TAB).AppendFormat("\"stringPoolSize_\" : \"%d\"\n", mc->stringPoolSize_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"stringPoolSize_\" : \"%d\"\n", mc->stringPoolSize_);
|
||||
|
||||
sb.Append(prefix).Append("}\n");
|
||||
|
||||
@ -91,51 +91,51 @@ String MetadataDumper::DumpMetaComponent(MetaComponent* mc, const String& prefix
|
||||
void MetadataDumper::DumpMetaNamespace(StringBuilder& sb, MetaNamespace* mn, const String& prefix)
|
||||
{
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mn->name_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"sequenceableNumber_\" : \"%d\",\n", mn->sequenceableNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"interfaceNumber_\" : \"%d\",\n", mn->interfaceNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"namespaceNumber_\" : \"%d\",\n", mn->namespaceNumber_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"name_\" : \"%s\",\n", mn->name_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"sequenceableNumber_\" : \"%d\",\n", mn->sequenceableNumber_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"interfaceNumber_\" : \"%d\",\n", mn->interfaceNumber_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"namespaceNumber_\" : \"%d\",\n", mn->namespaceNumber_);
|
||||
|
||||
if (mn->sequenceableNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"sequenceableIndexes_\" : [],\n");
|
||||
sb.Append(prefix + tab).Append("\"sequenceableIndexes_\" : [],\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"sequenceableIndexes_\" : [\n");
|
||||
sb.Append(prefix + tab).Append("\"sequenceableIndexes_\" : [\n");
|
||||
for (int i = 0; i < mn->sequenceableNumber_; i++) {
|
||||
MetaSequenceable* mp = metaComponent_->sequenceables_[mn->sequenceableIndexes_[i]];
|
||||
sb.Append(prefix + TAB + TAB).AppendFormat("{ \"name\" : \"%s\" }", mp->name_);
|
||||
sb.Append(prefix + tab + tab).AppendFormat("{ \"name\" : \"%s\" }", mp->name_);
|
||||
if (i != mn->sequenceableNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("],\n");
|
||||
sb.Append("\n" + prefix + tab).Append("],\n");
|
||||
}
|
||||
|
||||
if (mn->interfaceNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"interfaceIndexes_\" : [],\n");
|
||||
sb.Append(prefix + tab).Append("\"interfaceIndexes_\" : [],\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"interfaceIndexes_\" : [\n");
|
||||
sb.Append(prefix + tab).Append("\"interfaceIndexes_\" : [\n");
|
||||
for (int i = 0; i < mn->interfaceNumber_; i++) {
|
||||
MetaInterface* mi = metaComponent_->interfaces_[mn->interfaceIndexes_[i]];
|
||||
sb.Append(prefix + TAB + TAB).AppendFormat("{ \"name\" : \"%s\" }", mi->name_);
|
||||
sb.Append(prefix + tab + tab).AppendFormat("{ \"name\" : \"%s\" }", mi->name_);
|
||||
if (i != mn->interfaceNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("],\n");
|
||||
sb.Append("\n" + prefix + tab).Append("],\n");
|
||||
}
|
||||
|
||||
if (mn->namespaceNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"namespaces_\" : []\n");
|
||||
sb.Append(prefix + tab).Append("\"namespaces_\" : []\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"namespaces_\" : [\n");
|
||||
sb.Append(prefix + tab).Append("\"namespaces_\" : [\n");
|
||||
for (int i = 0; i < mn->namespaceNumber_; i++) {
|
||||
MetaNamespace* innermn = mn->namespaces_[i];
|
||||
DumpMetaNamespace(sb, innermn, prefix + TAB + TAB);
|
||||
DumpMetaNamespace(sb, innermn, prefix + tab + tab);
|
||||
if (i != mn->namespaceNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("]\n");
|
||||
sb.Append("\n" + prefix + tab).Append("]\n");
|
||||
}
|
||||
|
||||
sb.Append(prefix).Append("}");
|
||||
@ -144,32 +144,32 @@ void MetadataDumper::DumpMetaNamespace(StringBuilder& sb, MetaNamespace* mn, con
|
||||
void MetadataDumper::DumpMetaSequenceable(StringBuilder& sb, MetaSequenceable* mp, const String& prefix)
|
||||
{
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mp->name_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"namespace_\" : \"%s\"\n", mp->namespace_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"name_\" : \"%s\",\n", mp->name_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"namespace_\" : \"%s\"\n", mp->namespace_);
|
||||
sb.Append(prefix).Append("}");
|
||||
}
|
||||
|
||||
void MetadataDumper::DumpMetaInterface(StringBuilder& sb, MetaInterface* mi, const String& prefix)
|
||||
{
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mi->name_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"namespace_\" : \"%s\",\n", mi->namespace_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"properties_\" : \"%s\",\n",
|
||||
sb.Append(prefix + tab).AppendFormat("\"name_\" : \"%s\",\n", mi->name_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"namespace_\" : \"%s\",\n", mi->namespace_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"properties_\" : \"%s\",\n",
|
||||
(mi->properties_ & INTERFACE_PROPERTY_ONEWAY) != 0 ? "oneway" : "");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"methodNumber_\" : \"%d\",\n", mi->methodNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"external_\" : \"%d\",\n", mi->external_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"methodNumber_\" : \"%d\",\n", mi->methodNumber_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"external_\" : \"%d\",\n", mi->external_);
|
||||
|
||||
if (mi->methodNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"methods_\" : []\n");
|
||||
sb.Append(prefix + tab).Append("\"methods_\" : []\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"methods_\" : [\n");
|
||||
sb.Append(prefix + tab).Append("\"methods_\" : [\n");
|
||||
for (int i = 0; i < mi->methodNumber_; i++) {
|
||||
DumpMetaMethod(sb, mi->methods_[i], prefix + TAB + TAB);
|
||||
DumpMetaMethod(sb, mi->methods_[i], prefix + tab + tab);
|
||||
if (i != mi->methodNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("]\n");
|
||||
sb.Append("\n" + prefix + tab).Append("]\n");
|
||||
}
|
||||
|
||||
sb.Append(prefix).Append("}");
|
||||
@ -178,25 +178,25 @@ void MetadataDumper::DumpMetaInterface(StringBuilder& sb, MetaInterface* mi, con
|
||||
void MetadataDumper::DumpMetaMethod(StringBuilder& sb, MetaMethod* mm, const String& prefix)
|
||||
{
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mm->name_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"signature_\" : \"%s\",\n", mm->signature_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"properties_\" : \"%s\",\n",
|
||||
sb.Append(prefix + tab).AppendFormat("\"name_\" : \"%s\",\n", mm->name_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"signature_\" : \"%s\",\n", mm->signature_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"properties_\" : \"%s\",\n",
|
||||
(mm->properties_ & METHOD_PROPERTY_ONEWAY) != 0 ? "oneway" : "");
|
||||
MetaType* type = metaComponent_->types_[mm->returnTypeIndex_];
|
||||
sb.Append(prefix + TAB).AppendFormat("\"returnType_\" : \"%s\",\n", DumpMetaType(type).string());
|
||||
sb.Append(prefix + TAB).AppendFormat("\"parameterNumber_\" : \"%d\",\n", mm->parameterNumber_);
|
||||
sb.Append(prefix + tab).AppendFormat("\"returnType_\" : \"%s\",\n", DumpMetaType(type).string());
|
||||
sb.Append(prefix + tab).AppendFormat("\"parameterNumber_\" : \"%d\",\n", mm->parameterNumber_);
|
||||
|
||||
if (mm->parameterNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"parameters_\" : []\n");
|
||||
sb.Append(prefix + tab).Append("\"parameters_\" : []\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"parameters_\" : [\n");
|
||||
sb.Append(prefix + tab).Append("\"parameters_\" : [\n");
|
||||
for (int i = 0; i < mm->parameterNumber_; i++) {
|
||||
DumpMetaParameter(sb, mm->parameters_[i], prefix + TAB + TAB);
|
||||
DumpMetaParameter(sb, mm->parameters_[i], prefix + tab + tab);
|
||||
if (i != mm->parameterNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("]\n");
|
||||
sb.Append("\n" + prefix + tab).Append("]\n");
|
||||
}
|
||||
|
||||
sb.Append(prefix).Append("}");
|
||||
@ -205,8 +205,8 @@ void MetadataDumper::DumpMetaMethod(StringBuilder& sb, MetaMethod* mm, const Str
|
||||
void MetadataDumper::DumpMetaParameter(StringBuilder& sb, MetaParameter* mp, const String& prefix)
|
||||
{
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mp->name_);
|
||||
sb.Append(prefix + TAB).Append("\"attributes_\" : \"");
|
||||
sb.Append(prefix + tab).AppendFormat("\"name_\" : \"%s\",\n", mp->name_);
|
||||
sb.Append(prefix + tab).Append("\"attributes_\" : \"");
|
||||
bool addComma = false;
|
||||
if ((mp->attributes_ & ATTR_IN) == ATTR_IN) {
|
||||
sb.Append("in");
|
||||
@ -217,7 +217,7 @@ void MetadataDumper::DumpMetaParameter(StringBuilder& sb, MetaParameter* mp, con
|
||||
}
|
||||
sb.Append("\",\n");
|
||||
MetaType* type = metaComponent_->types_[mp->typeIndex_];
|
||||
sb.Append(prefix + TAB).AppendFormat("\"type_\" : \"%s\"\n", DumpMetaType(type).string());
|
||||
sb.Append(prefix + tab).AppendFormat("\"type_\" : \"%s\"\n", DumpMetaType(type).string());
|
||||
|
||||
sb.Append(prefix).Append("}");
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ private:
|
||||
|
||||
String DumpMetaType(MetaType* mt);
|
||||
|
||||
static const char* TAB;
|
||||
static const char* tab;
|
||||
MetaComponent* metaComponent_;
|
||||
};
|
||||
} // namespace Idl
|
||||
|
@ -21,46 +21,46 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
const char* MetadataReader::TAG = "MetadataReader";
|
||||
const char* MetadataReader::tag = "MetadataReader";
|
||||
|
||||
std::shared_ptr<MetaComponent> MetadataReader::ReadMetadataFromFile(const String& filePath)
|
||||
{
|
||||
File file(filePath, File::READ);
|
||||
if (!file.IsValid()) {
|
||||
Logger::E(TAG, "Open \"%s\" file failed.", filePath.string());
|
||||
Logger::E(tag, "Open \"%s\" file failed.", filePath.string());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!file.Reset()) {
|
||||
Logger::E(TAG, "Reset \"%s\" file failed.", filePath.string());
|
||||
Logger::E(tag, "Reset \"%s\" file failed.", filePath.string());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MetaComponent header;
|
||||
|
||||
if (!file.ReadData((void*)&header, sizeof(MetaComponent))) {
|
||||
Logger::E(TAG, "Read \"%s\" file failed.", filePath.string());
|
||||
Logger::E(tag, "Read \"%s\" file failed.", filePath.string());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (header.magic_ != METADATA_MAGIC_NUMBER || header.size_ < 0) {
|
||||
Logger::E(TAG, "The metadata in \"%s\" file is bad.", filePath.string());
|
||||
Logger::E(tag, "The metadata in \"%s\" file is bad.", filePath.string());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!file.Reset()) {
|
||||
Logger::E(TAG, "Reset \"%s\" file failed.", filePath.string());
|
||||
Logger::E(tag, "Reset \"%s\" file failed.", filePath.string());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* data = malloc(header.size_);
|
||||
if (data == nullptr) {
|
||||
Logger::E(TAG, "Malloc metadata failed.");
|
||||
Logger::E(tag, "Malloc metadata failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!file.ReadData(data, header.size_)) {
|
||||
Logger::E(TAG, "Read \"%s\" file failed.", filePath.string());
|
||||
Logger::E(tag, "Read \"%s\" file failed.", filePath.string());
|
||||
free(data);
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
static std::shared_ptr<MetaComponent> ReadMetadataFromFile(const String& filePath);
|
||||
|
||||
private:
|
||||
static const char* TAG;
|
||||
static const char* tag;
|
||||
};
|
||||
} // namespace Idl
|
||||
} // namespace OHOS
|
||||
|
@ -291,6 +291,14 @@ String Lexer::DumpToken() const
|
||||
return comment_;
|
||||
case Token::DOT:
|
||||
return ".";
|
||||
default:
|
||||
return DumpTokenSecond();
|
||||
}
|
||||
}
|
||||
|
||||
String Lexer::DumpTokenSecond() const
|
||||
{
|
||||
switch (currentToken_) {
|
||||
case Token::DOUBLE:
|
||||
return "double";
|
||||
case Token::END_OF_FILE:
|
||||
|
@ -61,6 +61,8 @@ public:
|
||||
|
||||
String DumpToken() const;
|
||||
|
||||
String DumpTokenSecond() const;
|
||||
|
||||
int GetTokenLineNumber() const
|
||||
{
|
||||
return tokenLineNo_;
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
const char* Parser::TAG = "Parser";
|
||||
const char* Parser::tag = "Parser";
|
||||
|
||||
Parser::Parser(const Options& options)
|
||||
: options_(options)
|
||||
@ -35,7 +35,7 @@ bool Parser::Parse(const String& sourceFile)
|
||||
{
|
||||
bool ret = lexer_.OpenSourceFile(sourceFile);
|
||||
if (!ret) {
|
||||
Logger::E(TAG, "Fail to open file \"%s\".", sourceFile.string());
|
||||
Logger::E(tag, "Fail to open file \"%s\".", sourceFile.string());
|
||||
return false;
|
||||
}
|
||||
ret = ParseFile();
|
||||
@ -139,6 +139,15 @@ bool Parser::ParseInterface()
|
||||
}
|
||||
}
|
||||
String interfaceFullName;
|
||||
bool middleRes = ParseInterfaceMiddle(token, interfaceFullName);
|
||||
if (!middleRes) {
|
||||
return middleRes;
|
||||
}
|
||||
return ParseInterfaceEnd(token, interfaceFullName, hasProperties, oneway, ret);
|
||||
}
|
||||
|
||||
bool Parser::ParseInterfaceMiddle(Token& token, String& interfaceFullName)
|
||||
{
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::IDENTIFIER) {
|
||||
LogError(token, String::Format("%s is not expected.", lexer_.DumpToken().string()));
|
||||
@ -168,7 +177,11 @@ bool Parser::ParseInterface()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Parser::ParseInterfaceEnd(Token& token, String& interfaceFullName, bool hasProperties, bool oneway, bool ret)
|
||||
{
|
||||
AutoPtr<ASTInterfaceType> interface = new ASTInterfaceType();
|
||||
parsingInterface_ = interface;
|
||||
int index = interfaceFullName.LastIndexOf('.');
|
||||
@ -179,7 +192,6 @@ bool Parser::ParseInterface()
|
||||
interface->SetName(interfaceFullName);
|
||||
interface->SetNamespace(NameSpaceEmpty());
|
||||
}
|
||||
|
||||
// read ';'
|
||||
lexer_.GetToken();
|
||||
if (token == Token::SEMICOLON) {
|
||||
@ -211,9 +223,9 @@ bool Parser::ParseInterface()
|
||||
lexer_.GetToken();
|
||||
module_->AddInterface(interface);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Parser::ParseMethodProperties(bool& oneway, bool& cacheable, int& cacheTime)
|
||||
@ -759,7 +771,7 @@ void Parser::ShowError()
|
||||
{
|
||||
ErrorInfo* error = errors_;
|
||||
while (error != nullptr) {
|
||||
Logger::E(TAG, "%s[line %d, column %d] %s", error->file_.string(),
|
||||
Logger::E(tag, "%s[line %d, column %d] %s", error->file_.string(),
|
||||
error->lineNo_, error->columnNo_, error->message_.string());
|
||||
error = error->next_;
|
||||
}
|
||||
|
@ -59,6 +59,10 @@ private:
|
||||
|
||||
bool ParseInterface();
|
||||
|
||||
bool ParseInterfaceMiddle(Token& token, String& interfaceFullName);
|
||||
|
||||
bool ParseInterfaceEnd(Token& token, String& interfaceFullName, bool hasProperties, bool oneway, bool ret);
|
||||
|
||||
bool ParseMethod(ASTInterfaceType* interface);
|
||||
|
||||
bool ParseMethodProperties(bool& oneway, bool& cacheable, int& cacheTime);
|
||||
@ -98,7 +102,7 @@ private:
|
||||
|
||||
void ShowError();
|
||||
|
||||
static const char* TAG;
|
||||
static const char* tag;
|
||||
|
||||
const Options& options_;
|
||||
AutoPtr<ASTModule> module_;
|
||||
|
@ -33,7 +33,7 @@ constexpr int LINE_MAX_SIZE = 1024;
|
||||
|
||||
using SharedData = struct SharedData {
|
||||
SharedData(int refCount, int size)
|
||||
: refCount_(refCount), size_(size)
|
||||
: refCount_(refCount), shareDataSize(size)
|
||||
{}
|
||||
|
||||
static SharedData* Allocate(int size);
|
||||
@ -53,7 +53,7 @@ using SharedData = struct SharedData {
|
||||
}
|
||||
|
||||
std::atomic<int> refCount_;
|
||||
int size_;
|
||||
int shareDataSize;
|
||||
};
|
||||
|
||||
SharedData* SharedData::Allocate(int size)
|
||||
@ -172,7 +172,7 @@ int String::GetLength() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
return SharedData::GetHeader(string_)->size_;
|
||||
return SharedData::GetHeader(string_)->shareDataSize;
|
||||
}
|
||||
|
||||
char String::operator[](int index) const
|
||||
|
Loading…
Reference in New Issue
Block a user