Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plamen5kov/refactored metadata reader #14

Merged
merged 1 commit into from
Feb 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ LOCAL_SRC_FILES := com_tns_Platform.cpp com_tns_JsDebugger.cpp \
ArgConverter.cpp JsArgToArrayConverter.cpp JsArgConverter.cpp V8GlobalHelpers.cpp V8StringConstants.cpp \
FieldAccessor.cpp ArrayElementAccessor.cpp \
ExceptionUtil.cpp Util.cpp Logger.cpp \
ObjectManager.cpp CastFunctions.cpp WeakRef.cpp
ObjectManager.cpp CastFunctions.cpp WeakRef.cpp \
MetadataMethodInfo.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_LDLIBS := -llog -landroid
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
Expand Down
6 changes: 2 additions & 4 deletions src/jni/MetadataEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace tns
struct MetadataEntry
{
MetadataEntry()
: isMember(false), name(std::string()), treeNode(nullptr), sig(std::string()), paramCount(0), isStatic(false), declaringType(std::string())
: isTypeMember(false), name(std::string()), treeNode(nullptr), sig(std::string()), paramCount(0), isStatic(false), declaringType(std::string())
{
}
MetadataTreeNode *treeNode;
Expand All @@ -31,10 +31,8 @@ namespace tns
int paramCount;
bool isStatic;
bool isFinal;
bool isMember;
bool isTypeMember;
};
}



#endif /* METADATAENTRY_H_ */
29 changes: 29 additions & 0 deletions src/jni/MetadataFieldInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef METADATAFIELDINFO_H_
#define METADATAFIELDINFO_H_

namespace tns
{
struct __attribute__ ((__packed__)) FieldInfo
{
FieldInfo()
: nameOffset(0), nodeId(0), finalModifier(0)
{
}

uint32_t nameOffset;
uint16_t nodeId;
uint8_t finalModifier;
};

struct __attribute__ ((__packed__)) StaticFieldInfo : FieldInfo
{
StaticFieldInfo()
: FieldInfo(), declaringType(0)
{
}

uint16_t declaringType;
};
}

#endif /* METADATAFIELDINFO_H_ */
88 changes: 88 additions & 0 deletions src/jni/MetadataMethodInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "MetadataMethodInfo.h"
#include "MetadataReader.h"

using namespace tns;

std::string MethodInfo::GetName()
{
uint32_t nameOfffset = *reinterpret_cast<uint32_t*>(m_pData);
string methodName = m_reader->ReadName(nameOfffset);
m_pData += sizeof(uint32_t);

return methodName;
}

uint16_t MethodInfo::GetSignatureLength()
{
m_signatureLength = *reinterpret_cast<uint16_t*>(m_pData);
m_pData += sizeof(uint16_t);

return m_signatureLength;
}

std::string MethodInfo::GetSignature() //use nodeId's to read the whole signature
{
uint16_t *nodeIdPtr = reinterpret_cast<uint16_t*>(m_pData);
string signature = "(";
string ret;
for (int i=0; i< m_signatureLength; i++)
{
uint16_t nodeId = *nodeIdPtr++;
string curArgTypeName = m_reader->ReadTypeName(nodeId);
MetadataTreeNode *node = m_reader->GetNodeById(nodeId);

uint8_t nodeType = m_reader->GetNodeType(node);
bool isRefType = m_reader->IsNodeTypeClass(nodeType) || m_reader->IsNodeTypeInterface(nodeType);
if (i == 0)
{
if ((curArgTypeName[0] != '[') && isRefType)
{
ret.append("L");
}
ret.append(curArgTypeName);
if ((curArgTypeName[0] != '[') && isRefType)
{
ret.append(";");
}
}
else
{
if ((curArgTypeName[0] != '[') && isRefType)
{
signature.append("L");
}
signature.append(curArgTypeName);
if ((curArgTypeName[0] != '[') && isRefType)
{
signature.append(";");
}
}
}
if (ret.empty())
{
ret = "V";
}
signature += ")" + ret;

int sizeofReadNodeIds = m_signatureLength * sizeof(uint16_t);
m_pData += sizeofReadNodeIds;

return signature;
}

std::string MethodInfo::GetDeclaringType()
{
uint16_t *declaringTypePtr = reinterpret_cast<uint16_t*>(m_pData);
uint16_t nodeId = *declaringTypePtr;

string declTypeName = m_reader->ReadTypeName(nodeId);

m_pData += sizeof(uint16_t);

return declTypeName;
}

int MethodInfo::GetSizeOfReadMethodInfo()
{
return m_pData - m_pStartData;
}
38 changes: 38 additions & 0 deletions src/jni/MetadataMethodInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef METHODINFOSMARTPOINTER_H_
#define METHODINFOSMARTPOINTER_H_

#include "MetadataReader.h"

#include <iostream>
#include <string>
#include <vector>

using namespace std;

namespace tns
{
class MethodInfo
{
public:
MethodInfo(uint8_t *pValue, MetadataReader *reader)
: m_pData(pValue), m_pStartData(pValue), m_reader(reader), m_signatureLength(0)
{
};

std::string GetName();
uint16_t GetSignatureLength();
std::string GetSignature();
std::string GetDeclaringType();//used only for static methods

int GetSizeOfReadMethodInfo();

private:
uint8_t *m_pData; //where we currently read
uint8_t *m_pStartData; // pointer to the beginning
uint16_t m_signatureLength;
MetadataReader *m_reader;
};
}


#endif /* METHODINFOSMARTPOINTER_H_ */
20 changes: 10 additions & 10 deletions src/jni/MetadataNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ void MetadataNode::GetterCallback(Local<String> property, const PropertyCallback
{
auto first = candidates.front();

if (first.isMember)
if (first.isTypeMember)
{
if (first.type == NodeType::Method)
{
Expand Down Expand Up @@ -1142,7 +1142,7 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForTypeWithCustomMetada
case 'F':
case 'M':
entry.name = name;
entry.isMember = true;
entry.isTypeMember = true;
entry.type = (chKind == 'F') ? NodeType::Field : NodeType::Method;
entry.sig = signature;
entry.paramCount = paramCount;
Expand Down Expand Up @@ -1182,7 +1182,7 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForTypeWithoutCustomMet
curPtr += sizeof(uint16_t);
for (int i = 0; i < instanceMethodCout; i++)
{
MetadataEntry entry = s_metadataReader.ReadInstanceMethodEntry(curPtr);
MetadataEntry entry = s_metadataReader.ReadInstanceMethodEntry(&curPtr);

if (entry.name == propName)
{
Expand All @@ -1196,7 +1196,7 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForTypeWithoutCustomMet
curPtr += sizeof(uint16_t);
for (int i = 0; i < staticMethodCout; i++)
{
MetadataEntry entry = s_metadataReader.ReadStaticMethodEntry(curPtr);
MetadataEntry entry = s_metadataReader.ReadStaticMethodEntry(&curPtr);

if (entry.name == propName)
{
Expand All @@ -1211,14 +1211,14 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForTypeWithoutCustomMet
extendEntry.name = "extend";
extendEntry.type = NodeType::Method;
extendEntry.treeNode = node->m_treeNode;
extendEntry.isMember = true;
extendEntry.isTypeMember = true;
candidates.push_back(extendEntry);

MetadataEntry extendsEntry;
extendsEntry.name = "extends";
extendsEntry.type = NodeType::Method;
extendsEntry.treeNode = node->m_treeNode;
extendsEntry.isMember = true;
extendsEntry.isTypeMember = true;
candidates.push_back(extendsEntry);
}

Expand All @@ -1227,7 +1227,7 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForTypeWithoutCustomMet
curPtr += sizeof(uint16_t);
for (int i = 0; i < instanceFieldCout; i++)
{
MetadataEntry entry = s_metadataReader.ReadInstanceFieldEntry(curPtr);
MetadataEntry entry = s_metadataReader.ReadInstanceFieldEntry(&curPtr);

if (entry.name == propName)
{
Expand All @@ -1241,7 +1241,7 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForTypeWithoutCustomMet
curPtr += sizeof(uint16_t);
for (int i = 0; i < staticFieldCout; i++)
{
MetadataEntry entry = s_metadataReader.ReadStaticFieldEntry(curPtr);
MetadataEntry entry = s_metadataReader.ReadStaticFieldEntry(&curPtr);

if (entry.name == propName)
{
Expand All @@ -1258,7 +1258,7 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForTypeWithoutCustomMet
classEntry.declaringType = node->m_name;
classEntry.type = NodeType::StaticField;
classEntry.treeNode = node->m_treeNode;
classEntry.isMember = true;
classEntry.isTypeMember = true;
classEntry.isStatic = true;
candidates.push_back(classEntry);
}
Expand Down Expand Up @@ -1306,7 +1306,7 @@ vector<MetadataEntry> MetadataNode::GetMetadataCandidatesForArray(MetadataNode *
classEntry.declaringType = node->m_name;
classEntry.type = NodeType::Field;
classEntry.treeNode = node->m_treeNode;
classEntry.isMember = true;
classEntry.isTypeMember = true;
candidates.push_back(classEntry);
}

Expand Down
Loading