Skip to content

Commit

Permalink
Type support feedback (#4)
Browse files Browse the repository at this point in the history
* Adressed feedback from PR

* Renamed subpathstackPointer

* Fixing typo, variable names and TypeManagerScope for FindValue.

* Renamed pData in header
  • Loading branch information
Guillermo Leon authored and rajsite committed Jul 10, 2018
1 parent 48562fd commit 1eef26c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
37 changes: 19 additions & 18 deletions source/core/CEntryPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ VIREO_EXPORT Int32 EggShell_PokeMemory(TypeManagerRef tm,
//! Get a reference to the type pointer and data for a symbol.
VIREO_EXPORT EggShellResult EggShell_FindValue(TypeManagerRef tm, const char* viName, const char* eltName, TypeRef* typeRefLocation, void** dataRefLocation)
{
TypeManagerScope scope(tm);
SubString objectName(viName);
SubString path(eltName);
*typeRefLocation = tm->GetObjectElementAddressFromPath(&objectName, &path, dataRefLocation, true);
Expand Down Expand Up @@ -177,7 +178,7 @@ VIREO_EXPORT EggShellResult EggShell_ReadDouble(TypeManagerRef tm, const TypeRef
}
//------------------------------------------------------------
// Write a string value to a symbol. Value will be parsed according to format designated.
VIREO_EXPORT EggShellResult EggShell_WriteValueString(TypeManagerRef tm, const TypeRef typeRef, void* data, const char* format, const char* value)
VIREO_EXPORT EggShellResult EggShell_WriteValueString(TypeManagerRef tm, const TypeRef typeRef, void* pData, const char* format, const char* value)
{
TypeManagerScope scope(tm);

Expand All @@ -189,16 +190,16 @@ VIREO_EXPORT EggShellResult EggShell_WriteValueString(TypeManagerRef tm, const T
EventLog log(EventLog::DevNull);
SubString formatss(format);
TDViaParser parser(tm, &valueString, &log, 1, &formatss, true, true, true);
Int32 error = parser.ParseData(typeRef, data);
Int32 error = parser.ParseData(typeRef, pData);
if (error) {
return kEggSehllResult_UnableToParseData;
return kEggShellResult_UnableToParseData;
}

return kEggShellResult_Success;
}
//------------------------------------------------------------
//! Read a symbol's value as a string. Value will be formatted according to the format designated.
VIREO_EXPORT EggShellResult EggShell_ReadValueString(TypeManagerRef tm, const TypeRef typeRef, void* data, const char* format, UInt8** valueString)
//! Read a symbol's value as a string. Value will be formatted according to designated format.
VIREO_EXPORT EggShellResult EggShell_ReadValueString(TypeManagerRef tm, const TypeRef typeRef, void* pData, const char* format, UInt8** valueString)
{
TypeManagerScope scope(tm);

Expand All @@ -218,8 +219,8 @@ VIREO_EXPORT EggShellResult EggShell_ReadValueString(TypeManagerRef tm, const Ty
if (returnBuffer) {
SubString formatss(format);
TDViaFormatter formatter(returnBuffer, true, 0, &formatss, kJSONEncodingEggShell);
formatter.FormatData(typeRef, data);
// Add an explicit nullptr terminator so it looks like a C string.
formatter.FormatData(typeRef, pData);
// Add an explicit null terminator so it looks like a C string.
returnBuffer->Append((Utf8Char)'\0');
*valueString = returnBuffer->Begin();
return kEggShellResult_Success;
Expand Down Expand Up @@ -285,7 +286,7 @@ VIREO_EXPORT Int32 EggShell_GetArrayDimLength(TypeManagerRef tm, const char* viN
//------------------------------------------------------------
//! Resizes a variable size Array symbol to have new dimension lengths specified by newLengths, it also initializes cells for non-flat data.
VIREO_EXPORT EggShellResult EggShell_ResizeArray(TypeManagerRef tm, const TypeRef typeRef, const void* pData,
Int32 newDimensionsLength, Int32 newDimensions[])
Int32 rank, Int32 dimensionLengths[])
{
TypeManagerScope scope(tm);
if (typeRef == nullptr || !typeRef->IsValid())
Expand All @@ -294,13 +295,13 @@ VIREO_EXPORT EggShellResult EggShell_ResizeArray(TypeManagerRef tm, const TypeRe
if (!typeRef->IsArray())
return kEggShellResult_UnexpectedObjectType;

if (typeRef->Rank() != newDimensionsLength)
if (typeRef->Rank() != rank)
return kEggShellResult_MismatchedArrayRank;

TypedArrayCoreRef arrayObject = *(TypedArrayCoreRef*)pData;
VIREO_ASSERT(TypedArrayCore::ValidateHandle(arrayObject));

if (!arrayObject->ResizeDimensions(newDimensionsLength, newDimensions, true, false)) {
if (!arrayObject->ResizeDimensions(rank, dimensionLengths, true, false)) {
return kEggShellResult_UnableToCreateReturnBuffer;
}
return kEggShellResult_Success;
Expand Down Expand Up @@ -373,12 +374,12 @@ VIREO_EXPORT void* Data_GetArrayBegin(const void* pData)
//------------------------------------------------------------
//! Get the values for dimensions of the array. Assumes dimensions target is of length equal to rank
//! Caller is expected to allocate an array dimensions of size array rank for the duration of function invocation.
VIREO_EXPORT void Data_GetArrayDimensions(const void* pData, IntIndex dimensions[])
VIREO_EXPORT void Data_GetArrayDimensions(const void* pData, IntIndex dimensionsLengths[])
{
TypedArrayCoreRef arrayObject = *(TypedArrayCoreRef*)pData;
VIREO_ASSERT(TypedArrayCore::ValidateHandle(arrayObject));
for (int i = 0; i < arrayObject->Rank(); i++) {
dimensions[i] = arrayObject->GetLength(i);
dimensionsLengths[i] = arrayObject->GetLength(i);
}
}
//------------------------------------------------------------
Expand Down Expand Up @@ -578,12 +579,12 @@ VIREO_EXPORT const char* TypeRef_Name(TypeManagerRef tm, TypeRef typeRef)
STACK_VAR(String, tempReturn);
returnBuffer = tempReturn.DetachValue();
} else {
returnBuffer->Resize1D(0);
returnBuffer->Resize1D(name.Length() + 1);
}

if (returnBuffer) {
returnBuffer->AppendSubString(&name);
// Add an explicit nullptr terminator so it looks like a C string.
returnBuffer->CopyFromSubString(&name);
// Add an explicit null terminator so it looks like a C string.
returnBuffer->Append((Utf8Char)'\0');
return (const char*) returnBuffer->Begin();
}
Expand All @@ -603,12 +604,12 @@ VIREO_EXPORT const char* TypeRef_ElementName(TypeManagerRef tm, TypeRef typeRef)
STACK_VAR(String, tempReturn);
returnBuffer = tempReturn.DetachValue();
} else {
returnBuffer->Resize1D(0);
returnBuffer->Resize1D(name.Length() + 1);
}

if (returnBuffer) {
returnBuffer->AppendSubString(&name);
// Add an explicit nullptr terminator so it looks like a C string.
returnBuffer->CopyFromSubString(&name);
// Add an explicit null terminator so it looks like a C string.
returnBuffer->Append((Utf8Char)'\0');
return (const char*) returnBuffer->Begin();
}
Expand Down
2 changes: 1 addition & 1 deletion source/core/StringUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ void SubString::TrimQuotedString(TokenTraits tt)
}
}
//------------------------------------------------------------
IntIndex SubString::FindFirstMatch(SubString* searchString, IntIndex offset, Boolean ignoreCase)
IntIndex SubString::FindFirstMatch(const SubString* searchString, IntIndex offset, Boolean ignoreCase)
{
IntIndex searchStringLength = searchString->Length();
if (Length() == 0 || searchStringLength > Length())
Expand Down
3 changes: 1 addition & 2 deletions source/core/TypeAndDataManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,7 @@ Boolean TypeCommon::IsAnalogWaveform()
TypeRef t = this;
while (t) {
SubString typeName = t->Name();
SubString analogTypess(TypeAnalogWaveform);
if (typeName.FindFirstMatch(&analogTypess, 0, false) == 0) {
if (typeName.FindFirstMatch(&TypeAnalogWaveform, 0, false) == 0) {
return true;
}
t = t->BaseType();
Expand Down
8 changes: 4 additions & 4 deletions source/include/CEntryPoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef enum {
kEggShellResult_UnableToCreateReturnBuffer = 4,
kEggShellResult_InvalidTypeRef = 5,
kEggShellResult_MismatchedArrayRank = 6,
kEggSehllResult_UnableToParseData = 7,
kEggShellResult_UnableToParseData = 7,
} EggShellResult;
//------------------------------------------------------------
//! TypeManager functions
Expand All @@ -43,20 +43,20 @@ VIREO_EXPORT EggShellResult EggShell_FindSubValue(TypeManagerRef tm, const TypeR
TypeRef* typeRefLocation, void** dataRefLocation);
VIREO_EXPORT EggShellResult EggShell_WriteDouble(TypeManagerRef tm, const TypeRef actualType, void* pData, Double value);
VIREO_EXPORT EggShellResult EggShell_ReadDouble(TypeManagerRef tm, const TypeRef actualType, const void* pData, Double* result);
VIREO_EXPORT EggShellResult EggShell_WriteValueString(TypeManagerRef tm, TypeRef typeRef, void* data, const char* format, const char* value);
VIREO_EXPORT EggShellResult EggShell_WriteValueString(TypeManagerRef tm, TypeRef typeRef, void* pData, const char* format, const char* value);
VIREO_EXPORT EggShellResult EggShell_ReadValueString(TypeManagerRef tm, TypeRef typeRef, void* pData, const char* format, UInt8** valueString);
VIREO_EXPORT EggShellResult EggShell_GetPointer(TypeManagerRef tm,
const char* viName, const char* elementName, void** dataPointer, void** typePointer);
VIREO_EXPORT Int32 EggShell_GetArrayDimLength(TypeManagerRef tm, const char* viName, const char* eltName, Int32 dim);
VIREO_EXPORT EggShellResult EggShell_ResizeArray(TypeManagerRef tm, const TypeRef actualType, const void* pData,
Int32 newDimensionsLength, Int32 newDimensions[]);
Int32 rank, Int32 dimensionLengths[]);
VIREO_EXPORT EggShellResult Data_ValidateArrayType(TypeManagerRef tm, TypeRef typeRef);
VIREO_EXPORT void* Data_GetStringBegin(StringRef stringObject);
VIREO_EXPORT Int32 Data_GetStringLength(StringRef stringObject);
VIREO_EXPORT EggShellResult Data_GetArrayMetadata(TypeManagerRef tm,
TypedArrayCoreRef arrayObject, char** arrayTypeName, Int32* arrayRank, unsigned char** arrayBegin);
VIREO_EXPORT void* Data_GetArrayBegin(const void* pData);
VIREO_EXPORT void Data_GetArrayDimensions(const void* pData, IntIndex dimensions[]);
VIREO_EXPORT void Data_GetArrayDimensions(const void* pData, IntIndex dimensionsLengths[]);
VIREO_EXPORT Int32 Data_GetArrayLength(const void* pData);
VIREO_EXPORT Int32 Data_GetArrayDimLength(TypeManagerRef tm, TypedArrayCoreRef arrayObject, Int32 dim);
VIREO_EXPORT Int32 Data_ResizeArray(TypeManagerRef tm, TypedArrayCoreRef arrayObject, Int32 rank, Int32* newLengths);
Expand Down
2 changes: 1 addition & 1 deletion source/include/StringUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class SubString : public SubVector<Utf8Char>
//! based on previously determined token trait.
void TrimQuotedString(TokenTraits tt);

IntIndex FindFirstMatch(SubString* searchString, IntIndex offset, Boolean ignoreCase);
IntIndex FindFirstMatch(const SubString* searchString, IntIndex offset, Boolean ignoreCase);
};

//------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions source/io/module_eggShell.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,19 @@
return valueRef;
};

Module.eggShell.findSubValueRef = publicAPI.eggShell.findSubValueRef = function (valueRef, path) {
Module.eggShell.findSubValueRef = publicAPI.eggShell.findSubValueRef = function (valueRef, subPath) {
var stack = Module.stackSave();

var pathStackPointer = Module.coreHelpers.writeJSStringToStack(path);
var subPathStackPointer = Module.coreHelpers.writeJSStringToStack(subPath);
var typeStackPointer = Module.stackAlloc(POINTER_SIZE);
var dataStackPointer = Module.stackAlloc(POINTER_SIZE);

var eggShellResult = Module._EggShell_FindSubValue(Module.eggShell.v_userShell, valueRef.typeRef, valueRef.dataRef, pathStackPointer, typeStackPointer, dataStackPointer);
var eggShellResult = Module._EggShell_FindSubValue(Module.eggShell.v_userShell, valueRef.typeRef, valueRef.dataRef, subPathStackPointer, typeStackPointer, dataStackPointer);
if (eggShellResult !== EGGSHELL_RESULT.SUCCESS) {
throw new Error('A ValueRef could not be made for the following reason: ' + eggShellResultEnum[eggShellResult] +
' (error code: ' + eggShellResult + ')' +
' (type name: ' + Module.typeHelpers.typeName(valueRef.typeRef) + ')' +
' (path: ' + path + ')');
' (subpath: ' + subPath + ')');
}

var typeRef = Module.getValue(typeStackPointer, 'i32');
Expand Down

0 comments on commit 1eef26c

Please sign in to comment.