boolean isClassLibrary=false;
+ String sourceFileName;
+
public ClassDescriptor(String classname, boolean isInterface) {
this("", classname, isInterface);
}
return isClassLibrary;
}
+ public void setSourceFileName(String sourceFileName){
+ this.sourceFileName=sourceFileName;
+ }
+
+ public String getSourceFileName(){
+ return this.sourceFileName;
+ }
+
}
protected void generateFlatNode(FlatMethod fm, FlatNode fn, PrintWriter output) {
+ if(state.LINENUM) printSourceLineNumber(fm,fn,output);
additionalCodePreNode(fm, fn, output);
-
switch(fn.kind()) {
case FKind.FlatAtomicEnterNode:
generateFlatAtomicEnterNode(fm, (FlatAtomicEnterNode) fn, output);
}
protected void generateFlatFieldNode(FlatMethod fm, FlatFieldNode ffn, PrintWriter output) {
+
if(ffn.getField().isStatic()) {
// static field
if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) {
}
protected void additionalCodePostNode(FlatMethod fm, FlatNode fn, PrintWriter output) {
}
+
+ private void printSourceLineNumber(FlatMethod fm, FlatNode fn, PrintWriter output) {
+ // we do not print out line number if no one explicitly set the number
+ if(fn.getNumLine()!=-1){
+
+ int lineNum=fn.getNumLine();
+
+ // do not generate the line number if it is same as the previous one
+ boolean needtoprint;
+ if(fn.prev.size()==0){
+ needtoprint=true;
+ }else{
+ needtoprint=false;
+ }
+
+ for(int i=0;i<fn.prev.size();i++){
+ int prevLineNum=((FlatNode)fn.prev.get(i)).getNumLine();
+ if(prevLineNum!=lineNum){
+ needtoprint=true;
+ break;
+ }
+ }
+ if(needtoprint){
+ output.println("// "+fm.getMethod().getClassDesc().getSourceFileName()+":"+fn.getNumLine());
+ }
+ }
+ }
+
}
TempDescriptor[] nargs=new TempDescriptor[args.length];
for(int i=0;i<nargs.length;i++)
nargs[i]=t.tempMap(args[i]);
+
return new FlatCall(method, ndst, nthis, nargs);
}
protected Vector prev;
static int idcounter=0;
public final int nodeid;
- public int numLine;
+ public int numLine=-1;
public FlatNode() {
next=new Vector();
private int arraycount=0;
public Hashtable cd2locationOrderMap;
public boolean OPTIMIZE=false;
+ public boolean LINENUM=false;
private Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors;
private Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults;
this.m_taskexitnum = 0;
}
- public void buildtree(ParseNode pn, Set toanalyze) {
- parseFile(pn, toanalyze);
+ public void buildtree(ParseNode pn, Set toanalyze, String sourcefile) {
+ parseFile(pn, toanalyze,sourcefile);
// numering the interfaces
int if_num = 0;
NameDescriptor packages;
/** Parse the classes in this file */
- public void parseFile(ParseNode pn, Set toanalyze) {
+ public void parseFile(ParseNode pn, Set toanalyze,String sourcefile) {
singleimports=new Vector();
multiimports=new Vector();
continue;
if (isNode(type_pn,"class_declaration")) {
ClassDescriptor cn=parseTypeDecl(type_pn);
+ cn.setSourceFileName(sourcefile);
parseInitializers(cn);
if (toanalyze!=null)
toanalyze.add(cn);
if(toanalyze != null) {
toanalyze.add(cd);
}
+ cd.setSourceFileName(sourcefile);
state.addClass(cd);
Iterator it_ics = cd.getInnerClasses();
if(toanalyze != null) {
toanalyze.add(iecd);
}
+ iecd.setSourceFileName(sourcefile);
state.addClass(iecd);
}
}
if(toanalyze != null) {
toanalyze.add(ecd);
}
+ ecd.setSourceFileName(sourcefile);
state.addClass(ecd);
}
} else if (isNode(type_pn,"task_declaration")) {
ClassDescriptor cn = parseInterfaceDecl(type_pn);
if (toanalyze!=null)
toanalyze.add(cn);
+ cn.setSourceFileName(sourcefile);
state.addClass(cn);
// for enum
if(toanalyze != null) {
toanalyze.add(ecd);
}
+ ecd.setSourceFileName(sourcefile);
state.addClass(ecd);
}
} else if (isNode(type_pn,"enum_declaration")) {
ClassDescriptor cn = parseEnumDecl(null, type_pn);
if (toanalyze!=null)
toanalyze.add(cn);
+ cn.setSourceFileName(sourcefile);
state.addClass(cn);
} else {
throw new Error(type_pn.getLabel());
ExpressionNode en=null;
if (epn!=null) {
en=parseExpression(epn.getFirstChild());
+ en.setNumLine(epn.getFirstChild().getLine());
if(m.isStatic()) {
// for static field, the initializer should be considered as a
// static block
cn.incStaticBlocks();
BlockNode bn=new BlockNode();
NameNode nn=new NameNode(new NameDescriptor(identifier));
+ nn.setNumLine(en.getNumLine());
AssignmentNode an=new AssignmentNode(nn,en,new AssignOperation(1));
an.setNumLine(pn.getLine());
bn.addBlockStatement(new BlockExpressionNode(an));
ParseNode left=pnv.elementAt(0);
ParseNode right=pnv.elementAt(1);
Operation op=new Operation(pn.getLabel());
- return new OpNode(parseExpression(left),parseExpression(right),op);
+ OpNode on=new OpNode(parseExpression(left),parseExpression(right),op);
+ on.setNumLine(pn.getLine());
+ return on;
} else if (isNode(pn,"unaryplus")||
isNode(pn,"unaryminus")||
isNode(pn,"not")||
isNode(pn,"comp")) {
ParseNode left=pn.getFirstChild();
Operation op=new Operation(pn.getLabel());
- return new OpNode(parseExpression(left),op);
+ OpNode on=new OpNode(parseExpression(left),op);
+ on.setNumLine(pn.getLine());
+ return on;
} else if (isNode(pn,"postinc")||
isNode(pn,"postdec")) {
ParseNode left=pn.getFirstChild();
} else if (isNode(pn,"literal")) {
String literaltype=pn.getTerminal();
ParseNode literalnode=pn.getChild(literaltype);
- Object literal_obj=literalnode.getLiteral();
- return new LiteralNode(literaltype, literal_obj);
+ Object literal_obj=literalnode.getLiteral();
+ LiteralNode ln=new LiteralNode(literaltype, literal_obj);
+ ln.setNumLine(pn.getLine());
+ return ln;
} else if (isNode(pn,"createobject")) {
TypeDescriptor td=parseTypeDescriptor(pn);
return nn;
} else if (isNode(pn,"isavailable")) {
NameDescriptor nd=new NameDescriptor(pn.getTerminal());
- return new OpNode(new NameNode(nd),null,new Operation(Operation.ISAVAILABLE));
+ NameNode nn=new NameNode(nd);
+ nn.setNumLine(pn.getLine());
+ return new OpNode(nn,null,new Operation(Operation.ISAVAILABLE));
} else if (isNode(pn,"methodinvoke1")) {
NameDescriptor nd=parseName(pn.getChild("name"));
Vector args=parseArgumentList(pn);
if (fd.getType().iswrapper()) {
FieldAccessNode fan2=new FieldAccessNode(left, fieldname);
+ fan2.setNumLine(left.getNumLine());
fan2.setField(fd);
fan.left=fan2;
fan.fieldname="value";
if (nd.getBase()!=null) {
/* Big hack */
/* Rewrite NameNode */
- ExpressionNode en=translateNameDescriptorintoExpression(nd);
+ ExpressionNode en=translateNameDescriptorintoExpression(nd,nn.getNumLine());
nn.setExpression(en);
checkExpressionNode(md,nametable,en,td);
} else {
String id=nd.getIdentifier();
NameDescriptor base=nd.getBase();
NameNode n=new NameNode(nn.getName());
+ n.setNumLine(nn.getNumLine());
n.setField(fd);
n.setVar((VarDescriptor)nametable.get("this")); /* Need a pointer to this */
FieldAccessNode fan=new FieldAccessNode(n,"value");
+ fan.setNumLine(n.getNumLine());
FieldDescriptor fdval=(FieldDescriptor) fd.getType().getClassDesc().getFieldTable().get("value");
fan.setField(fdval);
nn.setExpression(fan);
if (!(an.getSrc().getType().isString()&&(an.getSrc() instanceof OpNode))) {
MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
+ rightmin.setNumLine(an.getSrc().getNumLine());
rightmin.addArgument(an.getSrc());
an.right=rightmin;
checkExpressionNode(md, nametable, an.getSrc(), null);
- ExpressionNode translateNameDescriptorintoExpression(NameDescriptor nd) {
+ ExpressionNode translateNameDescriptorintoExpression(NameDescriptor nd, int numLine) {
String id=nd.getIdentifier();
NameDescriptor base=nd.getBase();
- if (base==null)
- return new NameNode(nd);
- else
- return new FieldAccessNode(translateNameDescriptorintoExpression(base),id);
+ if (base==null){
+ NameNode nn=new NameNode(nd);
+ nn.setNumLine(numLine);
+ return nn;
+ }else{
+ FieldAccessNode fan=new FieldAccessNode(translateNameDescriptorintoExpression(base,numLine),id);
+ fan.setNumLine(numLine);
+ return fan;
+ }
}
typetolookin=new TypeDescriptor(cd);
} else if (nametable.get(rootname)!=null) {
//we have an expression
- min.setExpression(translateNameDescriptorintoExpression(min.getBaseName()));
+ min.setExpression(translateNameDescriptorintoExpression(min.getBaseName(),min.getNumLine()));
checkExpressionNode(md, nametable, min.getExpression(), null);
typetolookin=min.getExpression().getType();
} else {
if(!min.getBaseName().getSymbol().equals("System.out")) {
- ExpressionNode nn = translateNameDescriptorintoExpression(min.getBaseName());
+ ExpressionNode nn = translateNameDescriptorintoExpression(min.getBaseName(),min.getNumLine());
checkExpressionNode(md, nametable, nn, null);
typetolookin = nn.getType();
if(!((nn.kind()== Kind.NameNode) && (((NameNode)nn).getField() == null)
NameDescriptor valuend=new NameDescriptor(nd, "valueOf");
if (!(ltd.isString()&&(on.getLeft() instanceof OpNode))) {
MethodInvokeNode leftmin=new MethodInvokeNode(valuend);
+ leftmin.setNumLine(on.getLeft().getNumLine());
leftmin.addArgument(on.getLeft());
on.left=leftmin;
checkExpressionNode(md, nametable, on.getLeft(), null);
if (!(rtd.isString()&&(on.getRight() instanceof OpNode))) {
MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
+ rightmin.setNumLine(on.getRight().getNumLine());
rightmin.addArgument(on.getRight());
on.right=rightmin;
checkExpressionNode(md, nametable, on.getRight(), null);
public class TreeNode {
public static final int INDENT=2;
- int numLine;
+ int numLine=-1;
public String printNode(int indent) {
return null;
if (f.exists()) {
try {
ParseNode pn=Main.readSourceFile(state, f.getCanonicalPath());
- bir.buildtree(pn, todo);
+ bir.buildtree(pn, todo,f.getCanonicalPath());
return;
} catch (Exception e) {
throw new Error(e);
state.NOSTALLTR = true;
} else if (option.equals("-ssjava")){
state.SSJAVA = true;
- } else if (option.equals("-help")) {
+ } else if (option.equals("-printlinenum")){
+ state.LINENUM=true;
+ }else if (option.equals("-help")) {
System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
System.out.println("-selfloop task -- this task doesn't self loop its parameters forever");
System.out.println("-dir outputdirectory -- output code in outputdirectory");
System.out.println("-printscheduling -- print out scheduling graphs");
System.out.println("-printschedulesim -- print out scheduling simulation result graphs");
System.out.println("-webinterface -- enable web interface");
+ System.out.println("-linenum print out line numbers in generated C codes");
System.out.println("-help -- print out help");
System.exit(0);
} else {
public static void loadClass(State state, BuildIR bir, String sourcefile) {
try {
ParseNode pn=readSourceFile(state, sourcefile);
- bir.buildtree(pn, null);
+ bir.buildtree(pn, null,sourcefile);
} catch (Exception e) {
System.out.println("Error in sourcefile:"+sourcefile);
e.printStackTrace();
echo -dsmtask support work and task class library
echo -recoverystats print out recovery record
echo -src-after-pp prints source code after preprocessor to tmp.c
+echo -printlinenum print out line numbers in generated C codes
echo -help help
}
then
JAVAOPTS="$JAVAOPTS -nostalltr"
+elif [[ $1 = '-printlinenum' ]]
+then
+JAVAOPTS="$JAVAOPTS -printlinenum"
+
elif [[ $1 = '-rcr' ]]
then
JAVAOPTS="$JAVAOPTS -rcr"