changes for language and solver work

This commit is contained in:
Julian Dolby 2015-12-09 17:28:45 -05:00
parent ab22d9abb0
commit 9267003c5b
5 changed files with 47 additions and 24 deletions

View File

@ -61,9 +61,9 @@ public class DefaultSourceExtractor extends DomLessSourceExtractor{
String v = e.getValue().fst;
if (v != null && v.startsWith("javascript:")) {
try {
entrypointRegion.println(" " + v.substring(11), e.getValue().snd, new URL(tag.getElementPosition().getURL().toString() + "#" + a), true);
writeEntrypoint(" " + v.substring(11), e.getValue().snd, new URL(tag.getElementPosition().getURL().toString() + "#" + a), true);
} catch (MalformedURLException ex) {
entrypointRegion.println(v.substring(11), e.getValue().snd, entrypointUrl, false);
writeEntrypoint(v.substring(11), e.getValue().snd, entrypointUrl, false);
}
}
}
@ -78,7 +78,7 @@ public class DefaultSourceExtractor extends DomLessSourceExtractor{
newLine();
}
private void printlnIndented(String line, ITag relatedTag){
protected void printlnIndented(String line, ITag relatedTag){
printlnIndented(line, relatedTag==null? null: relatedTag.getElementPosition());
}
@ -142,6 +142,8 @@ public class DefaultSourceExtractor extends DomLessSourceExtractor{
}
}
}
inputElementCallback(tag);
}
assert varName != null && !"".equals(varName);
@ -150,6 +152,10 @@ public class DefaultSourceExtractor extends DomLessSourceExtractor{
printlnIndented("parent.appendChild(this);", tag);
}
protected void inputElementCallback(ITag tag) {
// this space intentionally left blank
}
protected void writeAttribute(ITag tag, Position pos, String attr, String value, String varName, String varName2) {
writePortletAttribute(tag, attr, value, varName);
writeEventAttribute(tag, pos, attr, value, varName, varName2);
@ -159,7 +165,7 @@ public class DefaultSourceExtractor extends DomLessSourceExtractor{
//There should probably be more checking to see what the attributes are since we allow things like: ; to be used as attributes now.
if(attr.length() >= 2 && attr.substring(0,2).equals("on")) {
printlnIndented(varName + "." + attr + " = function " + tag.getName().toLowerCase() + "_" + attr + "(event) {" + value + "};", tag);
entrypointRegion.println(varName2 + "." + attr + "(null);", tag.getElementPosition(), entrypointUrl, false);
writeEntrypoint(varName2 + "." + attr + "(null);", tag.getElementPosition(), entrypointUrl, false);
} else if (value != null) {
Pair<String, Character> x = quotify(value);

View File

@ -79,9 +79,13 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
addDefaultHandlerInvocations();
}
private void addDefaultHandlerInvocations() {
protected void writeEntrypoint(String ep) {
entrypointRegion.println(ep);
}
protected void addDefaultHandlerInvocations() {
// always invoke window.onload
entrypointRegion.println("window.onload();");
writeEntrypoint("window.onload();");
}
protected Position makePos(int lineNumber, ITag governingTag) {
@ -187,10 +191,14 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
// Defines the function
domRegion.println(signatureLine + "\n" + extructJS(attValue) + "\n}", pos, url, true);
// Run it
entrypointRegion.println("\t" + fName + "(null);", pos, url, true);
writeEntrypoint("\t" + fName + "(null);", pos, url, true);
}
}
protected void writeEntrypoint(String text, Position pos, URL url, boolean b) {
entrypointRegion.println(text, pos, url, b);
}
protected static Pair<String,Character> quotify(String value) {
char quote;
if (value.indexOf('"') < 0) {
@ -288,6 +296,10 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
return file;
}
protected void writeEventLoopHeader(SourceRegion finalRegion) {
finalRegion.println("while (true){ // event loop model");
}
@Override
public void writeToFinalRegion(SourceRegion finalRegion) {
// wrapping the embedded scripts with a fake method of the window. Required for making this == window.
@ -299,9 +311,9 @@ public class DomLessSourceExtractor extends JSSourceExtractor {
finalRegion.println(" document.URL = new String(\"" + entrypointUrl + "\");");
finalRegion.println("while (true){ ");
writeEventLoopHeader(finalRegion);
finalRegion.write(entrypointRegion);
finalRegion.println("} // while (true)");
finalRegion.println("} // event loop model");
finalRegion.println("} // end of window.__MAIN__");
finalRegion.println("window.__MAIN__();");

View File

@ -75,7 +75,7 @@ abstract public class ScopeMappingInstanceKeys implements InstanceKeyFactory {
*/
private final CGNode creator;
private ScopeMappingInstanceKey(CGNode creator, InstanceKey base) {
public ScopeMappingInstanceKey(CGNode creator, InstanceKey base) {
this.creator = creator;
this.base = base;
}

View File

@ -1519,7 +1519,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
Scope getParent();
}
private static abstract class AbstractSymbol implements Symbol {
public static abstract class AbstractSymbol implements Symbol {
private Object constantValue;
private boolean isFinalValue;
@ -1528,7 +1528,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
private Object defaultValue;
AbstractSymbol(Scope definingScope, boolean isFinalValue, Object defaultValue) {
protected AbstractSymbol(Scope definingScope, boolean isFinalValue, Object defaultValue) {
this.definingScope = definingScope;
this.isFinalValue = isFinalValue;
this.defaultValue = defaultValue;
@ -1560,7 +1560,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
}
};
private abstract class AbstractScope implements Scope {
public abstract class AbstractScope implements Scope {
private final Scope parent;
private final Map<String, Symbol> values = new LinkedHashMap<String, Symbol>();
@ -1651,7 +1651,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
}
}
AbstractScope(Scope parent) {
protected AbstractScope(Scope parent) {
this.parent = parent;
}
@ -1715,7 +1715,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
public abstract CAstEntity getEntity();
};
private AbstractScope makeScriptScope(final CAstEntity s, Scope parent) {
protected AbstractScope makeScriptScope(final CAstEntity s, Scope parent) {
return new AbstractScope(parent) {
SymbolTable scriptGlobalSymtab = new SymbolTable(s.getArgumentCount());
@ -2523,7 +2523,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
}
private class CodeEntityContext extends EntityContext {
public class CodeEntityContext extends EntityContext {
private final Scope topEntityScope;
private final Set<Scope> allEntityScopes;
@ -2543,7 +2543,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
*/
private final Map<CAstNode, Integer> results = new LinkedHashMap<CAstNode, Integer>();
CodeEntityContext(WalkContext parent, Scope entityScope, CAstEntity s) {
public CodeEntityContext(WalkContext parent, Scope entityScope, CAstEntity s) {
super(parent, s);
this.topEntityScope = entityScope;
@ -3024,7 +3024,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
context.exposeNameSet(entity, isWrite).add(newVal);
}
private void setDefaultValue(SymbolTable symtab, int vn, Object value) {
public void setDefaultValue(SymbolTable symtab, int vn, Object value) {
if (value == CAstSymbol.NULL_DEFAULT_VALUE) {
symtab.setDefaultValue(vn, null);
} else {

View File

@ -19,19 +19,24 @@ import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
public class RangePosition extends AbstractSourcePosition implements Position {
private final URL url;
private final int line;
private final int startLine;
private final int endLine;
private final int startOffset;
private final int endOffset;
public RangePosition(URL url, int line, int startOffset, int endOffset) {
public RangePosition(URL url, int startLine, int endLine, int startOffset, int endOffset) {
super();
this.url = url;
this.line = line;
this.startLine = startLine;
this.endLine = endLine;
this.startOffset = startOffset;
this.endOffset = endOffset;
}
public RangePosition(URL url, int line, int startOffset, int endOffset) {
this(url, line, -1, startOffset, endOffset);
}
@Override
public int compareTo(Object o) {
Position other = (Position) o;
@ -44,12 +49,12 @@ public class RangePosition extends AbstractSourcePosition implements Position {
@Override
public int getFirstLine() {
return line;
return startLine;
}
@Override
public int getLastLine() {
return -1;
return endLine;
}
@Override