fix reference type inference
This commit is contained in:
@@ -709,7 +709,8 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
|
||||
// for type inferencing
|
||||
if (!identifierType) {
|
||||
if (toAssign) {
|
||||
identifierType = toAssign->getDataRef()->valueType;
|
||||
// no reference variables
|
||||
identifierType = toAssign->getDataRef()->valueType->withoutReference();
|
||||
newIdentifier->getDataRef()->valueType = identifierType;
|
||||
} else
|
||||
throw "have to inference but no expression";
|
||||
|
||||
@@ -568,7 +568,7 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
||||
output.value += ValueTypeToCType(children[0]->getData().valueType, assignedTo) + ";\n";
|
||||
// we put the thing about to be copy constructed in a variable so we can for sure take its address
|
||||
std::string toAssignTemp = "copy_construct_param" + getID();
|
||||
output.value += ValueTypeToCType(children[1]->getData().valueType, toAssignTemp) + " = " + toAssign.value + ";\n";
|
||||
output.value += ValueTypeToCType(children[1]->getData().valueType->withoutReference(), toAssignTemp) + " = " + toAssign.value + ";\n";
|
||||
|
||||
output.value += generateMethodIfExists(children[0]->getDataRef()->valueType, "copy_construct", "&" + assignedTo + ", &" + toAssignTemp, std::vector<Type>{children[1]->getDataRef()->valueType->withIncreasedIndirection()}) + ";\n" + output.postValue;
|
||||
output.value += toAssign.postValue;
|
||||
|
||||
@@ -139,42 +139,53 @@ obj grammer (Object) {
|
||||
)
|
||||
var first_helper = fun(rhs: vector::vector<symbol::symbol>): set::set<symbol::symbol> {
|
||||
var toRet = set::set<symbol::symbol>()
|
||||
rhs.for_each(fun(sym: symbol::symbol) {
|
||||
toRet.add(first_set_map[sym])
|
||||
})
|
||||
if (rhs.size) {
|
||||
for (var i = 0; i < rhs.size; i++;) {
|
||||
var lookahead = first_set_map[rhs[i]]
|
||||
if (lookahead.contains(symbol::null_symbol())) {
|
||||
lookahead.remove(symbol::null_symbol())
|
||||
toRet.add(lookahead)
|
||||
} else {
|
||||
toRet.add(lookahead)
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toRet.add(symbol::null_symbol())
|
||||
}
|
||||
return toRet
|
||||
}
|
||||
var changed = true
|
||||
while (changed) {
|
||||
io::println("//////////current state of map/////////////")
|
||||
/*io::println("//////////current state of map/////////////")*/
|
||||
first_set_map.keys.for_each(fun(sym: symbol::symbol) {
|
||||
io::print("for ")
|
||||
io::println(sym.to_string())
|
||||
io::println("map is:")
|
||||
first_set_map[sym].for_each(fun(look: symbol::symbol) {
|
||||
io::print("lookahead: "); io::println(look.to_string())
|
||||
})
|
||||
/*io::print("for ")*/
|
||||
/*io::println(sym.to_string())*/
|
||||
/*io::println("map is:")*/
|
||||
/*first_set_map[sym].for_each(fun(look: symbol::symbol) {*/
|
||||
/*io::print("lookahead: "); io::println(look.to_string())*/
|
||||
/*})*/
|
||||
})
|
||||
changed = false
|
||||
rules.for_each( fun(r: rule) {
|
||||
var rule_lookahead = first_helper(r.rhs)
|
||||
if (!changed) {
|
||||
io::println(r.to_string())
|
||||
/*io::println(r.to_string())*/
|
||||
changed = !first_set_map[r.lhs].contains(rule_lookahead)
|
||||
io::print("changed: "); io::println(changed)
|
||||
io::print("\tcurrent lookahead is sized:")
|
||||
io::println(first_set_map[r.lhs].size())
|
||||
io::println("\tcurrent lookahead is:")
|
||||
first_set_map[r.lhs].for_each(fun(look: symbol::symbol) {
|
||||
io::print("\t\tlookahead: "); io::println(look.to_string())
|
||||
})
|
||||
io::println()
|
||||
io::print("\rule lookahead is sized:")
|
||||
io::println(rule_lookahead.size())
|
||||
io::println("\trule lookahead is:")
|
||||
rule_lookahead.for_each(fun(look: symbol::symbol) {
|
||||
io::print("\t\tlookahead: "); io::println(look.to_string())
|
||||
})
|
||||
/*io::print("changed: "); io::println(changed)*/
|
||||
/*io::print("\tcurrent lookahead is sized:")*/
|
||||
/*io::println(first_set_map[r.lhs].size())*/
|
||||
/*io::println("\tcurrent lookahead is:")*/
|
||||
/*first_set_map[r.lhs].for_each(fun(look: symbol::symbol) {*/
|
||||
/*io::print("\t\tlookahead: "); io::println(look.to_string())*/
|
||||
/*})*/
|
||||
/*io::println()*/
|
||||
/*io::print("\rule lookahead is sized:")*/
|
||||
/*io::println(rule_lookahead.size())*/
|
||||
/*io::println("\trule lookahead is:")*/
|
||||
/*rule_lookahead.for_each(fun(look: symbol::symbol) {*/
|
||||
/*io::print("\t\tlookahead: "); io::println(look.to_string())*/
|
||||
/*})*/
|
||||
}
|
||||
first_set_map[r.lhs].add(rule_lookahead)
|
||||
})
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import string
|
||||
|
||||
fun null_symbol(): symbol {
|
||||
var toRet.construct(string::string("$NULL"), false, string::string("$NULL$")): symbol
|
||||
return toRet
|
||||
}
|
||||
|
||||
fun symbol(nameIn: *char, terminalIn: bool): symbol {
|
||||
var toRet.construct(string::string(nameIn), terminalIn, string::string("no_value")): symbol
|
||||
return toRet
|
||||
|
||||
10
tests/grammer2.kgm
Normal file
10
tests/grammer2.kgm
Normal file
@@ -0,0 +1,10 @@
|
||||
# comment
|
||||
a = b ;
|
||||
b = "c":named_c ;
|
||||
b = c "d":dname ;
|
||||
c = "a" | d ;
|
||||
d = e post_null post_non_null ;
|
||||
e = f | ;
|
||||
f = ;
|
||||
post_null = "hi"
|
||||
post_non_null = "bye"
|
||||
@@ -8,7 +8,8 @@ import symbol:*
|
||||
fun main():int {
|
||||
|
||||
/*var a = load_grammer(read_file(string("../krakenGrammer.kgm")))*/
|
||||
var a = load_grammer(read_file(string("grammer.kgm")))
|
||||
/*var a = load_grammer(read_file(string("grammer.kgm")))*/
|
||||
var a = load_grammer(read_file(string("grammer2.kgm")))
|
||||
println(a.to_string())
|
||||
var doFirstSet = fun() {
|
||||
a.calculate_first_set()
|
||||
@@ -39,8 +40,9 @@ fun main():int {
|
||||
var lex = lexer(a.terminals)
|
||||
|
||||
/*lex.set_input(read_file(string("test_grammer.krak")))*/
|
||||
lex.set_input(string("ccdahas spacedhas
|
||||
returndaaaaaaaaaaaaaa"))
|
||||
/*lex.set_input(string("ccdahas spacedhas*/
|
||||
/*returndaaaaaaaaaaaaaa"))*/
|
||||
lex.set_input(string("hibyed"))
|
||||
println("woo lexing:")
|
||||
range(8).for_each(fun(i: int) { println(lex.next().to_string()); } )
|
||||
/*range(80).for_each(fun(i: int) { println(lex.next().to_string()); } )*/
|
||||
|
||||
@@ -5,4 +5,7 @@
|
||||
construct
|
||||
do
|
||||
do
|
||||
copy_construct
|
||||
do
|
||||
destruct
|
||||
destruct
|
||||
|
||||
@@ -59,6 +59,9 @@ fun main():int {
|
||||
var t.construct() : test_cons
|
||||
call(t)
|
||||
id(t).do()
|
||||
|
||||
var do_copy = id(t)
|
||||
do_copy.do()
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user