* cilc.cs:
authorAlp Toker <alp@mono-cvs.ximian.com>
Sun, 12 Dec 2004 05:55:08 +0000 (05:55 -0000)
committerAlp Toker <alp@mono-cvs.ximian.com>
Sun, 12 Dec 2004 05:55:08 +0000 (05:55 -0000)
  Initial support for namespaceless assemblies.
  C keyword avoidance.

svn path=/trunk/mcs/; revision=37659

mcs/tools/cilc/ChangeLog
mcs/tools/cilc/cilc.cs

index 45d3eee139d65c072672ef050400a5de4a99aabb..be44bd97927068f0ed407660002d605e7fd38257 100644 (file)
@@ -6,7 +6,9 @@
        First stab at return values, and associated updates to the demo.
        Consider types registered ByVal but not in main registry as unregistered.
        Mark out some more ByVal types.
+  * cilc.cs:
        Initial support for namespaceless assemblies.
+       C keyword avoidance.
 
 2004-12-11  Alp Toker  <alp@atoker.com>
 
index 8c04bfdbc65eddb69f763d2089912bfdcc56c8db..2ad9a49ee90bb9bb85089dab909e7482c5174e87 100644 (file)
@@ -867,6 +867,16 @@ public class cilc
                FunctionGen (parameters, (MethodBase) m, t, m.ReturnType, false);
        }
 
+       static readonly string[] keywords = {"auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "int", "long", "register", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while"};
+
+       static string KeywordAvoid (string s)
+       {
+               if (Array.IndexOf (keywords, s.ToLower ()) != -1)
+                       return KeywordAvoid ("_" + s);
+
+               return s;
+       }
+       
        static string ToValidFuncName (string name)
        {
                //avoid generated function name conflicts with internal functions
@@ -938,7 +948,7 @@ public class cilc
                                else
                                        myname += "_and_";
 
-                               myname += p.Name;
+                               myname += KeywordAvoid (p.Name);
                        }
                }
 
@@ -954,7 +964,7 @@ public class cilc
                for (int i = 0 ; i < parameters.Length ; i++) {
                        ParameterInfo p = parameters[i];
                        mycsargs += GetMonoType (Type.GetTypeCode (p.ParameterType));
-                       myargs += CsTypeToC (p.ParameterType) + p.Name;
+                       myargs += CsTypeToC (p.ParameterType) + KeywordAvoid (p.Name);
                        if (i != parameters.Length - 1) {
                                mycsargs += ",";
                                myargs += ", ";
@@ -999,7 +1009,7 @@ public class cilc
                //assign the parameters
                for (int i = 0 ; i < parameters.Length ; i++) {
                        ParameterInfo p = parameters[i];
-                       C.WriteLine  (params_arg + "[" + i + "] = " + GetMonoVal (p.Name, p.ParameterType.ToString ()) + ";");
+                       C.WriteLine  (params_arg + "[" + i + "] = " + GetMonoVal (KeywordAvoid (p.Name), p.ParameterType.ToString ()) + ";");
                }
 
                if (parameters.Length != 0)