Permalink
Browse files

using proper class name in function invocations

  • Loading branch information...
thejoshwolfe committed Dec 6, 2010
1 parent a0764f6 commit 684bc7f58ef32171d411e7826085e6a40f9be21b
View
@@ -1082,6 +1082,7 @@ void MethodGenerator::gen_statement(Statement * statement) {
bool MethodGenerator::gen_method_designator(MethodDesignator * method_designator, Variant & out_dest) {
std::string class_name = get_class_name(method_designator->owner);
std::string method_name = method_designator->function->identifier->text;
+ class_name = get_declaring_class(m_symbol_table, class_name, method_name);
FunctionDeclaration * declaration = get_method(m_symbol_table, class_name, method_name);
bool non_void = declaration->type != NULL;
MethodCallInstruction * instruction = non_void ?
View
@@ -159,13 +159,22 @@ FunctionDeclaration * get_method(SymbolTable * symbol_table, std::string class_n
if (! symbol_table->has_key(class_name))
return NULL;
ClassSymbolTable * class_symbols = symbol_table->get(class_name);
- if (class_symbols->function_symbols->has_key(method_name)) {
+ if (class_symbols->function_symbols->has_key(method_name))
return class_symbols->function_symbols->get(method_name)->function_declaration;
- } else if (class_symbols->class_declaration->parent_identifier == NULL) {
+ if (class_symbols->class_declaration->parent_identifier == NULL)
return NULL;
- } else {
- return get_method(symbol_table, class_symbols->class_declaration->parent_identifier->text, method_name);
- }
+ return get_method(symbol_table, class_symbols->class_declaration->parent_identifier->text, method_name);
+}
+
+std::string get_declaring_class(SymbolTable * symbol_table, std::string class_name, std::string method_name) {
+ if (! symbol_table->has_key(class_name))
+ assert(false);
+ ClassSymbolTable * class_symbols = symbol_table->get(class_name);
+ if (class_symbols->function_symbols->has_key(method_name))
+ return class_name;
+ if (class_symbols->class_declaration->parent_identifier == NULL)
+ assert(false);
+ return get_declaring_class(symbol_table, class_symbols->class_declaration->parent_identifier->text, method_name);
}
View
@@ -51,6 +51,7 @@ SymbolTable * build_symbol_table(Program * program);
bool add_variables(OrderedInsensitiveMap<VariableData *> * function_variables, VariableDeclaration * variable_declaration, std::string function_name);
VariableData * get_field(SymbolTable * symbol_table, std::string class_name, std::string field_name);
FunctionDeclaration * get_method(SymbolTable * symbol_table, std::string class_name, std::string method_name);
+std::string get_declaring_class(SymbolTable * symbol_table, std::string class_name, std::string method_name);
VariableDeclarationList * reverse_variable_declaration_list(VariableDeclarationList * variable_declaration_list, VariableDeclarationList * prev = NULL);
bool inheritance_loop(SymbolTable * symbol_table, std::string original_class);
bool inheritance_loop(SymbolTable * symbol_table, std::string original_class, std::string current_class);
@@ -34,7 +34,9 @@ BEGIN
FUNCTION testFunctionCallObjectExtend;
BEGIN
- retval := myCustomObject.setCompilerWorks(onOff)
+ myCustomObject := new middleManClass;
+ retval := myCustomObject.setCompilerWorks(onOff);
+ print retval;
END
END

0 comments on commit 684bc7f

Please sign in to comment.