2007-02-02 17:25:09 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*****************************************************************************/
|
|
|
|
package com.ibm.wala.cast.js.translator;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2012-01-06 21:49:48 +00:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2007-02-02 17:25:09 +00:00
|
|
|
|
2009-04-15 12:52:40 +00:00
|
|
|
import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
|
|
|
|
import com.ibm.wala.cast.tree.CAstEntity;
|
2007-02-02 17:25:09 +00:00
|
|
|
import com.ibm.wala.cast.tree.impl.CAstImpl;
|
2012-10-03 14:53:04 +00:00
|
|
|
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
|
|
|
|
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.CopyKey;
|
|
|
|
import com.ibm.wala.cast.tree.rewrite.CAstRewriter.RewriteContext;
|
2009-04-15 12:52:40 +00:00
|
|
|
import com.ibm.wala.classLoader.SourceFileModule;
|
2011-04-04 15:27:11 +00:00
|
|
|
import com.ibm.wala.classLoader.SourceModule;
|
2007-02-02 17:25:09 +00:00
|
|
|
|
2009-04-15 12:52:40 +00:00
|
|
|
public class CAstRhinoTranslator implements TranslatorToCAst {
|
2012-01-06 21:49:48 +00:00
|
|
|
private final List<CAstRewriterFactory> rewriters = new LinkedList<CAstRewriterFactory>();
|
2011-04-04 15:27:11 +00:00
|
|
|
private final SourceModule M;
|
2012-01-27 20:15:33 +00:00
|
|
|
private final boolean replicateForDoLoops;
|
|
|
|
|
|
|
|
public CAstRhinoTranslator(SourceModule M, boolean replicateForDoLoops) {
|
2009-04-15 12:52:40 +00:00
|
|
|
this.M = M;
|
2012-01-27 20:15:33 +00:00
|
|
|
this.replicateForDoLoops = replicateForDoLoops;
|
2012-03-01 02:45:51 +00:00
|
|
|
}
|
2012-01-06 21:49:48 +00:00
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2012-01-06 21:49:48 +00:00
|
|
|
public <C extends RewriteContext<K>, K extends CopyKey<K>> void addRewriter(CAstRewriterFactory<C, K> factory, boolean prepend) {
|
|
|
|
if(prepend)
|
|
|
|
rewriters.add(0, factory);
|
|
|
|
else
|
|
|
|
rewriters.add(factory);
|
|
|
|
}
|
2007-02-02 17:25:09 +00:00
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2013-03-01 15:07:20 +00:00
|
|
|
public CAstEntity translateToCAst() throws IOException, Error {
|
2009-04-15 12:52:40 +00:00
|
|
|
String N;
|
|
|
|
if (M instanceof SourceFileModule) {
|
|
|
|
N = ((SourceFileModule) M).getClassName();
|
|
|
|
} else {
|
|
|
|
N = M.getName();
|
2007-02-02 17:25:09 +00:00
|
|
|
}
|
|
|
|
|
2011-04-07 16:57:03 +00:00
|
|
|
CAstImpl Ast = new CAstImpl();
|
2012-01-27 20:15:33 +00:00
|
|
|
CAstEntity entity = new RhinoToAstTranslator(Ast, M, N, replicateForDoLoops).translateToCAst();
|
2012-01-06 21:49:48 +00:00
|
|
|
for(CAstRewriterFactory rwf : rewriters)
|
|
|
|
entity = rwf.createCAstRewriter(Ast).rewrite(entity);
|
|
|
|
return entity;
|
|
|
|
}
|
2012-01-27 20:15:33 +00:00
|
|
|
|
2007-02-02 17:25:09 +00:00
|
|
|
}
|