From f1c3f3044b73d890ffdfdd113b3b37ae2809d21b Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Fri, 2 Apr 2010 11:20:32 -0700 Subject: ruby: get "using namespace" out of headers In addition to obvious changes, this required a slight change to the slicc grammar to allow types with :: in them. Otherwise slicc barfs on std::string which we need for the headers that slicc generates. --- src/mem/slicc/ast/EnumDeclAST.py | 2 +- src/mem/slicc/ast/LiteralExprAST.py | 2 +- src/mem/slicc/parser.py | 14 +++++++++++--- src/mem/slicc/symbols/Func.py | 1 + src/mem/slicc/symbols/StateMachine.py | 8 +++++--- src/mem/slicc/symbols/Type.py | 7 +------ 6 files changed, 20 insertions(+), 14 deletions(-) (limited to 'src/mem/slicc') diff --git a/src/mem/slicc/ast/EnumDeclAST.py b/src/mem/slicc/ast/EnumDeclAST.py index a20f4b749..da07a0165 100644 --- a/src/mem/slicc/ast/EnumDeclAST.py +++ b/src/mem/slicc/ast/EnumDeclAST.py @@ -66,6 +66,6 @@ class EnumDeclAST(DeclAST): pairs = { "external" : "yes" } func = Func(self.symtab, func_id, self.location, - self.symtab.find("string", Type), [ t ], [], "", + self.symtab.find("std::string", Type), [ t ], [], "", pairs, None) self.symtab.newSymbol(func) diff --git a/src/mem/slicc/ast/LiteralExprAST.py b/src/mem/slicc/ast/LiteralExprAST.py index 773e8f35c..6d259c17f 100644 --- a/src/mem/slicc/ast/LiteralExprAST.py +++ b/src/mem/slicc/ast/LiteralExprAST.py @@ -39,7 +39,7 @@ class LiteralExprAST(ExprAST): def generate(self, code): fix = code.nofix() - if self.type == "string": + if self.type == "std::string": code('("${{self.literal}}")') elif self.type == "bool": code('(${{str(self.literal).lower()}})') diff --git a/src/mem/slicc/parser.py b/src/mem/slicc/parser.py index ae8a9342f..1505e1d0c 100644 --- a/src/mem/slicc/parser.py +++ b/src/mem/slicc/parser.py @@ -394,8 +394,16 @@ class SLICC(Grammar): "types : empty" p[0] = [] - def p_type(self, p): - "type : ident" + def p_typestr__multi(self, p): + "typestr : typestr DOUBLE_COLON ident" + p[0] = '%s::%s' % (p[1], p[3]) + + def p_typestr__single(self, p): + "typestr : ident" + p[0] = p[1] + + def p_type__one(self, p): + "type : typestr" p[0] = ast.TypeAST(self, p[1]) def p_void(self, p): @@ -670,7 +678,7 @@ class SLICC(Grammar): def p_literal__string(self, p): "literal : STRING" - p[0] = ast.LiteralExprAST(self, p[1], "string") + p[0] = ast.LiteralExprAST(self, p[1], "std::string") def p_literal__number(self, p): "literal : NUMBER" diff --git a/src/mem/slicc/symbols/Func.py b/src/mem/slicc/symbols/Func.py index 459cca52a..a5751344a 100644 --- a/src/mem/slicc/symbols/Func.py +++ b/src/mem/slicc/symbols/Func.py @@ -81,6 +81,7 @@ class Func(Symbol): if self.isInternalMachineFunc: code('#include "mem/protocol/${{self.machineStr}}_Controller.hh"') + code('using namespace std;') # Generate function header void_type = self.symtab.find("void", Type) return_type = self.return_type.c_ident diff --git a/src/mem/slicc/symbols/StateMachine.py b/src/mem/slicc/symbols/StateMachine.py index 0c66ddab4..a58c1e9c7 100644 --- a/src/mem/slicc/symbols/StateMachine.py +++ b/src/mem/slicc/symbols/StateMachine.py @@ -32,7 +32,7 @@ from slicc.symbols.Var import Var import slicc.generate.html as html python_class_map = {"int": "Int", - "string": "String", + "std::string": "String", "bool": "Bool", "CacheMemory": "RubyCache", "Sequencer": "RubySequencer", @@ -271,12 +271,12 @@ std::string m_name; int m_transitions_per_cycle; int m_buffer_size; int m_recycle_latency; -map m_cfg; +std::map m_cfg; NodeID m_version; Network* m_net_ptr; MachineID m_machineID; bool m_is_blocking; -map< Address, MessageBuffer* > m_block_map; +std::map m_block_map; ${ident}_Profiler s_profiler; static int m_num_controllers; @@ -714,6 +714,8 @@ $c_ident::${{action.ident}}(const Address& addr) #include "mem/protocol/Types.hh" #include "mem/ruby/system/System.hh" +using namespace std; + void ${ident}_Controller::wakeup() { diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py index 645291ac2..c4b4d4275 100644 --- a/src/mem/slicc/symbols/Type.py +++ b/src/mem/slicc/symbols/Type.py @@ -385,12 +385,7 @@ set${{dm.ident}}(const ${{dm.type.c_ident}}& local_${{dm.ident}}) code('};') code(''' -// Output operator declaration -std::ostream& -operator<<(std::ostream& out, const ${{self.c_ident}}& obj); - -// Output operator definition -extern inline std::ostream& +inline std::ostream& operator<<(std::ostream& out, const ${{self.c_ident}}& obj) { obj.print(out); -- cgit v1.2.3