mirror of
https://github.com/vlang/v.git
synced 2025-09-14 01:47:30 -04:00
tools: implement an -s option for v ast
, to skip all nodes with default values like [], {}, 0, false; with it v ast -pts examples/hello_world.v | wc -l
is 36 lines
This commit is contained in:
parent
eecaa64e9d
commit
94a97f6173
@ -1,114 +1,75 @@
|
|||||||
module main
|
module main
|
||||||
|
|
||||||
import json
|
import json.cjson
|
||||||
|
|
||||||
struct UseJson {
|
type Node = C.cJSON
|
||||||
x int
|
|
||||||
|
fn as_n(p &cjson.Node) &Node {
|
||||||
|
return unsafe { &Node(p) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suppress_json_warning() {
|
fn as_c(p &Node) &cjson.Node {
|
||||||
json.encode(UseJson{})
|
return unsafe { &cjson.Node(p) }
|
||||||
}
|
|
||||||
|
|
||||||
// struct C.cJSON {}
|
|
||||||
fn C.cJSON_CreateObject() &C.cJSON
|
|
||||||
|
|
||||||
fn C.cJSON_CreateArray() &C.cJSON
|
|
||||||
|
|
||||||
// fn C.cJSON_CreateBool(bool) &C.cJSON
|
|
||||||
fn C.cJSON_CreateTrue() &C.cJSON
|
|
||||||
|
|
||||||
fn C.cJSON_CreateFalse() &C.cJSON
|
|
||||||
|
|
||||||
fn C.cJSON_CreateNull() &C.cJSON
|
|
||||||
|
|
||||||
// fn C.cJSON_CreateNumber() &C.cJSON
|
|
||||||
// fn C.cJSON_CreateString() &C.cJSON
|
|
||||||
fn C.cJSON_CreateRaw(&u8) &C.cJSON
|
|
||||||
|
|
||||||
fn C.cJSON_IsInvalid(voidptr) bool
|
|
||||||
|
|
||||||
fn C.cJSON_IsFalse(voidptr) bool
|
|
||||||
|
|
||||||
// fn C.cJSON_IsTrue(voidptr) bool
|
|
||||||
fn C.cJSON_IsBool(voidptr) bool
|
|
||||||
|
|
||||||
fn C.cJSON_IsNull(voidptr) bool
|
|
||||||
|
|
||||||
fn C.cJSON_IsNumber(voidptr) bool
|
|
||||||
|
|
||||||
fn C.cJSON_IsString(voidptr) bool
|
|
||||||
|
|
||||||
fn C.cJSON_IsArray(voidptr) bool
|
|
||||||
|
|
||||||
fn C.cJSON_IsObject(voidptr) bool
|
|
||||||
|
|
||||||
fn C.cJSON_IsRaw(voidptr) bool
|
|
||||||
|
|
||||||
fn C.cJSON_AddItemToObject(voidptr, &u8, voidptr)
|
|
||||||
|
|
||||||
fn C.cJSON_AddItemToArray(voidptr, voidptr)
|
|
||||||
|
|
||||||
fn C.cJSON_Delete(voidptr)
|
|
||||||
|
|
||||||
fn C.cJSON_Print(voidptr) &u8
|
|
||||||
|
|
||||||
@[inline]
|
|
||||||
fn create_object() &C.cJSON {
|
|
||||||
return C.cJSON_CreateObject()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline]
|
@[inline]
|
||||||
fn create_array() &C.cJSON {
|
fn create_object() &Node {
|
||||||
return C.cJSON_CreateArray()
|
return as_n(cjson.create_object())
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline]
|
@[inline]
|
||||||
fn create_string(val string) &C.cJSON {
|
fn create_array() &Node {
|
||||||
return C.cJSON_CreateString(val.str)
|
return as_n(cjson.create_array())
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline]
|
@[inline]
|
||||||
fn create_number(val f64) &C.cJSON {
|
fn create_string(val string) &Node {
|
||||||
return C.cJSON_CreateNumber(val)
|
return as_n(cjson.create_string(val))
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline]
|
@[inline]
|
||||||
fn create_bool(val bool) &C.cJSON {
|
fn create_number(val f64) &Node {
|
||||||
return C.cJSON_CreateBool(val)
|
return as_n(cjson.create_number(val))
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline]
|
@[inline]
|
||||||
fn create_true() &C.cJSON {
|
fn create_bool(val bool) &Node {
|
||||||
return C.cJSON_CreateTrue()
|
return as_n(cjson.create_bool(val))
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline]
|
@[inline]
|
||||||
fn create_false() &C.cJSON {
|
fn create_true() &Node {
|
||||||
return C.cJSON_CreateFalse()
|
return as_n(cjson.create_true())
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline]
|
@[inline]
|
||||||
fn create_null() &C.cJSON {
|
fn create_false() &Node {
|
||||||
return C.cJSON_CreateNull()
|
return as_n(cjson.create_false())
|
||||||
|
}
|
||||||
|
|
||||||
|
@[inline]
|
||||||
|
fn create_null() &Node {
|
||||||
|
return as_n(cjson.create_null())
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline]
|
@[inline]
|
||||||
fn delete(b voidptr) {
|
fn delete(b voidptr) {
|
||||||
C.cJSON_Delete(b)
|
unsafe { cjson.delete(b) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline]
|
@[inline]
|
||||||
fn add_item_to_object(obj &C.cJSON, key string, item &C.cJSON) {
|
fn add_item_to_object(mut obj Node, key string, item &Node) {
|
||||||
C.cJSON_AddItemToObject(obj, key.str, item)
|
mut o := unsafe { &cjson.Node(obj) }
|
||||||
|
o.add_item_to_object(key, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
@[inline]
|
@[inline]
|
||||||
fn add_item_to_array(obj &C.cJSON, item &C.cJSON) {
|
fn add_item_to_array(mut obj Node, item &Node) {
|
||||||
C.cJSON_AddItemToArray(obj, item)
|
mut o := as_c(obj)
|
||||||
|
o.add_item_to_array(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn json_print(json_ &C.cJSON) string {
|
fn json_print(mut obj Node) string {
|
||||||
s := C.cJSON_Print(json_)
|
mut o := as_c(obj)
|
||||||
return unsafe { tos3(s) }
|
return o.print()
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -12,6 +12,18 @@ module cjson
|
|||||||
#flag @VEXEROOT/thirdparty/cJSON/cJSON.o
|
#flag @VEXEROOT/thirdparty/cJSON/cJSON.o
|
||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
|
|
||||||
|
@[flag]
|
||||||
|
pub enum CJsonType {
|
||||||
|
t_false
|
||||||
|
t_true
|
||||||
|
t_null
|
||||||
|
t_number
|
||||||
|
t_string
|
||||||
|
t_array
|
||||||
|
t_object
|
||||||
|
t_raw
|
||||||
|
}
|
||||||
|
|
||||||
@[typedef]
|
@[typedef]
|
||||||
pub struct C.cJSON {
|
pub struct C.cJSON {
|
||||||
pub:
|
pub:
|
||||||
@ -19,7 +31,7 @@ pub:
|
|||||||
prev &C.cJSON
|
prev &C.cJSON
|
||||||
child &C.cJSON // An array or object item will have a child pointer pointing to a chain of the items in the array/object
|
child &C.cJSON // An array or object item will have a child pointer pointing to a chain of the items in the array/object
|
||||||
|
|
||||||
type int // The type of the item, as above
|
type CJsonType // The type of the item, as above
|
||||||
|
|
||||||
valueint int // writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead
|
valueint int // writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead
|
||||||
valuedouble f64 // The item's number, if type==cJSON_Number
|
valuedouble f64 // The item's number, if type==cJSON_Number
|
||||||
|
Loading…
x
Reference in New Issue
Block a user