Small speed improvement int trim by using stack (and DFS) instead of queue (and BFS) for remove and collapse, finally fix the unknown escape '\*' error
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import symbol:*
|
import symbol:*
|
||||||
import tree:*
|
import tree:*
|
||||||
import vector:*
|
import vector:*
|
||||||
|
import queue:*
|
||||||
import stack:*
|
import stack:*
|
||||||
import map:*
|
import map:*
|
||||||
import util:*
|
import util:*
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import symbol:*
|
import symbol:*
|
||||||
import tree:*
|
import tree:*
|
||||||
import vector:*
|
import vector:*
|
||||||
import queue:*
|
import stack:*
|
||||||
import map:*
|
import map:*
|
||||||
import util:*
|
import util:*
|
||||||
import string:*
|
import string:*
|
||||||
@@ -151,7 +151,7 @@ fun trim(parse_tree: *tree<symbol>): *tree<symbol> {
|
|||||||
return parse_tree
|
return parse_tree
|
||||||
}
|
}
|
||||||
fun remove_node(remove: symbol, parse_tree: *tree<symbol>) {
|
fun remove_node(remove: symbol, parse_tree: *tree<symbol>) {
|
||||||
var to_process = queue<*tree<symbol>>()
|
var to_process = stack<*tree<symbol>>()
|
||||||
to_process.push(parse_tree)
|
to_process.push(parse_tree)
|
||||||
while(!to_process.empty()) {
|
while(!to_process.empty()) {
|
||||||
var node = to_process.pop()
|
var node = to_process.pop()
|
||||||
@@ -174,7 +174,7 @@ fun remove_node(remove: symbol, parse_tree: *tree<symbol>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun collapse_node(remove: symbol, parse_tree: *tree<symbol>) {
|
fun collapse_node(remove: symbol, parse_tree: *tree<symbol>) {
|
||||||
var to_process = queue<*tree<symbol>>()
|
var to_process = stack<*tree<symbol>>()
|
||||||
to_process.push(parse_tree)
|
to_process.push(parse_tree)
|
||||||
while(!to_process.empty()) {
|
while(!to_process.empty()) {
|
||||||
var node = to_process.pop()
|
var node = to_process.pop()
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ fun get_builtin_function(name: string, param_types: vector<*type>, syntax: *tree
|
|||||||
}
|
}
|
||||||
if (name == "&" && param_types.size == 1)
|
if (name == "&" && param_types.size == 1)
|
||||||
return ast_function_ptr(name, type_ptr(param_types, param_types[0]->clone_with_increased_indirection()), vector<*ast_node>(), false)
|
return ast_function_ptr(name, type_ptr(param_types, param_types[0]->clone_with_increased_indirection()), vector<*ast_node>(), false)
|
||||||
if (name == "\*" && param_types.size == 1) {
|
if (name == "*" && param_types.size == 1) {
|
||||||
if (param_types[0]->indirection == 0)
|
if (param_types[0]->indirection == 0)
|
||||||
error(syntax, string("drereferencing not a pointer: ") + name)
|
error(syntax, string("drereferencing not a pointer: ") + name)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ obj stack<T> (Object, Serializable) {
|
|||||||
data.construct()
|
data.construct()
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
fun construct(ammt: int): *stack<T> {
|
||||||
|
data.construct(ammt)
|
||||||
|
return this
|
||||||
|
}
|
||||||
fun copy_construct(other: *stack<T>) {
|
fun copy_construct(other: *stack<T>) {
|
||||||
data.copy_construct(&other->data)
|
data.copy_construct(&other->data)
|
||||||
}
|
}
|
||||||
@@ -59,6 +63,9 @@ obj stack<T> (Object, Serializable) {
|
|||||||
fun size(): int {
|
fun size(): int {
|
||||||
return data.size
|
return data.size
|
||||||
}
|
}
|
||||||
|
fun available(): int {
|
||||||
|
return data.available
|
||||||
|
}
|
||||||
fun empty():bool {
|
fun empty():bool {
|
||||||
return data.size == 0
|
return data.size == 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user