tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robbin...@apache.org
Subject svn commit: r366157 [30/33] - in /incubator/tuscany/cpp/sca: ./ bin/ include/ include/osoa/ include/osoa/sca/ include/tuscany/ include/tuscany/sca/ include/tuscany/sca/core/ include/tuscany/sca/model/ include/tuscany/sca/util/ include/tuscany/sca/ws/ l...
Date Thu, 05 Jan 2006 10:59:14 GMT
Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/CParsingTool.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/CParsingTool.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/CParsingTool.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/CParsingTool.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,119 @@
+/*
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/*
+ *  Branched from the original class that was also contributed to the 
+ *  org.apache.axis.tools.common package.
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * The superclass of tools that parse C/C++ code. This CParsingTool provides
+ * some useful common methods.
+ */
+public class CParsingTool {
+    protected boolean failed = false;
+
+    protected Headers headers = new Headers();
+
+    protected CParsingTool(String[] args) throws Exception {
+        String text = new String();
+        for (int i = 0; i < args.length; i++)
+            text += args[i] + " ";
+        Utils.outputDebugString(text);
+
+        Options.set(args);
+        String config = (String) Options.getOption("-config");
+        if (null != config)
+            Configuration.initialise(config);
+    }
+
+    /**
+     * Read in any include files before the main processing of the tool is done.
+     * This constructs the Headers.
+     */
+    protected Headers preparseHeaders(String option) throws Exception {
+        Headers headers = new Headers();
+        Object o = Options.getOption(option);
+        if (null != o) {
+            Utils.outputDebugString("Pre-parsing headers...");
+            List includeList;
+            if (o instanceof List)
+                includeList = (List) o;
+            else {
+                includeList = new ArrayList();
+                includeList.add(o);
+            }
+            Iterator it = includeList.iterator();
+            while (it.hasNext()) {
+                File include = new File((String) it.next());
+                if (!include.isDirectory())
+                    Utils.rude("Bad include directory " + include);
+
+                DirectoryTree tree = new DirectoryTree(headers, new HashSet(
+                        Arrays.asList(new Object[] { "hpp", "h" })));
+                tree.walkTree(include, null, 0);
+            }
+            Utils.outputDebugString("Parsing files...");
+        }
+
+        return headers;
+    }
+
+    /**
+     * Checks the source directory looks good.
+     */
+    protected File checkFile(String option) throws Exception {
+        String name = (String) Options.getOption(option);
+        if (null == name) {
+            printUsage();
+            System.exit(-1);
+        }
+
+        File file = new File(name);
+        if (!file.isFile() && !file.isDirectory())
+            Utils.rude("Bad file or directory " + file);
+        return file;
+    }
+
+    /**
+     * Checks the target directory and creates it if it doesn't already exist.
+     */
+    protected File maybeCreateDirectory(String option) throws Exception {
+        String name = (String) Options.getOption(option);
+        if (null == name) {
+            printUsage();
+            System.exit(-1);
+        }
+
+        File file = new File(name);
+        if (!file.exists() && !file.mkdir())
+            Utils.screenMessage("Failed to create directory " + file);
+        return file;
+    }
+
+    protected void printUsage() {
+        System.out.println("usage: ??");
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/CParsingTool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/CParsingTool.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Configuration.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Configuration.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Configuration.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Configuration.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,126 @@
+/*
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/*
+ *  Branched from the original class that was also contributed to the 
+ *  org.apache.axis.tools.common package.
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Encapsulates the tool's configuration file
+ */
+public class Configuration {
+    private static Set files = new HashSet();
+
+    private static Set classes = new HashSet();
+
+    private static Set methods = new HashSet();
+
+    private static Set macros = new HashSet();
+
+    private static Set defines = new HashSet();
+
+    private static Set attributes = new HashSet();
+
+    private static Map others = new HashMap();
+
+    /**
+     * No one creates an instance of this class.
+     */
+    private Configuration() {
+    }
+
+    /**
+     * Reads in the configuration file
+     */
+    public static void initialise(String filename) throws Exception {
+        File file = new File(filename);
+        FileReader fr = new FileReader(file);
+        BufferedReader br = new BufferedReader(fr);
+        String line = br.readLine();
+        for (int lineno = 1; null != line; lineno++, line = br.readLine()) {
+            // Ignore lines starting with a # (comments) and blank lines
+            if (line.startsWith("#"))
+                continue;
+            boolean blank = true;
+            for (int i = 0; i < line.length() && blank; i++)
+                if (!Character.isWhitespace(line.charAt(i)))
+                    blank = false;
+            if (blank)
+                continue;
+
+            int equals = line.indexOf("=");
+            if (-1 == equals)
+                Utils.rude("Bad line in configuration file " + filename
+                        + " lineno " + lineno);
+            String key = line.substring(0, equals).trim();
+            String value = line.substring(equals + 1).trim();
+            if ("excludefile".equals(key)) {
+                files.add(value);
+            } else if ("excludeclass".equals(key)) {
+                classes.add(value);
+            } else if ("excludemethod".equals(key)) {
+                methods.add(value);
+            } else if ("macro".equals(key)) {
+                macros.add(value);
+            } else if ("define".equals(key)) {
+                defines.add(value);
+            } else if ("attribute".equals(key)) {
+                attributes.add(value);
+            } else {
+                others.put(key, value);
+            }
+        }
+    }
+
+    public static boolean fileExcluded(String s) {
+        return files.contains(s);
+    }
+
+    public static boolean classExcluded(String s) {
+        return classes.contains(s);
+    }
+
+    public static boolean methodExcluded(String className, String method) {
+        return methods.contains(className + "::" + method);
+    }
+
+    public static boolean isMacro(String s) {
+        return macros.contains(s);
+    }
+
+    public static boolean isDefine(String s) {
+        return defines.contains(s);
+    }
+
+    public static boolean isAttribute(String s) {
+        return attributes.contains(s);
+    }
+
+    public static String getConfigured(String key) {
+        return (String) others.get(key);
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Configuration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Configuration.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/DirectoryTree.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/DirectoryTree.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/DirectoryTree.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/DirectoryTree.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,100 @@
+/*
+ * 
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+/*
+ * Branched from the original class that was also contributed to the
+ * org.apache.axis.tools.common package.
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+import java.io.File;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+public class DirectoryTree {
+    private FileActor actor;
+
+    private Set extensions;
+
+    public DirectoryTree(FileActor actor, Set extensions) {
+        this.actor = actor;
+        this.extensions = extensions;
+    }
+
+    /**
+     * Starts adding trace into the given file. If the given file is a directory
+     * then this the starting directory and all code beneath and in this
+     * directory will be given trace.
+     * 
+     * @param source -
+     *            either the starting directory or one file to add trace to.
+     */
+    public void walkTree(File source, File target, int depth) throws Exception {
+        depth++;
+        boolean noTarget = (null == target);
+
+        if (!source.canRead())
+            Utils.rude("Cannot read from source directory " + source);
+        if (!noTarget && !target.canWrite())
+            Utils.rude("Cannot write to target directory " + target);
+
+        if (source.isDirectory()) {
+            File[] filesInDirectory = source.listFiles();
+            for (int i = 0; i < filesInDirectory.length; i++) {
+                File file = filesInDirectory[i];
+                String name = file.getName();
+                int dot = name.lastIndexOf('.');
+                String ext = null;
+                if (-1 != dot)
+                    ext = name.substring(dot + 1);
+
+                if (file.isDirectory()) {
+                    File newTarget = null;
+                    if (!noTarget) {
+                        StringTokenizer st = new StringTokenizer(
+                                file.getPath(), "\\/");
+                        String newdir = null;
+                        while (st.hasMoreTokens())
+                            newdir = st.nextToken();
+                        String targetName = maybeAppendSeparator(target
+                                .toString());
+                        newTarget = new File(targetName + newdir);
+                        if (!newTarget.mkdir())
+                            Utils.rude("Failed to create target directory "
+                                    + newTarget);
+                    }
+
+                    // recurse
+                    walkTree(file, newTarget, depth);
+                } else if (file.isFile()
+                        && (extensions == null || (!file.isHidden() && extensions
+                                .contains(ext)))) {
+                    // this is a file and we need to add trace into it !
+                    actor.actOnFile(file, target, depth);
+                }
+            }
+        } else {
+            actor.actOnFile(source, target, depth);
+        }
+    }
+
+    public static String maybeAppendSeparator(String name) {
+        if (!name.endsWith("/") && !name.endsWith("\\"))
+            name += "/";
+        return name;
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/DirectoryTree.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/DirectoryTree.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FileActor.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FileActor.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FileActor.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FileActor.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,32 @@
+/*
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/*
+ *  Branched from the original class that was also contributed to the 
+ *  org.apache.axis.tools.common package.
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+import java.io.File;
+
+/**
+ * DirectoryTree calls this interface to allow implementations of this interface
+ * to act on a file in the directory tree.
+ */
+public interface FileActor {
+    public void actOnFile(File source, File target, int depth) throws Exception;
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FileActor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FileActor.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FilePart.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FilePart.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FilePart.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FilePart.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,75 @@
+/*
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/*
+ *  Branched from the original class that was also contributed to the 
+ *  org.apache.axis.tools.common package.
+ */
+
+package org.apache.tuscany.sca.cpp.tools.common;
+
+/**
+ * A piece of C++ source code
+ */
+public class FilePart {
+    public final static int UNKNOWN = 0;
+
+    public final static int COMMENT = 1;
+
+    public final static int METHOD = 2;
+
+    public final static int FIELD = 3;
+
+    public final static int BEGINSCOPE = 4;
+
+    public final static int ENDSCOPE = 5;
+
+    public final static int DIRECTIVE = 6;
+
+    public final static int WHITESPACE = 7;
+
+    public final static int MACRO = 8;
+
+    public final static int CLASSATTRIBUTE = 9;
+
+    public final static int ENUM = 10;
+
+    public final static int PROTOTYPE = 11;
+
+    public final static int TYPEDEF = 12;
+
+    protected String cppsource;
+
+    protected int type;
+
+    FilePart(String s, int type) {
+        cppsource = s;
+        this.type = type;
+    }
+
+    public int getType() {
+        return type;
+    }
+
+    int length() {
+        return cppsource.length();
+    }
+
+    public String toString() {
+        return cppsource;
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FilePart.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/FilePart.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Headers.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Headers.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Headers.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Headers.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,162 @@
+/*
+ * 
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+/*
+ * Branched from the original class that was also contributed to the
+ * org.apache.axis.tools.common package.
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class Headers implements FileActor {
+    private ArrayList instanceMethods = new ArrayList();
+
+    private ArrayList staticMethods = new ArrayList();
+
+    private ArrayList allMethods = new ArrayList();
+
+    private ArrayList classNames = new ArrayList();
+
+    private boolean failed = false;
+
+    public void actOnFile(File header, File ignored, int depth)
+            throws Exception {
+        if (Configuration.fileExcluded(header.getName())) {
+            Utils.outputDebugString("excluding " + header + "...");
+            return;
+        }
+
+        Utils.outputDebugString("pre-parsing " + header + "...");
+        FileReader fr = null;
+        try {
+            fr = new FileReader(header);
+        } catch (FileNotFoundException fnfe) {
+            throw fnfe;
+        }
+        BufferedReader inputFile = new BufferedReader(fr);
+
+        try {
+            InputCppSourceCode code = new InputCppSourceCode(inputFile, header
+                    .getName());
+            Iterator it = code.getPartIterator();
+            while (it.hasNext()) {
+                FilePart fp = (FilePart) (it.next());
+                if (fp.getType() != FilePart.PROTOTYPE)
+                    continue;
+                PrototypePart pp = (PrototypePart) fp;
+                String className = pp.className();
+                if (null == className)
+                    continue;
+                String trimClassName = className;
+                if (className.endsWith("::"))
+                    trimClassName = className.substring(0,
+                            className.length() - 2);
+                if (!classNames.contains(trimClassName))
+                    classNames.add(trimClassName);
+
+                Signature sign = new Signature(fp.toString());
+                sign.setClassName(className);
+                //Tuscany
+                sign.setScope(pp.getSignature().getScope());
+                sign.setNamespace(pp.getSignature().getNamespace());
+
+                // "Clean" the signature by stripping off attributes,
+                // semicolons, etc
+                Signature cleaned = new Signature(sign.toStringWithoutAttrs());
+                //Tuscany - problem
+                cleaned.setClassName(className);
+                cleaned.setScope(pp.getSignature().getScope());
+                cleaned.setNamespace(pp.getSignature().getNamespace());
+                //Tuscany - end of problem
+                
+                
+                if (-1 == sign.getAttributes().indexOf("static"))
+                    instanceMethods.add(cleaned);
+                else
+                    staticMethods.add(cleaned);
+            }
+        } catch (ParsingException pe) {
+            failed = true;
+        }
+
+        inputFile.close();
+        allMethods.addAll(staticMethods);
+        allMethods.addAll(instanceMethods);
+    }
+
+    public boolean failed() {
+        return failed;
+    }
+
+    public boolean isInstanceMethod(Signature sign) {
+        Iterator it = instanceMethods.iterator();
+        while (it.hasNext()) {
+            Signature s = (Signature) it.next();
+            if (s.equals(sign))
+                return true;
+        }
+        return false;
+    }
+
+    public boolean isStaticMethod(Signature sign) {
+        Iterator it = staticMethods.iterator();
+        while (it.hasNext()) {
+            Signature s = (Signature) it.next();
+            if (s.equals(sign))
+                return true;
+        }
+        return false;
+    }
+
+    public List getMethods(String method) {
+        ArrayList list = new ArrayList();
+        if (null == method)
+            return list;
+
+        Iterator it = allMethods.iterator();
+        while (it.hasNext()) {
+            Signature s = (Signature) it.next();
+            if (method.equals(s.getMethodName()))
+                list.add(s);
+        }
+        return list;
+    }
+
+    /**
+     * Tuscany change - a method to get all the method signatures at once
+     */
+    public List getAllMethods() {
+        ArrayList list = new ArrayList();
+        Iterator it = allMethods.iterator();
+        while (it.hasNext()) {
+            Signature s = (Signature) it.next();
+            list.add(s);
+        }
+        return list;
+    }
+
+    public boolean isClassName(String text) {
+        return classNames.contains(text);
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Headers.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Headers.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/InputCppSourceCode.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/InputCppSourceCode.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/InputCppSourceCode.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/InputCppSourceCode.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,412 @@
+/*
+ * 
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+/*
+ * Branched from the original class that was also contributed to the
+ * org.apache.axis.tools.common package.
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+import java.io.BufferedReader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+public class InputCppSourceCode {
+
+    private ArrayList parts = new ArrayList();
+
+    private String name;
+
+    public InputCppSourceCode(BufferedReader br, String name) throws Exception {
+        this.name = name;
+
+        String s = null;
+        StringBuffer buff = new StringBuffer();
+        for (int i = 1;; i++) {
+            try {
+                s = br.readLine();
+            } catch (Exception e) {
+                System.err.println("Ignoring exception thrown parsing file "
+                        + name + " line number " + i);
+                e.printStackTrace();
+                break;
+            }
+            if (s == null)
+                break;
+            buff.append(s + "\n");
+        }
+        String str = buff.toString();
+
+        // TODO: When checking for rest.startsWith("struct") should
+        // check the next letter after struct is not alphanumeric otherwise
+        // we'll get false matches on a function called structify() for
+        // instance. Also applies to enum, union, public, typedef, etc
+
+        String rest, text = "";
+        int scopedepth = 0;
+        String scope = "public";
+        String currentClass = null;
+        String currentNamespace = null;
+        for (int idx = 0; idx < str.length(); /* No idx++ */
+        ) {
+            rest = str.substring(idx);
+            if (Character.isWhitespace(rest.charAt(0))) {
+                int ridx = 0;
+                while (ridx < rest.length()
+                        && Character.isWhitespace(rest.charAt(ridx)))
+                    ridx++;
+                text = rest.substring(0, ridx);
+                FilePart fp = new FilePart(text, FilePart.WHITESPACE);
+                parts.add(fp);
+                idx += ridx;
+
+            } else if (rest.startsWith("/*")) {
+                int ridx = rest.indexOf("*/"); // Don't use Utils here
+                text = str.substring(idx, idx + ridx + 2);
+                FilePart fp = new FilePart(text, FilePart.COMMENT);
+                parts.add(fp);
+                idx += text.length();
+
+            } else if (rest.startsWith("//")) {
+                text = str.substring(idx, idx + rest.indexOf("\n"));
+                FilePart fp = new FilePart(text, FilePart.COMMENT);
+                parts.add(fp);
+                idx += text.length();
+
+            } else if (rest.startsWith("#")) {
+                int ridx = rest.indexOf("\n");
+                char c = rest.charAt(ridx - 1);
+                while (-1 != ridx && '\\' == c) {
+                    String rest2 = rest.substring(ridx + 1);
+                    ridx += rest2.indexOf("\n") + 1;
+                    c = rest.charAt(ridx - 1);
+                }
+                text = str.substring(idx, idx + ridx);
+                FilePart fp = new FilePart(text, FilePart.DIRECTIVE);
+                parts.add(fp);
+                idx += text.length();
+
+            } else if (rest.startsWith("}")) {
+                if (scopedepth <= 0) //Tuscany need to increase scopedepth for
+                    // namespaces?
+                    Utils.rude("Braces do not match", name, lineNo(str, idx),
+                            rest.substring(0, rest.indexOf("\n")));
+                else
+                    scopedepth--;
+                // TODO: better checking that this brace really ends the class
+                if (0 == scopedepth)
+                    currentClass = null;
+                scope = "public";
+                parts.add(new FilePart("}", FilePart.ENDSCOPE));
+                idx++;
+
+            } else if (rest.startsWith(";")) {
+                parts.add(new FilePart(";", FilePart.FIELD));
+                idx++;
+
+            } else if (!Character.isLetter(rest.charAt(0))
+                    && '~' != rest.charAt(0) && '_' != rest.charAt(0)) {
+                Utils.rude("Lines must start with a letter ", name, lineNo(str,
+                        idx), rest.substring(0, rest.indexOf("\n")));
+
+            } else if (MacroPart.isAMacro(rest)) {
+                MacroPart mp = MacroPart.create(rest);
+                parts.add(mp);
+                idx += mp.length();
+
+            } else if (beginsScope(rest)) {
+
+                //Tuscany a namespace comes in here
+                scopedepth++;
+                text = rest.substring(0, Utils.indexOf(rest, "{") + 1);
+                FilePart fp = new FilePart(text, FilePart.BEGINSCOPE);
+                parts.add(fp);
+                idx += text.length();
+                if (Utils.startsWith(text, "class")) {
+                    // TODO: cope with comments here
+                    // TODO: split out classes into a ClassPart
+                    StringTokenizer st = new StringTokenizer(text,
+                            Utils.whitespace + ":");
+                    st.nextToken(); // step over "class"
+                    while (st.hasMoreTokens()) {
+                        String word = st.nextToken();
+                        if (Configuration.isAttribute(word))
+                            continue;
+                        currentClass = word;
+                        break;
+                    }
+                }
+
+                //Tuscany
+                if (Utils.startsWith(text, "namespace")) {
+                    // TODO: cope with comments here
+                    StringTokenizer st = new StringTokenizer(text,
+                            Utils.whitespace + "{");
+                    st.nextToken(); // step over "namespace"
+                    String word = "";
+                    while (st.hasMoreTokens()) {
+                        word = st.nextToken();
+                        if (word.equals("{")) {
+                            break;
+                        }
+
+                    }
+                    currentNamespace = word;
+                    //We have not got to the class yet
+                    //so will need ot deal with the namespace
+                    //when we do
+                }
+                // Tuscany end
+
+            } else if (isEnumOrUnion(rest)) {
+                int ridx = Utils.findMatching(rest, '{', '}') + 1;
+                String rest2 = rest.substring(ridx);
+                ridx = idx + ridx + Utils.indexOf(rest2, ';') + 1;
+                text = str.substring(idx, ridx);
+                FilePart fp = new FilePart(text, FilePart.ENUM);
+                parts.add(fp);
+                idx += text.length();
+
+            } else if (scopedepth > 0
+                    && (rest.startsWith("public")
+                            || rest.startsWith("protected") || rest
+                            .startsWith("private"))) {
+                int colon = rest.indexOf(":");
+                if (-1 == colon)
+                    Utils.rude("No colon found after public or private ", name,
+                            lineNo(str, idx), rest.substring(0, rest
+                                    .indexOf("\n")));
+                scope = str.substring(idx, idx + colon);
+                text = str.substring(idx, idx + colon + 1);
+                FilePart fp = new FilePart(text, FilePart.CLASSATTRIBUTE);
+                parts.add(fp);
+                idx += text.length();
+
+            } else if (Utils.startsWith(rest, "typedef")) {
+                int semicolon = Utils.indexOf(rest, ';');
+                int brace = Utils.indexOf(rest, '{');
+
+                if (-1 == semicolon)
+                    Utils.rude("No semicolon found after typedef", name,
+                            lineNo(str, idx), rest.substring(0, rest
+                                    .indexOf("\n")));
+
+                if (-1 == brace || semicolon < brace) {
+                    // Simple typedef
+                    text = str.substring(idx, idx + semicolon + 1);
+                } else {
+                    // Typedef of a struct, etc
+                    int endbrace = Utils.findMatching(rest, '{', '}');
+                    String rest2 = rest.substring(endbrace);
+                    semicolon = Utils.indexOf(rest2, ';');
+                    text = str.substring(idx, idx + endbrace + semicolon + 1);
+                }
+                FilePart fp = new FilePart(text, FilePart.TYPEDEF);
+                parts.add(fp);
+                idx += text.length();
+
+            } else {
+                if (isMethod(rest)) {
+
+                    int brace = Utils.indexOf(rest, '{');
+                    Signature signature = new Signature(str.substring(idx, idx
+                            + brace));
+                    if (signature.failed())
+                        Utils.rude("Signature parsing failed", name, lineNo(
+                                str, idx), signature.getOriginal());
+                    if (null != currentClass
+                            && null == signature.getClassName())
+                        signature.setClassName(currentClass);
+                    signature.setScope(scope);
+                    signature.setNamespace(currentNamespace);
+
+                    String body = rest.substring(brace);
+                    int endBrace = Utils.findMatching(body, '{', '}');
+                    body = body.substring(0, endBrace + 1);
+                    int endIdx = idx + signature.originalLength()
+                            + body.length();
+                    text = str.substring(idx, endIdx);
+                    MethodPart mp = new MethodPart(text, signature, body);
+                    parts.add(mp);
+                    idx += text.length();
+
+                } else if (isField(rest)) {
+                    int semicolon = Utils.indexOf(rest, ';');
+                    text = str.substring(idx, idx + semicolon + 1);
+                    FilePart fp = new FilePart(text, FilePart.FIELD);
+                    parts.add(fp);
+                    idx += text.length();
+
+                } else if (isPrototype(rest)) {
+                    int semicolon = Utils.indexOf(rest, ';');
+                    text = str.substring(idx, idx + semicolon + 1);
+                    PrototypePart pp = new PrototypePart(text, currentClass, currentNamespace);
+                    pp.setScope(scope);
+                    parts.add(pp);
+                    idx += text.length();
+
+                } else {
+                    //TODO other file parts here - not sure if there are any
+                    // others?
+                    Utils.rude("Unrecognised file part", name,
+                            lineNo(str, idx), rest.substring(0, rest
+                                    .indexOf("\n")));
+                } // end if
+            } // end if
+        } // end for
+    }
+
+    public Iterator getPartIterator() {
+        return parts.iterator();
+    }
+
+    private int lineNo(String s, int idx) {
+        int n = 0;
+        for (int i = 0; i < idx && i < s.length(); i++)
+            if ('\n' == s.charAt(i))
+                n++;
+        return n;
+    }
+
+    /**
+     * Find out whether we are defining a class, struct or extern "C" which may
+     * contain function implementations. These will have braces which begin a
+     * new scope. Ignore function prototypes that return a struct. struct mystr {
+     * int f1; }; struct mystr func(); struct mystr func() { struct mystr a;
+     * return a; }
+     */
+    private static boolean beginsScope(String s) throws ParsingException {
+        if (isMethod(s))
+            return false;
+
+        int brace = Utils.indexOf(s, '{');
+        int semicolon = Utils.indexOf(s, ';');
+
+        // Return false for class prototypes, but true for class definitions.
+        if (Utils.startsWith(s, "class")) {
+            if (-1 == brace)
+                return false;
+            if (-1 == semicolon)
+                return true;
+            return brace < semicolon;
+        }
+
+        if (Utils.startsWith(s, "struct")) {
+            if (-1 == brace || -1 == semicolon)
+                return false;
+            return brace < semicolon;
+        }
+
+        //Tuscany handle namespace for prototypes
+        //in a similar way to "class"
+        if (Utils.startsWith(s, "namespace")) {
+            if (-1 == brace || -1 == semicolon)
+                return false;
+            return brace < semicolon;
+        }
+
+        return startsWithExternScope(s);
+    }
+
+    /**
+     * There are 4 types of extern ... extern int field; extern int func();
+     * extern "C" int func() { return 2; } extern "C" { int func() { return 2; } }
+     * This method should return true only for the last of these three examples
+     * since only the last one creates a new scope using braces.
+     */
+    private static boolean startsWithExternScope(String s)
+            throws ParsingException {
+        if (!s.startsWith("extern"))
+            return false;
+
+        int brace = Utils.indexOf(s, '{');
+        int semicolon = Utils.indexOf(s, ';');
+        int bracket = Utils.indexOf(s, '(');
+
+        if (-1 == brace)
+            return false;
+        return (-1 == semicolon || brace < semicolon)
+                && (-1 == bracket || brace < bracket);
+    }
+
+    /**
+     * Find out whether we are defining an enum or union which will contain
+     * braces. Ignore function prototypes that return an enum or union. enum
+     * colour { red, blue }; enum colour func(); enum colour func() { return
+     * colour.red; }
+     */
+    private static boolean isEnumOrUnion(String s) throws ParsingException {
+        if ((!Utils.startsWith(s, "enum") && !Utils.startsWith(s, "union"))
+                || isMethod(s))
+            return false;
+
+        int brace = Utils.indexOf(s, '{');
+        int semicolon = Utils.indexOf(s, ';');
+        return -1 != brace && (-1 == semicolon || brace < semicolon);
+    }
+
+    /**
+     * Rules to recognise fields and methods...
+     * 
+     * Fields must contain a semicolon Methods may or may not contain a
+     * semicolon Prototypes must contain a semicolon Fields may or may not
+     * contain a brace (array initialisers do) Methods must contain a brace
+     * Prototypes must not contain a brace Fields may or may not contain a
+     * bracket (casts do) Methods must contain a bracket Prototypes must contain
+     * a bracket
+     * 
+     * It's a method if it contains a bracket and then a brace before the first
+     * semicolon (if there is a semicolon). It's a prototype if it's not a
+     * method and it contains brackets before a semicolon. It's a field if it's
+     * not a method or a prototype and it contains a semicolon. If it's not a
+     * field, a method or a prototype and we haven't recognised it previously
+     * then it's an error.
+     */
+    private static boolean isMethod(String s) throws ParsingException {
+        int semicolon = Utils.indexOf(s, ';');
+        int brace = Utils.indexOf(s, '{');
+        int bracket = Utils.indexOf(s, '(');
+
+        return (-1 != bracket && -1 != brace && bracket < brace && (-1 == semicolon || brace < semicolon));
+    }
+
+    private static boolean isPrototype(String s) throws ParsingException {
+        int semicolon = Utils.indexOf(s, ';');
+        int bracket = Utils.indexOf(s, '(');
+        return !isMethod(s) && -1 != semicolon && -1 != bracket
+                && bracket < semicolon;
+    }
+
+    private static boolean isField(String s) throws ParsingException {
+        int semicolon = Utils.indexOf(s, ';');
+        return !isMethod(s) && !isPrototype(s) && -1 != semicolon;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String toString() {
+        StringBuffer text = new StringBuffer();
+        for (int i = 0; i < parts.size(); i++) {
+            text.append(((FilePart) (parts.get(i))).toString());
+        }
+        return text.toString();
+    }
+
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/InputCppSourceCode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/InputCppSourceCode.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MacroPart.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MacroPart.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MacroPart.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MacroPart.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,82 @@
+/*
+ * 
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+/*
+ * Branched from the original class that was also contributed to the
+ * org.apache.axis.tools.common package.
+ */
+
+/*
+ * A C or C++ macro as it is used in the source code
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+class MacroPart extends FilePart {
+    /**
+     * Factory method to create a MacroPart.
+     * 
+     * @param s
+     *            unparsed source code which may start with a define or macro.
+     */
+    static MacroPart create(String s) {
+        String orig = getOriginalText(s);
+        if (null == orig)
+            return null;
+        return new MacroPart(orig);
+    }
+
+    MacroPart(String s) {
+        super(s, FilePart.MACRO);
+    }
+
+    /**
+     * @param s
+     *            unparsed source code which may start with a define or macro.
+     * @return all of s up to the end of the define or macro.
+     */
+    private static String getOriginalText(String s) {
+        String name = getName(s);
+        int len = name.length();
+        if (null == name)
+            return null;
+        else if (Configuration.isDefine(name)) {
+            return s.substring(0, len);
+        } else if (Configuration.isMacro(name)) {
+            String rest = s.substring(len);
+            len += Utils.findMatching(rest, '(', ')');
+            return s.substring(0, len + 1);
+        } else
+            return null;
+    }
+
+    static boolean isAMacro(String s) {
+        if (s == null || 0 == s.length())
+            return false;
+        String name = getName(s);
+        return Configuration.isMacro(name) || Configuration.isDefine(name);
+    }
+
+    private static String getName(String s) {
+        int i;
+        for (i = 0; i < s.length(); i++)
+            if (!Character.isLetterOrDigit(s.charAt(i)) && '_' != s.charAt(i))
+                break;
+        if (s.length() == i)
+            return null;
+        return s.substring(0, i);
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MacroPart.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MacroPart.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MethodPart.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MethodPart.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MethodPart.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MethodPart.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,128 @@
+/*
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/*
+ *  Branched from the original class that was also contributed to the 
+ *  org.apache.axis.tools.common package.
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+import java.util.ArrayList;
+
+/**
+ * A C or C++ method from a piece of source code. The method has a signature and
+ * a body (the bit between the braces).
+ */
+public class MethodPart extends FilePart {
+    private Signature signature;
+
+    private String body;
+
+    MethodPart(String s, Signature signature, String body) {
+        super(s, METHOD);
+        this.signature = signature;
+        this.body = body;
+    }
+
+    public Signature getSignature() {
+        return signature;
+    }
+
+    public String getOriginalSignature() {
+        return signature.getOriginal();
+    }
+
+    /**
+     * Returns the method body as code snippets, each ending with a place where
+     * a trace statement belongs. The end of the first code snippet is where the
+     * entry trace should go. The end of every other snippet is a return from
+     * the method.
+     */
+    public BodyPart[] getBodyParts() throws ParsingException {
+        String b = body; // Don't alter field member
+        if (b.startsWith("{"))
+            b = b.substring(1);
+
+        // Add in trace exit at all the return statements in the method.
+        ArrayList al = new ArrayList();
+        int idxR = Utils.indexOf(b, "return");
+        int idxC = Utils.indexOf(b, "catch");
+        while (-1 != idxR || -1 != idxC) {
+            if (-1 == idxC || (-1 != idxR && idxR < idxC)) {
+                String frag = b.substring(0, idxR);
+                String rest = b.substring(idxR + "return".length());
+
+                int semicolon = Utils.indexOf(rest, ';');
+                if (-1 == semicolon)
+                    Utils.rude("Missing semicolon in " + signature);
+                String retVal = rest.substring(0, semicolon);
+                BodyPart bp = new BodyPart(frag, retVal);
+                al.add(bp);
+                b = b.substring(idxR + "return".length() + retVal.length() + 1);
+            } else {
+                String frag = b.substring(0, idxC);
+                String rest = b.substring(idxC);
+
+                int brace = Utils.indexOf(rest, "{");
+                if (-1 == brace)
+                    Utils.rude("Missing open brace in " + signature);
+                Signature signature = new Signature(rest.substring(0, brace));
+                frag = frag + rest.substring(0, brace + 1);
+                BodyPart bp = new BodyPart(frag, signature.getParameters()[0]);
+                al.add(bp);
+                b = rest.substring(brace + 1);
+            }
+            idxR = Utils.indexOf(b, "return");
+            idxC = Utils.indexOf(b, "catch");
+        }
+
+        // Add in trace exit before the last } if there are no returns in
+        // the method or there is code after the last return and the method
+        // returns void.
+        // int f1(){try{return f2();}catch(Exception& e){throw;}}
+        // has code after the last return but having a traceexit before the
+        // last brace wouldn't compile since the method returns an int. We
+        // cope with this by only adding in a traceexit before the last brace
+        // if the method returns void. That may mean we add in an unreachable
+        // traceexit which may give a compiler warning, but that should be
+        // benign.
+        //
+        // TODO: Not quite good enough for
+        // void f(int a){if(a){printf("a");}else{printf("!a");return;}}
+        // as a trace exit is needed before the last } in case a>0 but
+        // void f(int a){if(a){printf("a");return;}else{printf("!a");return;}}
+        // would give compiler warnings about unreachable code if a trace
+        // exit is added before the last brace. This could be tricky to fix.
+        if ((0 == al.size() || -1 != Utils.indexOf(b, ';'))
+                && null == signature.getReturnType().getType()) {
+
+            int last = b.lastIndexOf('}');
+            if (-1 == last)
+                Utils.rude("Missing end brace in " + signature);
+            String b2 = b.substring(0, last);
+            al.add(new BodyPart(b2));
+            b = b.substring(last);
+        }
+
+        // The final body part is the last }
+        al.add(new BodyPart(b));
+
+        BodyPart[] bps = new BodyPart[al.size()];
+        System.arraycopy(al.toArray(), 0, bps, 0, al.size());
+        return bps;
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MethodPart.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/MethodPart.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Options.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Options.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Options.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Options.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,110 @@
+/*
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/*
+ *  Branched from the original class that was also contributed to the 
+ *  org.apache.axis.tools.common package.
+ *  
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Command line options passed to a tool's main program. All command line
+ * options should begin with a dash "-". Some command line options take a value
+ * which is the next parameter after the option. Others do not.
+ */
+public class Options {
+    static HashMap pairs = new HashMap();
+
+    static List values = new ArrayList();
+
+    /**
+     * No one constructs this class.
+     */
+    private Options() {
+    }
+
+    public static void reset() {
+        pairs = new HashMap();
+        values = new ArrayList();
+    }
+
+    /**
+     * Initialises the options based on the args passed to main
+     */
+    public static void set(String args[]) {
+        for (int i = 0; i < args.length; i++) {
+            if (args[i].startsWith("-")) {
+                if ((i + 1 <= args.length - 1) && // next one is testable
+                        !args[i + 1].startsWith("-") // and it starts with a "-"
+                ) {
+                    String key = args[i];
+                    Object pairValue = pairs.get(key);
+                    if (null == pairValue) {
+                        pairs.put(args[i], args[i + 1]);
+                    } else if (pairValue instanceof String) {
+                        List l = new ArrayList();
+                        l.add(pairValue);
+                        l.add(args[i + 1]);
+                        pairs.put(key, l);
+                    } else if (pairValue instanceof List) {
+                        ((List) pairValue).add(args[i + 1]);
+                    }
+                    i++; // Step over value for this key
+                } else
+                    values.add(args[i]);
+            }
+        }
+    }
+
+    public static Object getOption(String key) {
+        return pairs.get(key);
+    }
+
+    static boolean isOptionSet(String key) {
+        return values.contains(key);
+    }
+
+    public static boolean verbose() {
+        return isOptionSet("-verbose");
+    }
+
+    public static boolean debug() {
+        return isOptionSet("-debug");
+    }
+
+    public static boolean deploy() {
+        return isOptionSet("-deploy");
+    }
+
+    public static boolean noGenerate() {
+        return isOptionSet("-nogenerate");
+    }
+
+    public static boolean outputCommand() {
+        return isOptionSet("-outputCommand");
+    }
+
+
+    public static boolean quiet() {
+        return isOptionSet("-quiet");
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Options.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Options.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Parameter.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Parameter.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Parameter.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Parameter.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,211 @@
+/*
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/*
+ *  Branched from the original class that was also contributed to the 
+ *  org.apache.axis.tools.common package.
+ *  
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A parameter from a method signature. The parameter is the datatype plus its
+ * name but not its value.
+ */
+public class Parameter {
+    private ArrayList type = new ArrayList();
+
+    private String name = null;
+
+    private boolean failed = false;
+
+    /**
+     * Defaults to a parameter in a parameter list so it HAS a parameter name in
+     * it
+     */
+    Parameter(List parts) {
+        this(parts, false);
+    }
+
+    /**
+     * A parameter which is a return type does not have a parameter name.
+     * Parameters in a parameter list do have parameter names embedded in them
+     */
+    Parameter(List parts, boolean isRetType) {
+        if (parts == null || parts.size() == 0)
+            return;
+
+        // Tuscany: The original code below from apache axis blocks int
+        // getCustomer(long)
+        // i.e. no spaces in parameter list.
+        // We do not need to deal with "..." as parameters to SCS methods.
+        // 
+        //        if (!isRetType && parts.size() == 1) {
+        //            if ("...".equals(parts.get(0))) {
+        //                type.add("...");
+        //                name = "";
+        //            } else if (!"void".equals(parts.get(0)))
+        //                failed = true; // Seems like bad C++ code here
+        //            return;
+        //        }
+
+        if (isRetType) {
+            Iterator it = parts.iterator();
+            while (it.hasNext())
+                type.add(it.next());
+
+            // Some methods return have void on their signature and others
+            // have nothing. So to make them both the same, if a method
+            // doesn't return anything make type null.
+            // TODO: This assumption is wrong - methods that return nothing
+            // default to returning an int!
+            if (1 == type.size() && "void".equals(type.get(0)))
+                type = new ArrayList();
+
+        } else {
+            // Cope with array subscripts [] after the name
+            int arrIdx = -1;
+            for (int i = 0; i < parts.size(); i++) {
+                String tok = (String) parts.get(i);
+                if ("[".equals(tok)) {
+                    arrIdx = i;
+                    break;
+                }
+            }
+
+            // Find the name
+            int nameIdx = parts.size() - 1;
+            if (-1 != arrIdx)
+                nameIdx = arrIdx - 1;
+
+            // Even in real method declarations, parameters may not have a name
+            boolean noName = false;
+            name = (String) parts.get(nameIdx);
+            // Tuscany: The original code below from apache axis
+            // was updated to work with signatures of
+            // the form fn(int) a non-named, no-space, parameter list.
+            // if (Utils.cPrimitives.contains(name) ||
+            // Utils.cTypeQualifiers.contains(name) )
+            //
+            if (Utils.cPrimitives.contains(name)
+                    || Utils.cTypeQualifiers.contains(name)
+                    || parts.size() == 1)
+                noName = true;
+
+            if (noName) {
+                name = null;
+                for (int i = 0; i < parts.size(); i++)
+                    type.add(parts.get(i));
+            } else {
+                // Construct the type
+                for (int i = 0; i < nameIdx; i++)
+                    type.add(parts.get(i));
+
+                if (-1 != arrIdx)
+                    for (int i = arrIdx; i < parts.size(); i++)
+                        type.add(parts.get(i));
+            }
+        }
+    }
+
+    public boolean failed() {
+        return failed;
+    }
+
+    public String getType() {
+        String s = null;
+        Iterator it = type.iterator();
+        while (it.hasNext()) {
+            String next = (String) it.next();
+            if (null == s)
+                s = next;
+            else if ("*".equals(next) || "&".equals(next))
+                s += next;
+            else
+                s += " " + next;
+        }
+        return s;
+    }
+
+    public String getTypeWithoutConst() {
+        String s = null;
+        Iterator it = type.iterator();
+        while (it.hasNext()) {
+            String next = (String) it.next();
+            if ("const".equals(next))
+                continue;
+            else if (null == s)
+                s = next;
+            else if ("*".equals(next) || "&".equals(next))
+                s += next;
+            else
+                s += " " + next;
+        }
+        return s;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public boolean isVoid() {
+        return 0 == type.size();
+    }
+
+    public boolean isDotDotDot() {
+        return 1 == type.size() && "...".equals(type.get(0));
+    }
+
+    /**
+     * For two parameters to match their types must match or both be null, but
+     * the parameters names don't have to match. Just because a parameter is
+     * called something different in a header file as in the the source file
+     * doesn't mean it's a different parameter.
+     */
+    public boolean equals(Object o) {
+        if (null == o || !(o instanceof Parameter))
+            return false;
+        Parameter that = (Parameter) o;
+        if (type.size() != that.type.size())
+            return false;
+        for (int i = 0; i < type.size(); i++) {
+            String s1 = (String) type.get(i);
+            String s2 = (String) that.type.get(i);
+            if (!Utils.safeEquals(s1, s2))
+                return false;
+        }
+        return true;
+    }
+
+    public String toString() {
+        if (0 == type.size())
+            return "void";
+        if (null == name)
+            return getType();
+        return getType() + " " + name;
+    }
+
+    public Iterator iterator() {
+        if (null == type)
+            return null;
+        return type.iterator();
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Parameter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Parameter.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/ParsingException.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/ParsingException.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/ParsingException.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/ParsingException.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,42 @@
+/*
+ * 
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+/*
+ * Branched from the original class that was also contributed to the
+ * org.apache.axis.tools.common package.
+ *  
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+public class ParsingException extends Exception {
+
+    public ParsingException() {
+        super();
+    }
+
+    public ParsingException(String message) {
+        super(message);
+    }
+
+    public ParsingException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public ParsingException(Throwable cause) {
+        super(cause);
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/ParsingException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/ParsingException.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/PrototypePart.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/PrototypePart.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/PrototypePart.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/PrototypePart.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,51 @@
+/*
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/*
+ *  Branched from the original class that was also contributed to the 
+ *  org.apache.axis.tools.common package.
+ *  
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+/**
+ * A function prototype in an include file and possibly in a class definition.
+ */
+public class PrototypePart extends FilePart {
+    private Signature signature;
+
+    public PrototypePart(String s, String className, String namespace) {
+        super(s, PROTOTYPE);
+        signature = new Signature(s);
+        if (null != className)
+            signature.setClassName(className);
+        if (null != namespace && namespace.length()>0)
+            signature.setNamespace(namespace);
+    }
+
+    String className() {
+        return signature.getClassName();
+    }
+
+    public Signature getSignature() {
+        return signature;
+    }
+
+    public void setScope(String scope) {
+        signature.setScope(scope);
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/PrototypePart.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/PrototypePart.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Signature.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Signature.java?rev=366157&view=auto
==============================================================================
--- incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Signature.java (added)
+++ incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Signature.java Thu Jan  5 02:54:16 2006
@@ -0,0 +1,501 @@
+/*
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/*
+ *  Branched from the original class that was also contributed to the 
+ *  org.apache.axis.tools.common package.
+ *  
+ */
+package org.apache.tuscany.sca.cpp.tools.common;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * A C or C++ method signature with the ability to parse it. TODO: properly
+ * support variable length argument lists using "..." TODO: passing or returning
+ * function pointers (hopefully not needed) TODO: Cope with ~ <space>Classname()
+ */
+public class Signature {
+    private String originalText;
+
+    private String attributes;
+
+    private String className = null;
+    
+    private String namespace = null;
+
+    private String methodName = null;
+
+    private Parameter returnType = null;
+
+    private Parameter[] params = null;
+
+    private String trailingAttributes;
+
+    private String scope = "public";
+
+    private boolean failed = false;
+
+    private boolean traceable = true;
+
+    private final static Set knownAttrs = new HashSet(Arrays
+            .asList(new Object[] { "public", "private", "extern", "\"C\"",
+                    "virtual", "static", "inline" }));
+
+    private final static Set specialOperators = new HashSet(
+            Arrays.asList(new Object[] { "(", ")", "*", ",", "&", "]", "[",
+                    "=", "~" }));
+
+    /**
+     * Takes an unparsed signature string and parses it.
+     * 
+     * TODO: Should optionally pass in the className here in case it's an inline
+     * method implementation inside the class{}. Just so the className comes out
+     * in the trace.
+     */
+    Signature(String s) {
+        originalText = s;
+
+        try {
+            List tokens = tokenise(s);
+
+            ArrayList alAttrs = new ArrayList();
+            ArrayList alName = new ArrayList();
+            ArrayList alParms = new ArrayList();
+            ArrayList alTrailAttrs = new ArrayList();
+            ArrayList alInits = new ArrayList();
+            if (!splitUp(tokens, alAttrs, alName, alParms, alTrailAttrs,
+                    alInits)) {
+                failed = true;
+                return;
+            }
+
+            parseAttributes(alAttrs);
+            parseNameAndRetType(alName);
+            parseParameters(alParms);
+            parseTrailingAttributes(alTrailAttrs);
+
+            // Ignore any tokens after the ) since these are (hopefully)
+            // constructor initialisers
+
+            traceable = !Configuration.methodExcluded(className, methodName);
+        } catch (NullPointerException npe) {
+            failed = true;
+            traceable = false;
+        }
+    }
+
+    /**
+     * Parse the signature into tokens. This removes whitespace and comments and
+     * separates out "*", ",", "(", ")", "&", "[" and "]".
+     */
+    private static List tokenise(String s) {
+        ArrayList tokens = new ArrayList();
+        String tok = null;
+        boolean space = true;
+        for (int i = 0; i < s.length(); i++) {
+            char c = s.charAt(i);
+            if (Character.isWhitespace(c)) {
+                space = true;
+                continue;
+            }
+            if (space) {
+                if (tok != null)
+                    tokens.add(tok);
+                tok = "" + c;
+            } else
+                tok += c;
+            space = false;
+
+            if (tok.endsWith("/*")) {
+                String sub = s.substring(i);
+                int endcomm = sub.indexOf("*/");
+                if (endcomm == -1)
+                    break;
+                i += endcomm + 1;
+                if (tok.equals("/*"))
+                    tok = "";
+                else
+                    tok = tok.substring(0, tok.length() - 2);
+                continue;
+            }
+
+            if (tok.endsWith("//")) {
+                String sub = s.substring(i);
+                int endcomm = sub.indexOf("\n");
+                if (endcomm == -1)
+                    break;
+                i += endcomm;
+                if (tok.equals("//"))
+                    tok = "";
+                else
+                    tok = tok.substring(0, tok.length() - 1);
+                continue;
+            }
+
+            if (tok.endsWith("::"))
+                space = true;
+
+            String sc = "" + c;
+            if (specialOperators.contains(sc)) {
+                if (!tok.equals(sc)) {
+                    tokens.add(tok.substring(0, tok.length() - 1));
+                    tok = sc;
+                }
+                space = true;
+            }
+        }
+        tokens.add(tok);
+        return tokens;
+    }
+
+    /**
+     * Split up a tokenised method signature into a list of attributes, a list
+     * of name and return type tokens, a list of parameter tokens and a list of
+     * initialiser tokens.
+     */
+    private static boolean splitUp(List tokens, List attrs, List nameAndRet,
+            List parms, List trailAttrs, List inits) {
+
+        // nameStart points to the start of the return type if there is one
+        // else the start of the method name
+        int nameStart;
+        for (nameStart = 0; nameStart < tokens.size(); nameStart++) {
+            String tok = (String) (tokens.get(nameStart));
+            if (!knownAttrs.contains(tok) && !Configuration.isAttribute(tok))
+                break;
+        }
+        if (nameStart == tokens.size())
+            return false;
+
+        // initStart points to the initialisers, or thrown exceptions after
+        // the parameter list. throw is a keyword so we can safely search for
+        // it.
+        int initStart = tokens.size();
+        for (int i = nameStart; i < tokens.size(); i++) {
+            String tok = (String) tokens.get(i);
+            if ((tok.startsWith(":") && !tok.startsWith("::"))
+                    || "throw".equals(tok))
+                initStart = i;
+        }
+
+        int parmEnd;
+        for (parmEnd = initStart - 1; parmEnd > nameStart; parmEnd--)
+            if (")".equals(tokens.get(parmEnd)))
+                break;
+        if (parmEnd == nameStart)
+            return false;
+
+        int parmStart = parmEnd;
+        for (parmStart = parmEnd; parmStart > nameStart; parmStart--)
+            if ("(".equals(tokens.get(parmStart)))
+                break;
+
+        for (int i = 0; i < tokens.size(); i++) {
+            Object tok = tokens.get(i);
+            if (i < nameStart || Configuration.isAttribute((String) tok))
+                attrs.add(tok);
+            else if (i < parmStart)
+                nameAndRet.add(tok);
+            else if (i <= parmEnd)
+                parms.add(tok);
+            else if (i < initStart)
+                trailAttrs.add(tok);
+            else
+                inits.add(tok);
+        }
+        return true;
+    }
+
+    private void parseAttributes(List list) {
+        attributes = new String();
+        Iterator it = list.iterator();
+        while (it.hasNext()) {
+            if (attributes.length() > 0)
+                attributes += " ";
+            String next = (String) it.next();
+            
+            //Tuscancy 
+            //the scope is not present in the attributes
+            //but is set later in the InputCppSource contructor
+            if ("public".equals(next) || "protected".equals(next)
+                    || "private".equals(next))
+                scope = next;
+            attributes += next;
+        }
+    }
+
+    private void parseNameAndRetType(List list) {
+        int size = list.size();
+        int idx;
+        // "operator" is a key word so if it's present we know we're
+        // dealing with operator overloading. The operator that's been
+        // overloaded might have been split up into multiple tokens.
+        for (idx = 0; idx < size; idx++)
+            if ("operator".equals(list.get(idx)))
+                break;
+
+        if (idx < size) {
+            methodName = "";
+            for (int i = idx; i < size; i++)
+                methodName += (String) list.get(i);
+        } else { // No operator overloading
+            methodName = "" + list.get(size - 1);
+            idx = size - 1;
+        }
+
+        // If it's a destructor, the "~" will be split out into a separate
+        // token, so add it onto the methodName here.
+        if (idx > 0 && "~".equals(list.get(idx - 1))) {
+            methodName = "~" + methodName;
+            idx--;
+        }
+
+        // The class name comes before the method name
+        while (idx > 0 && ((String) list.get(idx - 1)).endsWith("::")) {
+            if (null == className)
+                className = (String) list.get(idx - 1);
+            else
+                className = (String) list.get(idx - 1) + className;
+            idx--;
+        }
+
+        // Whatever's left before the classname/methodname must be the
+        // return type
+        ArrayList retParm = new ArrayList();
+        for (int i = 0; i < idx; i++)
+            retParm.add(list.get(i));
+
+        returnType = new Parameter(retParm, true);
+    }
+
+    /**
+     * Constructs the parameter list
+     */
+    private void parseParameters(List list) {
+        ArrayList alParams = new ArrayList();
+        Iterator it = list.iterator();
+        String token = (String) it.next(); // step over the (
+        while (it.hasNext() && !")".equals(token)) {
+            token = (String) it.next();
+
+            int template = 0; // Depth of template scope
+            boolean foundEquals = false;
+            // Ignore default value for an optional parameter
+            ArrayList parm = new ArrayList();
+            while (!token.equals(")") && (!token.equals(",") || template > 0)) {
+                if (token.equals("="))
+                    foundEquals = true;
+                if (!foundEquals)
+                    parm.add(token);
+                if (contains(token, "<"))
+                    template++;
+                if (contains(token, ">"))
+                    template--;
+                token = (String) it.next();
+            }
+
+            // No parameters so break out
+            if (token.equals(")") && 0 == parm.size())
+                break;
+
+            Parameter p = new Parameter(parm);
+            if (p.failed()) {
+                failed = true;
+                return;
+            }
+
+            // Copes with void func(void)
+            if (!p.isVoid())
+                alParams.add(p);
+        }
+
+        int size = alParams.size();
+        if (size > 0) {
+            params = new Parameter[size];
+            System.arraycopy(alParams.toArray(), 0, params, 0, size);
+        }
+    }
+
+    private void parseTrailingAttributes(List list) {
+        trailingAttributes = new String();
+        Iterator it = list.iterator();
+        while (it.hasNext()) {
+            if (trailingAttributes.length() > 0)
+                trailingAttributes += " ";
+            trailingAttributes += (String) it.next();
+        }
+    }
+
+    public String getOriginal() {
+        return originalText;
+    }
+
+    public int originalLength() {
+        return originalText.length();
+    }
+
+    public boolean failed() {
+        return failed;
+    }
+
+    public String getAttributes() {
+        return attributes;
+    }
+
+    public String getClassName() {
+        return className;
+    }
+
+    /**
+     * @param namespace The namespace to set.
+     */
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+
+    /**
+     * @return Returns the namespace.
+     */
+    public String getNamespace() {
+        return namespace;
+    }
+
+    public String getTrimClassName() {
+        return trimClassName(className);
+    }
+
+    public String getMethodName() {
+        return methodName;
+    }
+
+    public Parameter getReturnType() {
+        return returnType;
+    }
+
+    public Parameter[] getParameters() {
+        return params;
+    }
+
+    public boolean isConstructor() {
+        return className != null && methodName != null
+                && trimClassName(className).equals(methodName);
+    }
+
+    public boolean isDestructor() {
+        return className != null && methodName != null
+                && methodName.startsWith("~")
+                && methodName.endsWith(trimClassName(className));
+    }
+
+    private static String trimClassName(String name) {
+        if (name.endsWith("::"))
+            return name.substring(0, name.length() - 2);
+        return name;
+    }
+
+    void setClassName(String className) {
+        if (null == className)
+            return;
+        if (!className.endsWith("::"))
+            className += "::";
+        this.className = className;
+    }
+
+    public String getScope() {
+        return scope;
+    }
+
+    /**
+     * Sets the scope, but only if the scope is not set by an explicit attribute
+     * in the signature.
+     */
+    public void setScope(String scope) {
+        if (-1 == attributes.indexOf(this.scope))
+            this.scope = scope;
+    }
+
+    /**
+     * Should this method be traced?
+     */
+    public boolean traceable() {
+        return traceable;
+    }
+
+    private static boolean contains(String src, String tgt) {
+        if (src == null || tgt == null)
+            return false;
+        if (-1 == src.indexOf(tgt))
+            return false;
+        return true;
+    }
+
+    public boolean equals(Object obj) {
+        if (null == obj || !(obj instanceof Signature))
+            return false;
+        Signature that = (Signature) obj;
+        if (!Utils.safeEquals(className, that.className))
+            return false;
+        if (!Utils.safeEquals(methodName, that.methodName))
+            return false;
+        if (!Utils.safeEquals(returnType, that.returnType))
+            return false;
+        if (null == params && null == that.params)
+            return true;
+        if (null != params && null == that.params)
+            return false;
+        if (null == params && null != that.params)
+            return false;
+        if (params.length != that.params.length)
+            return false;
+        for (int i = 0; i < params.length; i++)
+            if (!Utils.safeEquals(params[i], that.params[i]))
+                return false;
+        return true;
+    }
+
+    public String toStringWithoutAttrs() {
+        String s = new String();
+        if (returnType != null)
+            s += returnType + " ";
+        if (className != null)
+            s += className;
+        s += methodName + "(";
+        for (int i = 0; params != null && i < params.length; i++) {
+            if (i > 0)
+                s += ", ";
+            s += params[i].toString();
+        }
+        s += ")";
+        return s;
+    }
+
+    public String toString() {
+        String s = attributes;
+        if (attributes.length() > 0)
+            s += " ";
+        s += toStringWithoutAttrs();
+        if (trailingAttributes.length() > 0)
+            s += " " + trailingAttributes;
+        return s;
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Signature.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/cpp/sca/tools/scagen/src/org/apache/tuscany/sca/cpp/tools/common/Signature.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date



Mime
View raw message