You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/08/02 18:17:04 UTC
svn commit: r1368572 [1/2] - in
/incubator/etch/trunk/binding-cpp/compiler/src/main:
java/org/apache/etch/bindings/cpp/compiler/
resources/org/apache/etch/bindings/cpp/compiler/
Author: veithm
Date: Thu Aug 2 16:17:03 2012
New Revision: 1368572
URL: http://svn.apache.org/viewvc?rev=1368572&view=rev
Log:
ETCH-198 ETCH-195 Implementation of cpp compiler
Added compiler implementation
Added velocity templates used for code generation
Change-Id: I86af43a7b93f34e55779b5c4787038851ff22c1f
Added:
incubator/etch/trunk/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/Compiler.java
incubator/etch/trunk/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/IncludeTreeWalker.java
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/base_cpp.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/base_h.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/etch_wireshark.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_h.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/impl_cpp.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/impl_h.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/intf_cpp.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/intf_h.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/main_cpp.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/main_h.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/readme.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_cpp.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/remote_h.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/stub_cpp.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/stub_h.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_cpp.vm
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/vf_h.vm
Modified:
incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/cppKeywords.kwd
Added: incubator/etch/trunk/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/Compiler.java
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/Compiler.java?rev=1368572&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/Compiler.java (added)
+++ incubator/etch/trunk/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/Compiler.java Thu Aug 2 16:17:03 2012
@@ -0,0 +1,1699 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.etch.bindings.cpp.compiler;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.etch.compiler.Backend;
+import org.apache.etch.compiler.CmdLineOptions;
+import org.apache.etch.compiler.EtchGrammarConstants;
+import org.apache.etch.compiler.LogHandler;
+import org.apache.etch.compiler.Output;
+import org.apache.etch.compiler.ParseException;
+import org.apache.etch.compiler.Token;
+import org.apache.etch.compiler.Version;
+import org.apache.etch.compiler.ast.Builtin;
+import org.apache.etch.compiler.ast.Enumx;
+import org.apache.etch.compiler.ast.Except;
+import org.apache.etch.compiler.ast.Item;
+import org.apache.etch.compiler.ast.Message;
+import org.apache.etch.compiler.ast.MessageDirection;
+import org.apache.etch.compiler.ast.Module;
+import org.apache.etch.compiler.ast.MsgDirHelper;
+import org.apache.etch.compiler.ast.Name;
+import org.apache.etch.compiler.ast.Named;
+import org.apache.etch.compiler.ast.ParamList;
+import org.apache.etch.compiler.ast.Parameter;
+import org.apache.etch.compiler.ast.ReservedWordChecker;
+import org.apache.etch.compiler.ast.Service;
+import org.apache.etch.compiler.ast.Struct;
+import org.apache.etch.compiler.ast.Thrown;
+import org.apache.etch.compiler.ast.TypeRef;
+import org.apache.etch.compiler.opt.ToString;
+import org.apache.etch.compiler.opt.ToString.FieldItem;
+import org.apache.etch.compiler.opt.ToString.FmtItem;
+import org.apache.etch.compiler.opt.ToString.StringItem;
+import org.apache.etch.util.Assertion;
+import org.apache.etch.util.Hash;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.log.LogChute;
+
+/**
+ * Compiler is a helper class not only for Backend, but also for the templates.
+ * They call methods here to perform "hard" tasks.
+ */
+public class Compiler extends Backend {
+
+ private final static String tmplPath1 = "org/apache/etch/bindings/cpp/compiler/";
+
+ private final static String tmplPath2 = "resources/org/apache/etch/bindings/cpp/compiler/";
+
+ /**
+ * Filename suffix for Header and Implementation files
+ */
+ private final static String fnSuffixH = ".h";
+ private final static String fnSuffixI = ".cpp";
+
+ /**
+ * Folder Name - Include and Source
+ */
+ private final static String fnInclude = "include/";
+ private final static String fnSource = "src/";
+
+ private final static String VERSION = Version.VERSION + " / "
+ + CompilerVersion.VERSION;
+
+ /**
+ * Constructs the Compiler. This is a helper class not only for Backend, but
+ * also for the templates. They call methods here to perform "hard" tasks. * @throws
+ * Exception
+ */
+ public Compiler() throws Exception {
+ this.initVelocity();
+
+ String[] path = { tmplPath1, tmplPath2 };
+
+ // value factory templates
+ this.vf_h_vm = this.getTemplate(path, "vf_h.vm");
+ this.vf_cpp_vm = this.getTemplate(path, "vf_cpp.vm");
+
+ // interface templates
+ this.intf_h_vm = this.getTemplate(path, "intf_h.vm");
+ this.intf_cpp_vm = this.getTemplate(path, "intf_cpp.vm");
+
+ // interface remote templates
+ this.remote_h_vm = this.getTemplate(path, "remote_h.vm");
+ this.remote_cpp_vm = this.getTemplate(path, "remote_cpp.vm");
+
+ // interface stub templates
+ this.stub_h_vm = this.getTemplate(path, "stub_h.vm");
+ this.stub_cpp_vm = this.getTemplate(path, "stub_cpp.vm");
+
+ // helper templates
+ this.helper_h_vm = this.getTemplate(path, "helper_h.vm");
+ this.helper_cpp_vm = this.getTemplate(path, "helper_cpp.vm");
+
+ this.readme_vm = this.getTemplate(path, "readme.vm");
+
+ // Main template
+ this.main_h_vm = this.getTemplate(path, "main_h.vm");
+ this.main_cpp_vm = this.getTemplate(path, "main_cpp.vm");
+
+ // Base template
+ this.base_h_vm = this.getTemplate(path, "base_h.vm");
+ this.base_cpp_vm = this.getTemplate(path, "base_cpp.vm");
+
+ // Implementation template
+ this.impl_h_vm = this.getTemplate(path, "impl_h.vm");
+ this.impl_cpp_vm = this.getTemplate(path, "impl_cpp.vm");
+
+ // Wireshark
+ this.etch_wireshark_vm = this.getTemplate(path, "etch_wireshark.vm");
+
+ // Keyword list
+ this.local_kwd = this.getPath(path, "cppKeywords.kwd");
+ }
+
+ // interface templates
+ private final Template intf_h_vm;
+ private final Template intf_cpp_vm;
+
+ // Base template
+ private final Template base_h_vm;
+ private final Template base_cpp_vm;
+
+ // Value Factory
+ private final Template vf_h_vm;
+ private final Template vf_cpp_vm;
+
+ // remote interface templates
+ private final Template remote_h_vm;
+ private final Template remote_cpp_vm;
+
+ // interface stub templates
+ private final Template stub_h_vm;
+ private final Template stub_cpp_vm;
+
+ // helper templates
+ private final Template helper_h_vm;
+ private final Template helper_cpp_vm;
+
+ private final Template readme_vm;
+
+ // Main template
+ private final Template main_h_vm;
+ private final Template main_cpp_vm;
+
+ // Implementation template
+ private final Template impl_h_vm;
+ private final Template impl_cpp_vm;
+
+ private final Template etch_wireshark_vm;
+
+ private final String local_kwd;
+
+ private LogHandler lh;
+
+ /**
+ * Initializes use of velocity engine and sets up resource loaders. * @throws
+ * Exception
+ */
+ private void initVelocity() throws Exception {
+ Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new MyLogger());
+ Velocity.setProperty(Velocity.RESOURCE_LOADER, "file, class");
+
+ Velocity.setProperty("file.resource.loader.description",
+ "Velocity File Resource Loader");
+ Velocity.setProperty("file.resource.loader.class",
+ "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
+ Velocity.setProperty("file.resource.loader.path", ".");
+
+ Velocity.setProperty("class.resource.loader.description",
+ "Velocity Classpath Resource Loader");
+ Velocity.setProperty("class.resource.loader.class",
+ "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
+ Velocity.init();
+ }
+
+ private static class MyLogger implements LogChute {
+ private final LogHandler lh = null;
+
+ @Override
+ public void init(RuntimeServices rts) throws Exception {
+ // ignore.
+ }
+
+ @Override
+ public boolean isLevelEnabled(int level) {
+ return level >= 2;
+ }
+
+ @Override
+ public void log(int level, String msg) {
+ if (level < 2)
+ return;
+ if (this.lh != null)
+ this.lh.report(level == 2 ? LogHandler.LEVEL_WARNING
+ : LogHandler.LEVEL_ERROR, null, msg);
+ else
+ System.out.printf("Velocity msg (%d): %s\n", level, msg);
+ }
+
+ @Override
+ public void log(int level, String msg, Throwable e) {
+ if (level < 2)
+ return;
+ if (this.lh != null)
+ this.lh.report(level == 2 ? LogHandler.LEVEL_WARNING
+ : LogHandler.LEVEL_ERROR, null, msg);
+ else
+ System.out.printf("Velocity msg (%d): %s: %s\n", level, msg, e);
+ }
+ }
+
+ /**
+ * @param path
+ * @param fn
+ * @return the velocity template
+ * @throws Exception
+ */
+ private Template getTemplate(String[] path, String fn) throws Exception {
+ ResourceNotFoundException rnfe = null;
+
+ for (String p : path) {
+ if (p == null)
+ continue;
+
+ // System.out.println( "trying to load template "+(p+fn) );
+ try {
+ if (Velocity.resourceExists(p + fn))
+ return Velocity.getTemplate(p + fn);
+ } catch (ResourceNotFoundException e) {
+ rnfe = e;
+ } catch (Exception e) {
+ System.out.println("ignoring " + e);
+ }
+ }
+
+ if (rnfe != null)
+ throw rnfe;
+
+ throw new ResourceNotFoundException("could not find resource: " + fn);
+ }
+
+ @Override
+ public void generate(Module module, CmdLineOptions options) throws Exception {
+ // java always wants to not flatten packages:
+ options.noFlattenPackages = true;
+
+ this.lh = options.lh;
+
+ boolean ignoreGlobal = options.ignoreGlobalWordsList;
+ boolean ignoreLocal = options.ignoreLocalWordsList;
+ String userWords = options.userWordsList != null ? options.userWordsList
+ .getPath() : null;
+ Set<String> what = options.what;
+
+ // Load the reserved words lists if any have been provided.
+ Map<String, String> words = new HashMap<String, String>();
+ if (!ignoreGlobal)
+ this.mapWords(this.global_kwd, words);
+ if (!ignoreLocal)
+ this.mapWords(this.local_kwd, words);
+ if (userWords != null)
+ this.mapWords(userWords, words);
+
+ // check for collisions with the reserved word list.
+ ReservedWordChecker checker = new ReservedWordChecker(words, false, this.lh);
+ module.treewalk(checker);
+ if (!checker.ok()) {
+ this.lh.report(LogHandler.LEVEL_ERROR, null,
+ "Encountered errors during c generation.");
+ return;
+ }
+
+ // ok, we're ready to generate code. make sure the
+ // output directories exist.
+
+ Output dir = options.output;
+ Output templateDir = options.templateOutput;
+
+ // generate code for each service.
+
+ for (Service intf : module) {
+ this.generate(intf, what, dir, templateDir);
+ }
+ }
+
+ public boolean isGenerateImpl() {
+ return this.isGenerateImpl;
+ }
+
+ public boolean isGenerateMain() {
+ return this.isGenerateMain;
+ }
+
+ boolean isGenerateImpl;
+ boolean isGenerateMain;
+
+ private void generate(final Service intf, Set<String> what, Output dir,
+ Output templateDir) throws Exception {
+ what = this.populateWhat(what);
+
+ if (what.isEmpty()) {
+ // lh.logMessage( lh.LEVEL_ERROR, null, "User has selected NONE\n"
+ // );
+ return;
+ }
+
+ final MessageDirection msgDir = this.getMessageDirection(what);
+
+ if (what.contains(WHAT_INTF)) {
+ // Generate the value factory file.
+ this.generateVf(intf, dir, msgDir);
+ // Generate the interface, remote, and stub files.
+ this.generateIntfRemoteStub(intf, dir, msgDir, MessageDirection.BOTH,
+ false);
+ this.generateIntfRemoteStub(intf, dir, msgDir, MessageDirection.SERVER,
+ true);
+ this.generateIntfRemoteStub(intf, dir, msgDir, MessageDirection.CLIENT,
+ true);
+ // Generate helper file.
+ this.generateHelper(intf, dir, msgDir);
+ // Generate base file.
+ this.generateBase(intf, dir, msgDir);
+ // Generate readme file.
+ this.generateReadme(intf, dir, msgDir);
+ this.generateKeywordList(intf, dir, msgDir, MessageDirection.BOTH, true);
+ }
+
+ // Generate main template file.
+ if (what.contains(WHAT_MAIN))
+ this.generateMain(intf, templateDir, msgDir);
+
+ // Generate impl template file.
+ if (what.contains(WHAT_IMPL))
+ this.generateImpl(intf, templateDir, msgDir);
+ }
+
+ private void generateReadme(final Service intf, Output dir,
+ final MessageDirection msgDir) throws Exception {
+ this.doFile(dir, "readme-etch-cpp-files.txt", this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateReadme(pw, intf, msgDir);
+ }
+ });
+ }
+
+ private void generateKeywordList(final Service intf, Output dir,
+ final MessageDirection what, final MessageDirection mc,
+ final boolean hasBaseClass) throws Exception {
+ this.doFile(dir, this.getKeywordFilename(intf), this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateKeywords(pw, intf, mc, hasBaseClass);
+ }
+ });
+ }
+
+ void generateKeywords(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc).toLowerCase());
+ context.put("hasBaseClass", hasBaseClass);
+ this.etch_wireshark_vm.merge(context, pw);
+ }
+
+ public String getKeywordForWireshark(String fieldname) {
+ int hash = Hash.hash(fieldname);
+ return String.format("0x%08x", hash) + "," + fieldname;
+ }
+
+ private void generateVf(final Service intf, Output dir,
+ final MessageDirection mc) throws Exception {
+ this.doFile(dir, fnSource + this.getVfName(intf) + fnSuffixI, this.lh,
+ new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateVfI(pw, intf, mc);
+ }
+ });
+ this.doFile(dir, fnInclude + this.getVfName(intf) + fnSuffixH, this.lh,
+ new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateVfH(pw, intf, mc);
+ }
+ });
+ }
+
+ private void generateHelper(final Service intf, Output dir,
+ final MessageDirection msgDir) throws Exception {
+ this.doFile(dir, fnSource + this.getHelperName(intf) + fnSuffixI, this.lh,
+ new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateHelperI(pw, intf, msgDir);
+ }
+ });
+ this.doFile(dir, fnInclude + this.getHelperName(intf) + fnSuffixH, this.lh,
+ new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateHelperH(pw, intf, msgDir);
+ }
+ });
+ }
+
+ private void generateMain(final Service intf, Output dir,
+ MessageDirection msgDir) throws Exception {
+ if (msgDir == MessageDirection.BOTH || msgDir == MessageDirection.CLIENT) {
+ this.doFile(dir, this.getMainName(intf, MessageDirection.CLIENT)
+ + fnSuffixI, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateMainI(pw, intf, MessageDirection.CLIENT, false);
+ }
+ });
+ this.doFile(dir, this.getMainName(intf, MessageDirection.CLIENT)
+ + fnSuffixH, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateMainH(pw, intf, MessageDirection.CLIENT, false);
+ }
+ });
+ }
+
+ if (msgDir == MessageDirection.BOTH || msgDir == MessageDirection.SERVER) {
+ this.doFile(dir, this.getMainName(intf, MessageDirection.SERVER)
+ + fnSuffixI, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateMainI(pw, intf, MessageDirection.SERVER, false);
+ }
+ });
+ this.doFile(dir, this.getMainName(intf, MessageDirection.SERVER)
+ + fnSuffixH, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateMainH(pw, intf, MessageDirection.SERVER, false);
+ }
+ });
+ }
+ }
+
+ private void generateBase(final Service intf, Output dir,
+ MessageDirection msgDir) throws Exception {
+ if (msgDir == MessageDirection.BOTH || msgDir == MessageDirection.CLIENT) {
+ this.doFile(dir,
+ fnSource + this.getBaseName(intf, MessageDirection.CLIENT)
+ + fnSuffixI, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateBaseI(pw, intf, MessageDirection.CLIENT,
+ false);
+ }
+ });
+ this.doFile(dir,
+ fnInclude + this.getBaseName(intf, MessageDirection.CLIENT)
+ + fnSuffixH, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateBaseH(pw, intf, MessageDirection.CLIENT,
+ false);
+ }
+ });
+ }
+ if (msgDir == MessageDirection.BOTH || msgDir == MessageDirection.SERVER) {
+ this.doFile(dir,
+ fnSource + this.getBaseName(intf, MessageDirection.SERVER)
+ + fnSuffixI, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateBaseI(pw, intf, MessageDirection.SERVER,
+ false);
+ }
+ });
+ this.doFile(dir,
+ fnInclude + this.getBaseName(intf, MessageDirection.SERVER)
+ + fnSuffixH, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateBaseH(pw, intf, MessageDirection.SERVER,
+ false);
+ }
+ });
+ }
+ }
+
+ private void generateImpl(final Service intf, Output dir,
+ MessageDirection msgDir) throws Exception {
+ if (msgDir == MessageDirection.BOTH || msgDir == MessageDirection.CLIENT) {
+ this.doFile(dir, this.getImplName(intf, MessageDirection.CLIENT)
+ + fnSuffixI, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateImplI(pw, intf, MessageDirection.CLIENT, false);
+ }
+ });
+ this.doFile(dir, this.getImplName(intf, MessageDirection.CLIENT)
+ + fnSuffixH, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateImplH(pw, intf, MessageDirection.CLIENT, false);
+ }
+ });
+ }
+ if (msgDir == MessageDirection.BOTH || msgDir == MessageDirection.SERVER) {
+ this.doFile(dir, this.getImplName(intf, MessageDirection.SERVER)
+ + fnSuffixI, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateImplI(pw, intf, MessageDirection.SERVER, false);
+ }
+ });
+ this.doFile(dir, this.getImplName(intf, MessageDirection.SERVER)
+ + fnSuffixH, this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateImplH(pw, intf, MessageDirection.SERVER, false);
+ }
+ });
+ }
+ }
+
+ private void generateIntfRemoteStub(final Service intf, Output dir,
+ final MessageDirection what, final MessageDirection mc,
+ final boolean hasBaseClass) throws Exception {
+ // Generate interface file
+ this.doFile(dir, fnSource + this.getIntfName(intf, mc) + fnSuffixI,
+ this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateIntfI(pw, intf, mc, hasBaseClass);
+ }
+ });
+ this.doFile(dir, fnInclude + this.getIntfName(intf, mc) + fnSuffixH,
+ this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateIntfH(pw, intf, mc, hasBaseClass);
+ }
+ });
+
+ // Generate remote file
+
+ if (mc == MessageDirection.BOTH || what == MessageDirection.BOTH
+ || mc != what) {
+ this.doFile(dir, fnSource + this.getRemoteName(intf, mc) + fnSuffixI,
+ this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateRemoteI(pw, intf, mc, hasBaseClass);
+ }
+ });
+ this.doFile(dir, fnInclude + this.getRemoteName(intf, mc) + fnSuffixH,
+ this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateRemoteH(pw, intf, mc, hasBaseClass);
+ }
+ });
+ }
+ // Generate stub file
+
+ if (mc == MessageDirection.BOTH || what == MessageDirection.BOTH
+ || mc == what) {
+ this.doFile(dir, fnSource + this.getStubName(intf, mc) + fnSuffixI,
+ this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateStubI(pw, intf, mc, hasBaseClass);
+ }
+ });
+ this.doFile(dir, fnInclude + this.getStubName(intf, mc) + fnSuffixH,
+ this.lh, new Gen() {
+ @Override
+ public void run(PrintWriter pw) throws Exception {
+ Compiler.this.generateStubH(pw, intf, mc, hasBaseClass);
+ }
+ });
+ }
+ }
+
+ /**
+ * Generate the value factory Implementation for the service.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @throws Exception
+ */
+ void generateVfI(PrintWriter pw, Service intf, MessageDirection mc)
+ throws Exception {
+ // params keeps track of the total set of parameters
+ // named (for enums, structs, exceptions, and messages).
+ Set<String> params = new HashSet<String>();
+
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("params", params);
+ context.put("inc", this.getVfName(intf) + fnSuffixH);
+ context.put("mc", mc);
+ context.put("namespace", this.cppNamespace(intf));
+ this.vf_cpp_vm.merge(context, pw);
+ }
+
+ /**
+ * Generate the value factory Header for the service.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @throws Exception
+ */
+ void generateVfH(PrintWriter pw, Service intf, MessageDirection mc)
+ throws Exception {
+ // params keeps track of the total set of parameters
+ // named (for enums, structs, exceptions, and messages).
+ Set<String> params = new HashSet<String>();
+
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("params", params);
+ context.put("mc", mc);
+ context.put("namespace", this.cppNamespace(intf));
+ this.vf_h_vm.merge(context, pw);
+ }
+
+ /**
+ * Generate the interface Implementation for the service.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateIntfI(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("inc", this.getIntfName(intf, mc) + fnSuffixH);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("namespace", this.cppNamespace(intf));
+ this.intf_cpp_vm.merge(context, pw);
+ }
+
+ /**
+ * Generate the interface Header for the service.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateIntfH(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("inc", intf.name() + fnSuffixH);
+ context.put("namespace", this.cppNamespace(intf));
+ this.intf_h_vm.merge(context, pw);
+ }
+
+ /**
+ * Generate the call to message implementation of the interface. This class
+ * turns calls on its methods into messages which are sent to the remote stub.
+ * For two-way calls, it then waits for a response message, returning the
+ * result therein to the caller.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateRemoteI(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("inc", this.getRemoteName(intf, mc) + fnSuffixH);
+ context.put("methodList", new ArrayList<String>());
+ context.put("namespace", this.cppNamespace(intf));
+ this.remote_cpp_vm.merge(context, pw);
+
+ }
+
+ /**
+ * Generate the call to message implementation Header of the interface. This
+ * class turns calls on its methods into messages which are sent to the remote
+ * stub. For two-way calls, it then waits for a response message, returning
+ * the result therein to the caller.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateRemoteH(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("inc", this.getRemoteName(intf, mc) + fnSuffixH);
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("methodList", new ArrayList<String>());
+ context.put("namespace", this.cppNamespace(intf));
+ this.remote_h_vm.merge(context, pw);
+
+ }
+
+ /**
+ * Generate the message to call implementation. This class accepts a message
+ * and turns it back into a call on the user's implementation. For two-way
+ * messages, the return value from the user's implementation method is turned
+ * into the appropriate response message and sent.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateStubI(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("inc", this.getStubName(intf, mc) + fnSuffixH);
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("namespace", this.cppNamespace(intf));
+ this.stub_cpp_vm.merge(context, pw);
+ }
+
+ /**
+ * Generate the message to call implementation. This class accepts a message
+ * and turns it back into a call on the user's implementation. For two-way
+ * messages, the return value from the user's implementation method is turned
+ * into the appropriate response message and sent.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateStubH(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("inc", this.getIntfName(intf, mc) + fnSuffixH);
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("namespace", this.cppNamespace(intf));
+ this.stub_h_vm.merge(context, pw);
+ }
+
+ /**
+ * Generate the transport plumbing helper Implementation.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @throws Exception
+ */
+ void generateHelperI(PrintWriter pw, Service intf, MessageDirection mc)
+ throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("inc", this.getHelperName(intf) + fnSuffixH);
+ context.put("mc", mc);
+ context.put("namespace", this.cppNamespace(intf));
+ this.helper_cpp_vm.merge(context, pw);
+ }
+
+ /**
+ * Generate the transport plumbing helper Header.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @throws Exception
+ */
+ void generateHelperH(PrintWriter pw, Service intf, MessageDirection mc)
+ throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("inc", this.getHelperName(intf) + fnSuffixH);
+ context.put("mc", mc);
+ context.put("namespace", this.cppNamespace(intf));
+ this.helper_h_vm.merge(context, pw);
+ }
+
+ /**
+ * Generate the readme.txt.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @throws Exception
+ */
+ void generateReadme(PrintWriter pw, Service intf, MessageDirection mc)
+ throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("namespace", this.cppNamespace(intf));
+ this.readme_vm.merge(context, pw);
+ }
+
+ /**
+ * Generate the template main program.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateMainI(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("namespace", this.cppNamespace(intf));
+ this.main_cpp_vm.merge(context, pw);
+ }
+
+ void generateMainH(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("namespace", this.cppNamespace(intf));
+ this.main_h_vm.merge(context, pw);
+ }
+
+ /**
+ * Generates the base implementation of the interfaces, with each method
+ * throwing an exception to the tune that it isn't implemented. User's impl
+ * will extend this base implementation.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateBaseI(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("inc", this.getBaseName(intf, mc) + fnSuffixH);
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("methodList", new ArrayList<String>());
+ context.put("namespace", this.cppNamespace(intf));
+ this.base_cpp_vm.merge(context, pw);
+ }
+
+ /**
+ * Generates the base implementation of the interfaces, with each method
+ * throwing an exception to the tune that it isn't implemented. User's impl
+ * will extend this base implementation.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateBaseH(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("inc", this.getIntfName(intf, mc) + fnSuffixH);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("methodList", new ArrayList<String>());
+ context.put("namespace", this.cppNamespace(intf));
+ this.base_h_vm.merge(context, pw);
+ }
+
+ /**
+ * Generate the template user implemention class which extends the base
+ * implementation generated above. This class will only have the appropriate
+ * constructor and reference to the appropriate remote, and a comment inviting
+ * the user to override methods.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateImplI(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("namespace", this.cppNamespace(intf));
+ this.impl_cpp_vm.merge(context, pw);
+ }
+
+ /**
+ * Generate the template user implemention class which extends the base
+ * implementation generated above. This class will only have the appropriate
+ * constructor and reference to the appropriate remote, and a comment inviting
+ * the user to override methods.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateImplH(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc));
+ context.put("hasBaseClass", hasBaseClass);
+ context.put("namespace", this.cppNamespace(intf));
+ this.impl_h_vm.merge(context, pw);
+ }
+
+ public MessageDirection getRemoteDirection(MessageDirection mc) {
+ if (mc == MessageDirection.SERVER) {
+ return MessageDirection.CLIENT;
+ }
+ if (mc == MessageDirection.BOTH) {
+ return MessageDirection.BOTH;
+ }
+ return MessageDirection.SERVER;
+ }
+
+ public String getRemoteDirectionName(MessageDirection mc) {
+
+ return this.getDirectionName(this.getRemoteDirection(mc));
+ }
+
+ public boolean hasMessageDirectionBoth(Service intf) {
+ return intf.hasMessageDirection(MessageDirection.BOTH);
+ }
+
+ @Override
+ public boolean isClient(MessageDirection mc) {
+ return mc == MessageDirection.CLIENT || mc == MessageDirection.BOTH;
+ }
+
+ @Override
+ public boolean isServer(MessageDirection mc) {
+ return mc == MessageDirection.SERVER || mc == MessageDirection.BOTH;
+ }
+
+ public String getDirectionName(MessageDirection mc) {
+ return MsgDirHelper.getSuffix(mc).toLowerCase();
+ }
+
+ public MessageDirection getMsgDirServer() {
+ return MessageDirection.SERVER;
+ }
+
+ public MessageDirection getMsgDirClient() {
+ return MessageDirection.CLIENT;
+ }
+
+ public String getServiceName(Service intf) {
+ return intf.name().name().toLowerCase();
+ }
+
+ public String getIntfName(Service intf) {
+ return this.getServiceName(intf);
+ }
+
+ public String getVfName(Service intf) {
+ return "ValueFactory" + this.getIntfName(intf, MessageDirection.BOTH);
+ }
+
+ public String getIntfName(Service intf, MessageDirection mc) {
+ String suffix = MsgDirHelper.getSuffix(mc);
+ return intf.name() + suffix;
+ }
+
+ public String getMainName(Service intf, MessageDirection mc) {
+ if (mc == MessageDirection.SERVER)
+ return "Main" + intf.name() + "Listener";
+ return "Main" + this.getIntfName(intf, mc);
+ }
+
+ public String getImplName(Service intf, MessageDirection mc) {
+ return "Impl" + this.getIntfName(intf, mc);
+ }
+
+ public String getRemoteName(Service intf, MessageDirection mc) {
+ return "Remote" + this.getIntfName(intf, mc);
+ }
+
+ public String getStubName(Service intf, MessageDirection mc) {
+ return "Stub" + this.getIntfName(intf, mc);
+ }
+
+ public String getHelperName(Service intf) {
+ return intf.name() + "Helper";
+ }
+
+ public String getBaseName(Service intf, MessageDirection mc) {
+ return "Base" + this.getIntfName(intf, mc);
+ }
+
+ public String getKeywordFilename(Service intf) {
+ return intf.name().name().toLowerCase() + "_wireshark.ewh";
+ }
+
+ @Override
+ public String asyncReceiverPoolName(Message msg) {
+ return msg.getAsyncReceiver().toString().toLowerCase();
+ }
+
+ @Override
+ public String getTypeValue(TypeRef type, Token value) {
+ Token t = type.type();
+ switch (t.kind) {
+ case EtchGrammarConstants.LONG:
+ return value.image + "LL";
+ case EtchGrammarConstants.FLOAT:
+ case EtchGrammarConstants.DOUBLE:
+ return value.image + (value.image.indexOf('.') > -1 ? "f" : "");
+ case EtchGrammarConstants.STRING:
+ return "L" + this.protectString(value.image);
+ case EtchGrammarConstants.BOOLEAN:
+ return value.image.toUpperCase();
+ default:
+ return value.image;
+ }
+ }
+
+ private String protectString(String s) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("\"");
+ for (char c : s.toCharArray()) {
+ if (c == '\t') {
+ sb.append("\\t");
+ continue;
+ }
+ if (c == '\r') {
+ sb.append("\\r");
+ continue;
+ }
+ if (c == '\n') {
+ sb.append("\\n");
+ continue;
+ }
+ if (c == '\"') {
+ sb.append("\\\"");
+ continue;
+ }
+ if (c == '\\') {
+ sb.append("\\\\");
+ continue;
+ }
+ if (c >= 32 && c < 127) {
+ sb.append(c);
+ continue;
+ }
+ sb.append(String.format("\\u%04x", (int) c));
+ }
+ sb.append("\"");
+ return sb.toString();
+ }
+
+ private String getNativeArrayTypeName(TypeRef type) {
+ Token t = type.type();
+ switch (t.kind) {
+ case EtchGrammarConstants.BOOLEAN:
+ return "EtchBool";
+ case EtchGrammarConstants.BYTE:
+ return "Byte";
+ case EtchGrammarConstants.SHORT:
+ return "Short";
+ case EtchGrammarConstants.INT:
+ return "Int";
+ case EtchGrammarConstants.LONG:
+ return "Long";
+ case EtchGrammarConstants.FLOAT:
+ return "Float";
+ case EtchGrammarConstants.DOUBLE:
+ return "Double";
+ case EtchGrammarConstants.STRING:
+ return "String";
+ case EtchGrammarConstants.OBJECT:
+ return "";
+ default: {
+ // we have to use a fully qualified name here.
+ // find the actual type...
+ Named<?> n = type.intf().get(t.image);
+ // System.out.println("Token: " + t.image);
+ if (n == null)
+ throw new IllegalArgumentException(String.format(
+ "undefined or ambiguous name at line %d: %s", t.beginLine, t.image));
+ if (n.isBuiltin()) {
+ Builtin b = (Builtin) n;
+ return b.className().substring(4);
+ }
+ if (n.isEnumx()) {
+ return n.efqname(this);
+ } else {
+ return type.intf().name() + "::" + n.efqname(this);
+ }
+ }
+ }
+ }
+
+
+ @Override
+ public String getTypeName(TypeRef type) {
+ return " I A M NOT IMPLEMENTED";
+ //if (type.dim() > 0)
+ // return this.getPointerTypeName(type);
+ }
+
+ public String getNativeTypeNameForConstants(TypeRef type) {
+ if (type.type().kind == EtchGrammarConstants.STRING)
+ return "wchar_t*";
+ return this.getNativeTypeName(type, false);
+ }
+
+ /**
+ * @param type
+ * the etch type
+ * @return the fundamental native type for c so etch int -> c int, while etch
+ * string -> wchar* string.
+ */
+ @Override
+ public String getNativeTypeName(TypeRef type) {
+ return this.getNativeTypeName(type, false);
+ }
+
+ public String getEtchTypeName(TypeRef type, boolean Pointer) {
+ if (type.dim() > 0) return this.getArrayTypeName(type, Pointer);
+ return Pointer ? this.getPointerTypeName(type) : this.getNativeTypeName(type, true);
+ }
+
+ private String getArrayTypeName(TypeRef type, boolean pointer) {
+ // TODO Auto-generated method stub
+ if(pointer)
+ return "EtchNativeArray" + this.getNativeArrayTypeName( type ) + "Ptr";
+ return "EtchNativeArray" + this.getNativeArrayTypeName( type ) + "Obj";
+ }
+
+ public String getNativeTypeName(TypeRef type, boolean etch_type) {
+ Token t = type.type();
+ switch (t.kind) {
+ case EtchGrammarConstants.VOID:
+ return "void";
+ case EtchGrammarConstants.BOOLEAN:
+ return (etch_type ? "EtchBool" : "capu::bool_t");
+ case EtchGrammarConstants.BYTE:
+ return (etch_type ? "EtchByte" : "capu::int8_t");
+ case EtchGrammarConstants.SHORT:
+ return (etch_type ? "EtchShort" : "capu::int16_t");
+ case EtchGrammarConstants.INT:
+ return (etch_type ? "EtchInt32" : "capu::int32_t");
+ case EtchGrammarConstants.LONG:
+ return (etch_type ? "EtchLong" : "capu::int64_t");
+ case EtchGrammarConstants.FLOAT:
+ return (etch_type ? "EtchFloat" : "capu::float_t");
+ case EtchGrammarConstants.DOUBLE:
+ return (etch_type ? "EtchDouble" : "capu::double_t");
+ case EtchGrammarConstants.STRING:
+ return (etch_type ? "EtchString" : "EtchString");
+ case EtchGrammarConstants.OBJECT:
+ return (etch_type ? "EtchObject" : "EtchObject");
+ default: {
+ // we have to use a fully qualified name here.
+ // find the actual type...
+ Named<?> n = type.intf().get(t.image);
+ // System.out.println("Token: " + t.image);
+ if (n == null)
+ throw new IllegalArgumentException(String.format(
+ "undefined or ambiguous name at line %d: %s", t.beginLine, t.image));
+ if (n.isBuiltin()) {
+ Builtin b = (Builtin) n;
+ if (n.efqname(this).equals("EtchDate")) return b.className();
+ return b.className() + "Obj";
+ }
+ if (n.isEnumx()) {
+ return n.efqname(this);
+ } else {
+ return type.intf().name() + "::" + n.efqname(this);
+ }
+ }
+ }
+ }
+
+ /**
+ * @param type
+ * the etch type
+ * @return the fundamental native reference type for cpp.
+ */
+ public String getPointerTypeName(TypeRef type) {
+ Token t = type.type();
+ switch (t.kind) {
+ case EtchGrammarConstants.VOID:
+ return "void";
+ case EtchGrammarConstants.BOOLEAN:
+ return "EtchBoolPtr";
+ case EtchGrammarConstants.BYTE:
+ return "EtchBytePtr";
+ case EtchGrammarConstants.SHORT:
+ return "EtchShortPtr";
+ case EtchGrammarConstants.INT:
+ return "EtchInt32Ptr";
+ case EtchGrammarConstants.LONG:
+ return "EtchLongPtr";
+ case EtchGrammarConstants.FLOAT:
+ return "EtchFloatPtr";
+ case EtchGrammarConstants.DOUBLE:
+ return "EtchDoublePtr";
+ case EtchGrammarConstants.STRING:
+ return "EtchStringPtr";
+ case EtchGrammarConstants.OBJECT:
+ return "EtchObjectPtr";
+ default: {
+ // we have to use a fully qualified name here.
+ // find the actual type...
+ Named<?> n = type.intf().get(t.image);
+ if (n == null)
+ throw new IllegalArgumentException(String.format(
+ "undefined or ambiguous name at line %d: %s", t.beginLine, t.image));
+ if (n.efqname(this).equals("EtchDate"))
+ return "EtchDatePtr";
+ if (n.isBuiltin()) {
+ return n.efqname(this) + "Ptr";
+ }
+ return type.intf().name() + "::" + n.efqname(this) + "Ptr";
+ }
+ }
+ }
+
+ @Override
+ public String mfvname(String vname) {
+ return "_mf_" + vname;
+ }
+
+ @Override
+ public String mtvname(String vname) {
+ return "_mt_" + vname;
+ }
+
+ @Override
+ public String getLang() {
+ return "cpp";
+ }
+
+ @Override
+ public String enum_efqname(String fqname, String moduleName,
+ String serviceName, String enumName) {
+ return enumName;
+ }
+
+ @Override
+ public String except_efqname(String fqname, String moduleName,
+ String serviceName, String exceptName) {
+ return serviceName.toLowerCase() + "_" + exceptName;
+ }
+
+ @Override
+ public String struct_efqname(String fqname, String moduleName,
+ String serviceName, String structName) {
+ return serviceName.toLowerCase() + "_" + structName;
+ }
+
+ @Override
+ public String qualifyParameterName(Token name) {
+ return name.image;
+ }
+
+ @Override
+ public String qualifyConstantName(Service intf, Token name) {
+ return intf.fqname() + '.' + name.image;
+ }
+
+ @Override
+ public String qualifyEnumName(Service intf, Token name) {
+ return intf.fqname() + '.' + name.image;
+ }
+
+ Set<String> history = new HashSet<String>();
+
+ public boolean resetHistory() {
+ this.history = new HashSet<String>();
+ return true;
+ }
+
+ public boolean addStringToHistory(String s) {
+ this.history.add(s);
+ return true;
+ }
+
+ public boolean historyContains(String s) {
+ return this.history.contains(s);
+ }
+
+ public String cppNamespace(Service svc) {
+ return (svc.fqname()).replace('.', '_');
+ }
+
+ // ///////////////////////////////////////////////
+ // /////////////////// WORKSPACE /////////////////
+ // ///////////////////////////////////////////////
+
+ @Override
+ public String formatString(ParamList<Service> n, boolean isExcept)
+ throws ParseException, IOException {
+ ToString ts = (ToString) n.getOpt("ToString");
+ List<FmtItem> list;
+ if (ts != null) {
+ list = ts.getFormat();
+ n.checkFormatList(ts.lineno(), list);
+ } else if (isExcept)
+ list = n.mkFormatList(true, ((Except) n).hasExtends());
+ else
+ list = n.mkFormatList(false, ((Struct) n).hasExtends());
+
+ if (list.size() == 1) {
+ return list.get(0).value();
+ }
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("\"");
+ for (FmtItem i : list) {
+ if (i instanceof FieldItem) {
+ sb.append("%s");
+ } else {
+ this.escape(sb, ((StringItem) i).value());
+ }
+ }
+ sb.append("\"");
+ for (FmtItem i : list) {
+ if (i instanceof FieldItem) {
+ sb.append(", ");
+ sb.append(((FieldItem) i).value() + "->c_str()");
+ }
+ }
+ return sb.toString();
+ }
+
+ private void escape(StringBuffer sb, String s) throws IOException {
+ StringReader rdr = new StringReader(s);
+ int c;
+ while ((c = rdr.read()) >= 0) {
+ if (c == '"')
+ sb.append("\\\"");
+ else if (c == '\\')
+ sb.append("\\\\");
+ else if (c == '\t')
+ sb.append("\\t");
+ else if (c == '\r')
+ sb.append("\\r");
+ else if (c == '\n')
+ sb.append("\\n");
+ else
+ sb.append((char) c);
+ }
+ }
+
+ @Override
+ public String getValidator(Named<?> named) {
+ if (named instanceof Parameter) {
+ Parameter param = (Parameter) named;
+ TypeRef type = param.type();
+
+ if (type.isBuiltin())
+ return String.format("EtchValidator%s::Get(%d, tmpValue)",
+ this.getValidatorStringForParam(param), type.dim());
+
+ Named<?> n = type.getNamed(type.intf());
+
+ if (n.isBuiltin()) {
+ Builtin b = (Builtin) n;
+
+ String cn = b.className();
+ if (!n.efqname(this).equals("EtchDate"))
+ cn += "Obj";
+
+ /*
+ * int i = cn.indexOf( '<' ); if (i >= 0) cn = cn.substring( 0, i );
+ */
+ return String.format(
+ "EtchValidatorCustom::Get(%d, %s::TYPE(), %s, tmpValue);",
+ type.dim(), cn, b.allowSubclass());
+ }
+
+ // Allow subclassing for etch defined structs and externs.
+
+ if (n.isStruct() || n.isExcept()) {
+ if (n.isStruct()) {
+ Struct s = (Struct) n;
+ return String.format(
+ "EtchValidatorCustom::Get( %d, %s::TYPE(), true, tmpValue);",
+ type.dim(), s
+ .service().name() + "::" + n.efqname(this));
+ }
+ Except e = (Except) n;
+ return String.format(
+ "EtchValidatorCustom::Get( %d, %s::TYPE(), true, tmpValue);", type.dim(), e
+ .service().name() + "::" + n.efqname(this));
+ }
+ // Don't allow subclassing for externs or etch defined enums.
+ if (!(n.isExtern() || n.isEnumx()))
+ Assertion.check(n.isExtern() || n.isEnumx(),
+ "n.isExtern() || n.isEnumx(): " + n);
+ Enumx e = (Enumx) n;
+ return String.format(
+ "EtchValidatorCustom::Get( %d, %s::TYPE(), false, tmpValue);",
+ type.dim(), n.efqname(this));
+ }
+
+ if (named instanceof Thrown) {
+ Thrown thrown = (Thrown) named;
+ Except e = (Except) thrown.getNamed();
+ String efgName = this.getExcept(thrown).service().name() + "::"
+ + e.efqname(this);
+ return String.format(
+ "EtchValidatorCustom::Get(0, %s::TYPE(), true, tmpValue);"
+ , efgName);
+ }
+ if (named instanceof Item)
+ return "EtchValidatorBoolean::Get(0, tmpValue)";
+ return "NULL";
+ }
+
+ /**
+ * @param name
+ * @return the appropriate name for a getter method.
+ */
+ public String getGetterName(Name name) {
+ String s = name.name;
+ return "get" + s.substring(0, 1).toUpperCase() + s.substring(1);
+ }
+
+ /**
+ * @param name
+ * @return the appropriate name for a setter method.
+ */
+ public String getSetterName(Name name) {
+ String s = name.name;
+ return "set" + s.substring(0, 1).toUpperCase() + s.substring(1);
+ }
+
+ @Override
+ public void addDefaults(Service service) throws ParseException {
+ this.addBuiltin(service, this.newName("List"), "EtchList", true);
+ this.addBuiltin(service, this.newName("Map"), "EtchHashTable", true);
+ this.addBuiltin(service, this.newName("Set"), "EtchHashSet", true);
+ this.addBuiltin(service, this.newName("Datetime"), "EtchDate", false);
+ }
+
+ public String getValidatorStringForParam(Parameter param) {
+ TypeRef type = param.type();
+ return this.getValidatorStringForParam(type);
+ }
+
+ public String getValidatorStringForParam(TypeRef type) {
+ switch (type.type().kind) {
+ case EtchGrammarConstants.BOOLEAN:
+ return "Boolean";
+ case EtchGrammarConstants.BYTE:
+ return "Byte";
+ case EtchGrammarConstants.INT:
+ return "Int";
+ case EtchGrammarConstants.SHORT:
+ return "Short";
+ case EtchGrammarConstants.DOUBLE:
+ return "Double";
+ case EtchGrammarConstants.FLOAT:
+ return "Float";
+ case EtchGrammarConstants.LONG:
+ return "Long";
+ case EtchGrammarConstants.STRING:
+ return "String";
+ }
+ // what should be the default here?
+ return "Object";
+ }
+
+ public String getValidatorStringForParam(Message param) {
+ return this.getValidatorStringForParam(param.type());
+ }
+
+ public boolean isEnumParam(Parameter p) {
+ if (p.type() == null)
+ return false;
+ if (p.type().intf() == null)
+ return false;
+ if (p.type().getNamed(p.type().intf()) == null)
+ return false;
+ return p.type().getNamed(p.type().intf()).isEnumx();
+ }
+
+ public boolean isCustomType(Parameter param) {
+ return this.isCustomType(param.type());
+ }
+
+ public boolean isRefType(TypeRef param) {
+ if (param == null)
+ return true;
+ switch (param.type().kind) {
+ case EtchGrammarConstants.BOOLEAN:
+ case EtchGrammarConstants.DOUBLE:
+ case EtchGrammarConstants.FLOAT:
+ case EtchGrammarConstants.INT:
+ case EtchGrammarConstants.LONG:
+ case EtchGrammarConstants.ENUM:
+ case EtchGrammarConstants.DECIMAL:
+ case EtchGrammarConstants.SHORT:
+ return false;
+ default:
+ return true;
+ }
+ }
+
+ public boolean isCustomType(TypeRef param) {
+ switch (param.type().kind) {
+ case EtchGrammarConstants.BOOLEAN:
+ case EtchGrammarConstants.DOUBLE:
+ case EtchGrammarConstants.FLOAT:
+ case EtchGrammarConstants.INTEGER:
+ case EtchGrammarConstants.STRING:
+ case EtchGrammarConstants.LONG:
+ return false;
+ default:
+ return true;
+ }
+ }
+
+ public String getTypeName(Parameter pa) {
+ return pa.type().type().image;
+ }
+
+ public String getTypeName(Message pa) {
+ return pa.type().type().image;
+ }
+
+ public List<String> getUsedServiceNames(Service s) {
+ final List<String> ret = new LinkedList<String>();
+ IncludeTreeWalker walker = new IncludeTreeWalker(ret, s);
+ try {
+ s.treewalk(walker);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return walker.getList();
+ }
+
+ public boolean containsStructsOrMessages(Service s) {
+ return s.messages(false).hasNext() || s.structs(false).hasNext();
+ }
+
+ public String getClassIdVarName(Parameter p) {
+ Named<?> n = p.type().getNamed(p.type().intf());
+ return n.efqname(this);
+ }
+
+ public String getClassIdVarName(Thrown t) {
+ Except p = (Except) t.getNamed();
+ return p.service().name() + "::" + p.name().toString();
+ }
+
+ public Except getExcept(Thrown t) {
+ Except e = (Except) t.getNamed();
+ return e;
+ }
+
+ public String getClassIdVarName(Message n) {
+ Named<?> na = n.type().getNamed(n.type().intf());
+ return na.efqname(this);
+ }
+
+ public String getDefiningServiceNameOf(TypeRef type) {
+ Named<?> na = type.getNamed(type.intf());
+ return na.parent().name().name.toLowerCase();
+ }
+
+}
Added: incubator/etch/trunk/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/IncludeTreeWalker.java
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/IncludeTreeWalker.java?rev=1368572&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/IncludeTreeWalker.java (added)
+++ incubator/etch/trunk/binding-cpp/compiler/src/main/java/org/apache/etch/bindings/cpp/compiler/IncludeTreeWalker.java Thu Aug 2 16:17:03 2012
@@ -0,0 +1,184 @@
+package org.apache.etch.bindings.cpp.compiler;
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+
+import java.util.List;
+
+import org.apache.etch.compiler.ast.Constant;
+import org.apache.etch.compiler.ast.Enumx;
+import org.apache.etch.compiler.ast.Except;
+import org.apache.etch.compiler.ast.Extern;
+import org.apache.etch.compiler.ast.Item;
+import org.apache.etch.compiler.ast.Message;
+import org.apache.etch.compiler.ast.Mixin;
+import org.apache.etch.compiler.ast.Module;
+import org.apache.etch.compiler.ast.Parameter;
+import org.apache.etch.compiler.ast.Service;
+import org.apache.etch.compiler.ast.Struct;
+import org.apache.etch.compiler.ast.Thrown;
+import org.apache.etch.compiler.ast.TreeWalker;
+import org.apache.etch.compiler.ast.TypeRef;
+
+public class IncludeTreeWalker implements TreeWalker {
+
+ private List<String> list;
+ private Service service;
+
+ public IncludeTreeWalker(List<String> list, Service s) {
+ this.list = list;
+ this.service = s;
+ }
+
+ @Override
+ public void doExtern(Extern extern) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void doItem(Item item) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void doMixin(Mixin mixin) {
+ String s = mixin.name().name(); //.intf().name().name();
+ if (!getList().contains(s) &&
+ !s.equals(service.name().name())) {
+ getList().add(s);
+ }
+
+ }
+
+ @Override
+ public void doThrown(Thrown thrown) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void doTypeRef(TypeRef ref) {
+
+ }
+
+ @Override
+ public void postConstant(Constant constant) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void postEnum(Enumx enumx) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void postExcept(Except except) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void postMessage(Message message) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void postModule(Module module) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void postParameter(Parameter parameter) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void postService(Service service) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void postStruct(Struct struct) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void preConstant(Constant constant) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void preEnum(Enumx enumx) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void preExcept(Except except) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void preMessage(Message message) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void preModule(Module module) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void preParameter(Parameter parameter) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void preService(Service service) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void preStruct(Struct struct) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public List<String> getList() {
+ return list;
+ }
+
+}
Added: incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/base_cpp.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/base_cpp.vm?rev=1368572&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/base_cpp.vm (added)
+++ incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/base_cpp.vm Thu Aug 2 16:17:03 2012
@@ -0,0 +1,129 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you 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.
+// This file automatically generated by:
+// $now
+// This file is automatically created and should not be edited!
+// Re-implement these methods by overriding them in Impl$intf.name()$suffix.
+
+#set($i = $intf.name())
+#set($intfname = "$i$suffix")
+#set($clname = "Base$intfname")
+#if ($helper.isServer($mc))
+#set($peer = "client")
+#else
+#set($peer = "server")
+#end
+
+\#include "common/EtchRuntimeException.h"
+\#include "$inc"
+
+using namespace $namespace;
+
+ /**
+ * Base implementation of $intfname, with default method implementations
+ * which throw runtime_error. Extend this class to provide
+ * implementations of messages from the $peer.
+ *
+ * @see Impl$intfname
+ */
+
+#foreach ($mthd in $intf.iterator())
+#if ($mthd.isMsgDir($mc) || $mthd.isMsgDirBoth())
+#if (!$mthd.isHidden())
+#if(!$methodList.contains($mthd.name().name()))
+#set ( $addMethodListStatus = $methodList.add($mthd.name().name()) )
+ $intfname::$mthd.name()AsyncResultPtr $clname::$mthd.name()(#set( $sep = "" )#foreach($param in $mthd.iterator())$sep$helper.getEtchTypeName($param.type(), true) $param.name() #set( $sep = ", " )#end)
+ {
+#if(!($helper.getEtchTypeName($mthd.type(), true) == "void"))
+ $mthd.name()AsyncResultPtr res = new EtchAsyncResult<$helper.getEtchTypeName($mthd.type(), false)>();
+#else
+ $mthd.name()AsyncResultPtr res = new EtchAsyncResultNone();
+#end
+ res->setException(new EtchRuntimeException("${mthd.name()} not implemented!", ETCH_EUNIMPL));
+ return res;
+ }
+
+#end
+#end
+#end
+#end
+
+#foreach($x in $intf.iterator())
+#if( $x.isMixin() )
+#set( $m = $x.getModule() )
+#set( $z = $m.iterator().next() )
+#foreach( $n in $z.messages( true ) )
+#if($n.isMsgDir($mc) || $n.isMsgDirBoth() )
+#if(!$n.isHidden())
+#if(!$methodList.contains($n.name().name()))
+#set ( $addMethodListStatus = $methodList.add($n.name().name()) )
+#if($n.isOneway())
+
+ $intfname::$n.name()AsyncResultPtr $clname::$n.name()(#set($sep = "")#foreach($p in $n.iterator())$sep$helper.getEtchTypeName($p.type(), true) $p.name() #set($sep = ", ")
+ #if(!($helper.getEtchTypeName($p.type(), true) == "void")), $helper.getEtchTypeName($p.type(), true) returnValue#end )
+ {
+#if(!($helper.getEtchTypeName($n.type(), true) == "void"))
+ $p.name()AsyncResultPtr res = new EtchAsyncResult<$helper.getEtchTypeName($p.type(), false)>();
+#else
+ $p.name()AsyncResultPtr res = new EtchAsyncResultNone();
+#end
+ res->setException(new EtchRuntimeException("${p.name()} not implemented!", ETCH_EUNIMPL));
+ return res;
+ }
+#end
+#else
+
+$intfname::$n.name()AsyncResultPtr $clname::$n.name()(#set($sep = "")#foreach($p in $n.iterator())$sep$helper.getEtchTypeName($p.type(), true) $p.name() #set($sep = ", ")#end #if(!($helper.getEtchTypeName($n.type(), true) == "void")), $helper.getEtchTypeName($n.type(), true) returnValue #end);#if(!$n.hasThrown())
+ {
+ return EtchRuntimeException("${p.name()} not implemented!", ETCH_EUNIMPL));
+ }#end
+#if($n.hasThrown())
+ {
+#if(!($helper.getEtchTypeName($n.type(), true) == "void"))
+ $p.name()AsyncResultPtr res = new EtchAsyncResult<$helper.getEtchTypeName($p.type(), false)>();
+#else
+ $p.name()AsyncResultPtr res = new EtchAsyncResultNone();
+#end
+ res->setException(new EtchRuntimeException("${p.name()} not implemented!", ETCH_EUNIMPL));
+ return res;
+#foreach($t in $n.thrown().iterator())
+ //TODO:
+ return ($sep$intf.name()::$t.getNamed().name()()
+#end
+ }
+#end
+#end
+#end
+#end
+#end
+#end
+#end
+#end
+
+ status_t $clname::_sessionQuery(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result)
+ {
+ return ETCH_EUNIMPL;
+ }
+ status_t $clname::_sessionControl(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value)
+ {
+ return ETCH_EUNIMPL;
+ }
+
+ status_t $clname::_sessionNotify(capu::SmartPointer<EtchObject> event )
+ {
+ return ETCH_EUNIMPL;
+ }
\ No newline at end of file
Added: incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/base_h.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/base_h.vm?rev=1368572&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/base_h.vm (added)
+++ incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/base_h.vm Thu Aug 2 16:17:03 2012
@@ -0,0 +1,94 @@
+##
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you 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.
+##
+
+// This file automatically generated by:
+// $version
+// $now
+// Re-implement these methods by overriding them in Impl$intf.name()$suffix.
+
+#set($i = $intf.name())
+#set($intfname = "$i$suffix")
+#set($clname = "Base$intfname")
+#if ($helper.isServer($mc))
+#set($peer = "client")
+#else
+#set($peer = "server")
+#end
+
+#ifndef __$helper.getBaseName($intf, $mc).toUpperCase()_H__
+\#define __$helper.getBaseName($intf, $mc).toUpperCase()_H__
+
+\#include "$inc"
+\#include "support/EtchObjectSession.h"
+
+namespace $namespace {
+ /**
+ * Base implementation of $intfname, with default method implementations
+ * which throw runtime_error. Extend this class to provide
+ * implementations of messages from the $peer.
+ *
+ * @see Impl$intfname
+ */
+
+ class $clname
+ : public $intfname, public EtchObjectSession
+ {
+#foreach ($mthd in $intf.iterator())
+#if ($mthd.isMsgDir($mc) || $mthd.isMsgDirBoth())
+#if (!$mthd.isHidden())
+#if(!$methodList.contains($mthd.name().name()))
+#set ( $addMethodListStatus = $methodList.add($mthd.name().name()) )
+ public:
+ $mthd.name()AsyncResultPtr $mthd.name()(#set( $sep = "" )#foreach($param in $mthd.iterator())$sep$helper.getEtchTypeName($param.type(), true) $param.name() #set( $sep = ", " )#end);
+#end
+#end
+#end
+#end
+
+#foreach( $x in $intf.iterator() )
+#if( $x.isMixin() )
+#set( $m = $x.getModule() )
+#set( $z = $m.iterator().next() )
+#foreach( $n in $z.messages( true ) )
+#if($n.isMsgDir($mc) || $n.isMsgDirBoth() )
+#if(!$n.isHidden())
+#if(!$methodList.contains($n.name().name()))
+#set ( $addMethodListStatus = $methodList.add($n.name().name()) )
+#if($n.isOneway())
+
+ public:
+ $n.name()AsyncResultPtr $n.name()(#set($sep = "")#foreach($p in $n.iterator())$sep$helper.getEtchTypeName($p.type(), true) $p.name() #set($sep = ", ")#end);
+#else
+
+ public:
+ $n.name()AsyncResultPtr $n.name()(#set($sep = "")#foreach($p in $n.iterator())$sep$helper.getEtchTypeName($p.type(), true) $p.name() #set($sep = ", ")#end);
+#end
+#end
+#end
+#end
+#end
+#end
+#end
+ public:
+ status_t _sessionQuery( capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result );
+ status_t _sessionControl( capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value );
+ status_t _sessionNotify( capu::SmartPointer<EtchObject> event );
+ };
+}
+#endif /* $helper.getBaseName($intf, $mc).toUpperCase() */
\ No newline at end of file
Modified: incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/cppKeywords.kwd
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/cppKeywords.kwd?rev=1368572&r1=1368571&r2=1368572&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/cppKeywords.kwd (original)
+++ incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/cppKeywords.kwd Thu Aug 2 16:17:03 2012
@@ -16,3 +16,45 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+
+true
+false
+NULL
+abstract
+continue
+for
+new
+switch
+default
+goto
+bool
+do
+if
+private
+this
+break
+double
+protected
+throw
+byte
+else
+include
+public
+throws
+case
+enum
+return
+catch
+int
+short
+try
+char
+static
+void
+class
+finally
+long
+volatile
+const
+float
+while
Added: incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/etch_wireshark.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/etch_wireshark.vm?rev=1368572&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/etch_wireshark.vm (added)
+++ incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/etch_wireshark.vm Thu Aug 2 16:17:03 2012
@@ -0,0 +1,64 @@
+##
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you 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.
+##
+
+#foreach($n in $intf.iterator())
+#if($n.isMessage())
+#if(!$n.isHidden())
+#set ( $str="$intf.fqname().$n.name()" )
+$helper.getKeywordForWireshark($str)
+#if(! $n.isOneway())
+#set ( $str="$intf.fqname()._result_$n.name()" )
+$helper.getKeywordForWireshark($str)
+#end
+#end
+#end
+#end
+#foreach($n in $intf.iterator() )
+#if ($n.isStruct() || $n.isEnumx() || $n.isExcept())
+$helper.getKeywordForWireshark($n.fqname().toString())
+#end
+#end
+#set ($tmp = $helper.resetHistory())
+#foreach($n in $intf.iterator())
+#if(!$n.isHidden())
+#if(!$n.isBuiltin())
+#foreach($p in $n.iterator())
+#if(!$helper.historyContains($p.name().toString()))
+$helper.getKeywordForWireshark($p.name().toString())
+#set ($tmp = $helper.addStringToHistory($p.name().toString()))
+#end
+#end
+#end
+#end
+#end
+$helper.getKeywordForWireshark("_Etch_RuntimeException")
+$helper.getKeywordForWireshark("_Etch_AuthException")
+$helper.getKeywordForWireshark("_exception")
+$helper.getKeywordForWireshark("_Etch_List")
+$helper.getKeywordForWireshark("_Etch_Map")
+$helper.getKeywordForWireshark("_Etch_Set")
+$helper.getKeywordForWireshark("_Etch_Datetime")
+$helper.getKeywordForWireshark("msg")
+$helper.getKeywordForWireshark("_messageId")
+$helper.getKeywordForWireshark("_inReplyTo")
+$helper.getKeywordForWireshark("result")
+$helper.getKeywordForWireshark("keys")
+$helper.getKeywordForWireshark("values")
+$helper.getKeywordForWireshark("dateTime")
+$helper.getKeywordForWireshark("keysAndValues")
\ No newline at end of file
Added: incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm?rev=1368572&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm (added)
+++ incubator/etch/trunk/binding-cpp/compiler/src/main/resources/org/apache/etch/bindings/cpp/compiler/helper_cpp.vm Thu Aug 2 16:17:03 2012
@@ -0,0 +1,202 @@
+##
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you 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.
+##
+
+// This file automatically generated by:
+// $version
+// $now
+// This file is automatically created and should not be edited!
+#set($i = $intf.name())
+#set($intfname = "$i$suffix")
+#set($clname = "${i}Helper")
+
+\#include "$inc"
+\#include "ValueFactory${i}.h"
+#if($helper.isServer($mc) || $helper.isBoth($mc))
+\#include "Stub${i}Server.h"
+#end
+#if($helper.isClient($mc) || $helper.isBoth($mc))
+\#include "Stub${i}Client.h"
+#end
+
+\#include "support/EtchRuntime.h"
+#if($helper.isServer($mc) || $helper.isBoth($mc))
+\#include "support/EtchServerStack.h"
+#end
+#if($helper.isClient($mc) || $helper.isBoth($mc))
+\#include "support/EtchClientStack.h"
+#end
+\#include "support/EtchPool.h"
+\#include "transport/EtchPlainMailboxManager.h"
+\#include "transport/EtchDefaultDeliveryService.h"
+
+using namespace $namespace;
+
+#if($helper.isServer($mc) || $helper.isBoth($mc))
+$clname::Listener${i}Server::Listener${i}Server(EtchTransport<EtchServerFactory>* listener, ${i}ServerFactory* implFactory)
+ : EtchDefaultServerFactory(listener, NULL), mFactory(implFactory)
+{
+
+}
+
+$clname::Listener${i}Server::~Listener${i}Server()
+{
+
+}
+
+status_t $clname::Listener${i}Server::newServer(EtchRuntime* runtime, EtchTransportMessage* transport, const EtchString& uri, EtchResources* resources)
+{
+ //get value factory
+ EtchObject* obj;
+ resources->get( EtchTransport<EtchValueFactory*>::VALUE_FACTORY(), obj );
+ EtchValueFactory* vf = (EtchValueFactory*) obj;
+
+ //create stack layers
+ EtchMailboxManager* mbm = new EtchPlainMailboxManager(transport, uri, resources);
+ EtchDeliveryService* dvs = new EtchDefaultDeliveryService(mbm, uri);
+ Remote${i}Client* client = new Remote${i}Client(runtime, dvs, vf);
+ ${i}Server* server = mFactory->new${i}Server(client);
+
+ //get thread pools
+ EtchObject* tmpObject;
+ resources->get( QUEUED_POOL(), tmpObject );
+ EtchQueuedPool* qp = (EtchQueuedPool*) tmpObject;
+ resources->get( FREE_POOL(), tmpObject );
+ EtchFreePool* fp = (EtchFreePool*) tmpObject;
+
+ //create stub
+ Stub${i}Server* tmp${i}Server = new Stub${i}Server(dvs, server, qp, fp);
+ EtchStack* stack = new EtchServerStack(client, tmp${i}Server, resources, vf);
+ client->start();
+ return ETCH_OK;
+}
+
+status_t $clname::Listener${i}Server::newValueFactory(const EtchString& uri, EtchValueFactory *&vf)
+{
+ vf = new ValueFactory${i}(uri);
+ return ETCH_OK;
+}
+
+
+/**
+ * Constructs a new server session listener per specifications in uri and
+ * resources. This listener will accept requests from clients for new server
+ * sessions.
+ *
+ * @param uri contains specifications for the server session listener and
+ * for the server session transport stack.
+ *
+ * @param resources additional resources to aid in constructing new server
+ * sessions.
+ *
+ * @param implFactory factory used to construct a new instance implementing
+ * ${i}Server. The new instance will receive and process messages from
+ * the client session.
+ *
+ * @return a server session listener.
+ *
+ * @throws Exception
+ */
+status_t $clname::newListener(EtchRuntime* runtime, EtchString uri, EtchResources* resources, ${i}ServerFactory* implFactory, EtchServerFactory*& serverFactory)
+{
+ status_t status = ETCH_OK;
+
+ //static initialization of value factory
+ ValueFactory${i}::__INIT(runtime);
+
+ //init resources
+ EtchResources *res;
+ status = EtchTransportHelper::InitResources(resources, res);
+ if (status != ETCH_OK) {
+ return status;
+ }
+
+ //get listener
+ EtchTransport<EtchServerFactory>* listener;
+ EtchTransportFactory::getListener(runtime, uri, res, listener);
+
+ //create server
+ serverFactory = new $clname::Listener${i}Server(listener, implFactory);
+ return status;
+}
+#end
+
+#if($helper.isClient($mc) || $helper.isBoth($mc))
+ /**
+ * Constructs a new client session per specifications in uri and resources.
+ *
+ * @param uri contains specifications for the client session transport
+ * stack.
+ *
+ * @param resources additional resources to aid in constructing new client
+ * sessions.
+ *
+ * @param implFactory factory used to construct a new instance implementing
+ * ${i}Client. The new instance will receive and process messages from
+ * the server session.
+ *
+ * @return an instance of Remote${i}Server initialized by uri and
+ * resources which may be used to send messages to the server session.
+ *
+ * @throws Exception
+ */
+ status_t $clname::newServer(EtchRuntime* runtime, EtchString uri, EtchResources* resources, ${i}ClientFactory& implFactory, Remote${i}Server*& server)
+ {
+ status_t status = ETCH_OK;
+
+ //static initialization of value factory
+ ValueFactory${i}::__INIT(runtime);
+
+ //init resources
+ EtchResources* res;
+ status = InitResources(resources, res);
+ if (status != ETCH_OK) {
+ return status;
+ }
+
+ //create valuefactory instance
+ ValueFactory${i}* vf = new ValueFactory${i}(uri);
+ EtchObject* vfobj = (EtchObject*) vf;
+ EtchObject* resobj = NULL;
+ res->put(EtchTransport<ValueFactory${i}>::VALUE_FACTORY(), vfobj, resobj);
+ if(resobj != NULL) delete resobj;
+
+ //init stack layers
+ EtchTransportMessage* m;
+ EtchTransportFactory::getTransport(runtime, uri, res, m);
+ EtchMailboxManager* mbm = new EtchPlainMailboxManager(m, uri, res);
+ EtchDeliveryService* dvs = new EtchDefaultDeliveryService(mbm, uri);
+ Remote${i}Server* _server = new Remote${i}Server(runtime, dvs, vf);
+ ${i}Client* client = implFactory.new${i}Client( server );
+
+ //get pools
+ EtchObject* tmpObject;
+ res->get(QUEUED_POOL(), tmpObject);
+ EtchQueuedPool* qp = (EtchQueuedPool*) tmpObject;
+ res->get(FREE_POOL(), tmpObject);
+ EtchFreePool* fp = (EtchFreePool*) tmpObject;
+
+ //init stub
+ Stub${i}Client* tmpStub${i}Client = new Stub${i}Client(dvs, client, qp, fp);
+ EtchStack* stack = new EtchClientStack(server, tmpStub${i}Client, res, vf);
+
+ //return server
+ server = _server;
+ return status;
+ }
+#end