private void VisitExternalStatementNode(external_statement stmt)
 {
     bw.Write(stmt.module_name);
     bw.Write(stmt.name);
 }
Esempio n. 2
0
 private void VisitExternalStatementNode(external_statement sn)
 {
     helper.MarkAsExternal(cur_func);
 }
 public override void visit(SyntaxTree.external_directive _external_directive)
 {
     string module_name = "";
     string name = "";
     if (_external_directive.modulename == null)
     {
     	if (!has_dll_import_attribute(context.top_function))
     	{
             AddError(context.top_function.loc, "FUNCTION_MUST_HAVE_DLLIMPORT_ATTRIBUTE");
     	}
     	else
     	{
     		location loc2 = get_location(_external_directive);
     		pinvoke_statement pinv_stmt = new pinvoke_statement(loc2);
     		//statement_node_list sal = new statement_node_list(loc);
     		//sal.AddElement(ext_stmt);
     		statements_list sl2 = new statements_list(loc2);
     		sl2.statements.AddElement(pinv_stmt);
     		//return_value(sl);
     		context.code = sl2;
     		return;
     	}
     }
     if (has_dll_import_attribute(context.top_function))
     {
         AddError(get_location(_external_directive.modulename), "FUNCTION_MUST_HAVE_ONLY_EXTERNAL_STATEMENT");
     }
     if (_external_directive.modulename is SyntaxTree.string_const)
     {
         module_name = ((SyntaxTree.string_const)_external_directive.modulename).Value;
     }
     else if (_external_directive.modulename is SyntaxTree.ident)
     {
         //throw new CompilerInternalError("Unsupported now");
         //throw new NotSupportedError(get_location(_external_directive));
         expression_node en = convert_strong(_external_directive.modulename as SyntaxTree.ident);
         if (en is string_const_node)
         	module_name = (en as string_const_node).constant_value;
         else
             AddError(get_location(_external_directive.modulename), "STRING_CONSTANT_EXPECTED");
     }
     else
         AddError(get_location(_external_directive.modulename), "STRING_CONSTANT_OR_IDENTIFIER_EXPECTED");
     if (_external_directive.name == null)
     {
     	name = context.converted_func_stack.top().name;
     }
     else
     if (_external_directive.name is SyntaxTree.string_const)
     {
         name = ((SyntaxTree.string_const)_external_directive.name).Value;
     }
     else if (_external_directive.name is SyntaxTree.ident)
     {
     	expression_node en = convert_strong(_external_directive.name as SyntaxTree.ident);
         if (en is string_const_node)
         	name = (en as string_const_node).constant_value;
         else
             AddError(get_location(_external_directive.name), "STRING_CONSTANT_EXPECTED");
     }
     else
     {
         //throw new CompilerInternalError("Unsupported now");
         AddError(get_location(_external_directive.name), "STRING_CONSTANT_OR_IDENTIFIER_EXPECTED");
     }
     location loc = get_location(_external_directive);
     external_statement ext_stmt = new external_statement(module_name, name, loc);
     //statement_node_list sal = new statement_node_list(loc);
     //sal.AddElement(ext_stmt);
     statements_list sl = new statements_list(loc);
     sl.statements.AddElement(ext_stmt);
     //return_value(sl);
     context.code = sl;
 }