Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bipscript
bipscript
Commits
bfdf37d1
Commit
bfdf37d1
authored
Apr 14, 2021
by
jhammen
Browse files
json object better warning messages when verbose
parent
527e4ac8
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/jsontype.h
View file @
bfdf37d1
...
...
@@ -156,9 +156,6 @@ class JsonBindHandler {
}
void
parse
(
json_stream
*
s
)
{
if
(
mverbose
)
{
printf
(
"start binding with root type @ %d
\n
"
,
typeloc
[
0
]);
}
bool
done
=
false
;
enum
json_type
type
=
json_next
(
s
);
while
(
!
done
)
{
...
...
@@ -179,15 +176,9 @@ class JsonBindHandler {
const
char
*
numstr
=
json_get_string
(
s
,
0
);
if
(
strchr
(
numstr
,
'.'
))
{
double
number
=
json_get_number
(
s
);
if
(
mverbose
)
{
printf
(
"parsed double %f
\n
"
,
number
);
}
sq_pushfloat
(
vm
,
json_get_number
(
s
));
}
else
{
long
long
number
=
std
::
stoll
(
numstr
);
if
(
mverbose
)
{
printf
(
"parsed integer %lld
\n
"
,
number
);
}
sq_pushinteger
(
vm
,
number
);
}
appendToParent
();
...
...
@@ -196,9 +187,6 @@ class JsonBindHandler {
case
JSON_STRING
:
{
const
char
*
str
=
json_get_string
(
s
,
0
);
if
(
parent
==
OBJECT
)
{
if
(
mverbose
)
{
printf
(
"key = '%s' "
,
str
);
}
sq_pushstring
(
vm
,
str
,
strlen
(
str
));
// pop key and push attributes table for this class
uint32_t
type
=
0
;
...
...
@@ -206,9 +194,6 @@ class JsonBindHandler {
// attributes table for this key now on stack
sq_pushstring
(
vm
,
"type"
,
4
);
if
(
SQ_SUCCEEDED
(
sq_get
(
vm
,
-
2
)))
{
if
(
mverbose
)
{
printf
(
"found type mapping @ %d
\n
"
,
typeloc
[
typetop
]);
}
sq_remove
(
vm
,
-
2
);
// remove attributes table
if
(
sq_gettype
(
vm
,
-
1
)
==
OT_ARRAY
)
{
sq_pushinteger
(
vm
,
0
);
// [0] array index
...
...
@@ -217,22 +202,21 @@ class JsonBindHandler {
}
type
=
sq_gettop
(
vm
);
// store location of typedef
}
else
if
(
mverbose
)
{
printf
(
"f
ound attributes, no type mapping found
\n
"
);
printf
(
"f
ield has no type mapping, mapping to table
\n
"
);
}
}
else
{
sq_poptop
(
vm
);
sq_pushnull
(
vm
);
// no type mapping
if
(
mverbose
)
{
printf
(
"no attributes found
\n
"
);
const
SQChar
*
name
;
sq_getstring
(
vm
,
-
1
,
&
name
);
printf
(
"warning: field %s does not exist in object
\n
"
,
name
);
}
sq_poptop
(
vm
);
sq_pushnull
(
vm
);
// no type mapping
}
sq_pushstring
(
vm
,
str
,
strlen
(
str
));
typeloc
[
++
typetop
]
=
type
;
parent
=
KEY
;
}
else
{
if
(
mverbose
)
{
printf
(
"parsed string value %s
\n
"
,
str
);
}
sq_pushstring
(
vm
,
str
,
strlen
(
str
));
appendToParent
();
}
...
...
@@ -244,13 +228,6 @@ class JsonBindHandler {
depth
++
;
break
;
case
JSON_OBJECT
:
{
if
(
mverbose
)
{
printf
(
"starting object "
);
}
// TODO: check if mapped
if
(
mverbose
)
{
printf
(
"with mapping @ %d
\n
"
,
typeloc
[
typetop
]);
}
uint32_t
type
=
typeloc
[
typetop
];
if
(
type
)
{
sq_createinstance
(
vm
,
type
);
...
...
@@ -262,15 +239,9 @@ class JsonBindHandler {
break
;
}
case
JSON_OBJECT_END
:
if
(
mverbose
)
{
printf
(
"end of current object, "
);
}
endComposite
();
break
;
case
JSON_ARRAY_END
:
if
(
mverbose
)
{
printf
(
"end of current array, "
);
}
endComposite
();
break
;
case
JSON_ERROR
:
...
...
@@ -296,33 +267,28 @@ class JsonBindHandler {
private:
void
appendToParent
()
{
if
(
parent
==
ARRAY
)
{
if
(
mverbose
)
{
printf
(
"append to current array
\n
"
);
}
sq_arrayappend
(
vm
,
-
2
);
}
else
if
(
parent
==
KEY
)
{
if
(
typetop
&&
typeloc
[
typetop
-
1
])
{
// in a mapped object
if
(
SQ_FAILED
(
sq_set
(
vm
,
-
4
)))
{
if
(
mverbose
)
{
printf
(
"bind to object failed
\n
"
);
const
SQChar
*
name
;
sq_getstring
(
vm
,
-
2
,
&
name
);
printf
(
"bind to object with key %s failed
\n
"
,
name
);
}
sq_pop
(
vm
,
3
);
// pop type, key, value
}
else
{
if
(
mverbose
)
{
printf
(
"bound value to object
\n
"
);
}
sq_pop
(
vm
,
1
);
// pop type for this key
}
}
else
{
// in a table
if
(
SQ_FAILED
(
sq_newslot
(
vm
,
-
4
,
false
)))
{
if
(
mverbose
)
{
printf
(
"bind to table failed
\n
"
);
const
SQChar
*
name
;
sq_getstring
(
vm
,
-
2
,
&
name
);
printf
(
"bind to object with key %s failed
\n
"
,
name
);
}
sq_pop
(
vm
,
3
);
// pop type, key, value
}
else
{
if
(
mverbose
)
{
printf
(
"bound value to table
\n
"
);
}
sq_pop
(
vm
,
1
);
// pop type for this key
}
}
...
...
@@ -332,30 +298,20 @@ class JsonBindHandler {
}
// end an object or array
void
endComposite
()
{
if
(
--
depth
)
{
if
(
--
depth
)
{
// else parse complete
// pop parent
switch
(
sq_gettype
(
vm
,
-
2
))
{
case
OT_STRING
:
{
// = key within object
if
(
mverbose
)
{
printf
(
"parent is object
\n
"
);
}
parent
=
KEY
;
break
;
}
case
OT_ARRAY
:
parent
=
ARRAY
;
if
(
mverbose
)
{
printf
(
"parent is array
\n
"
);
}
break
;
default:
throw
std
::
logic_error
(
"JSON parse error: unknown type not supported here"
);
}
appendToParent
();
}
else
{
if
(
mverbose
)
{
printf
(
"parse complete
\n
"
);
}
}
}
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment