2015-10-14 20:01:52 +00:00
|
|
|
/*
|
2018-10-30 00:09:20 +00:00
|
|
|
* Copyright (c) 2010-2015 SAP SE.
|
|
|
|
* 2016-2018 The University of Sheffield.
|
|
|
|
*
|
2015-10-14 20:01:52 +00:00
|
|
|
* All rights reserved. This program and the accompanying materials
|
2018-10-30 00:09:20 +00:00
|
|
|
* This program and the accompanying materials are made
|
|
|
|
* available under the terms of the Eclipse Public License 2.0
|
|
|
|
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
2015-10-14 20:01:52 +00:00
|
|
|
*
|
2018-10-30 00:09:20 +00:00
|
|
|
* SPDX-License-Identifier: EPL-2.0
|
2015-10-14 20:01:52 +00:00
|
|
|
*/
|
|
|
|
|
2017-05-21 14:58:16 +00:00
|
|
|
package com.logicalhacking.dasca.crosslanguage.util
|
2015-10-14 20:01:52 +00:00
|
|
|
|
|
|
|
import com.ibm.wala.cast.ir.ssa.AstIRFactory
|
|
|
|
import com.ibm.wala.classLoader.CallSiteReference
|
|
|
|
import com.ibm.wala.ipa.callgraph.CGNode
|
|
|
|
import com.ibm.wala.ssa.SSAInstruction
|
|
|
|
import com.ibm.wala.cast.js.html.IncludedPosition
|
2016-08-07 11:02:31 +00:00
|
|
|
import com.ibm.wala.classLoader.IMethod
|
2018-10-25 20:52:51 +00:00
|
|
|
import com.ibm.wala.cast.ir.ssa.AstIRFactory.AstIR
|
2015-10-14 20:01:52 +00:00
|
|
|
|
|
|
|
class JavaScriptSourceLocation(val line: Int, val column: Int, val filePath: String) extends SourceLocation with Equals {
|
|
|
|
|
|
|
|
override def toString = s"$filePath:$line:$column"
|
|
|
|
|
|
|
|
override def equals(other: Any) = other match {
|
|
|
|
case o: JavaScriptSourceLocation => line == o.line && column == o.column && filePath == o.filePath
|
|
|
|
case _ => false
|
|
|
|
}
|
|
|
|
|
|
|
|
def canEqual(other: Any) = {
|
2017-05-21 14:58:16 +00:00
|
|
|
other.isInstanceOf[com.logicalhacking.dasca.crosslanguage.util.JavaScriptSourceLocation]
|
2015-10-14 20:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override def hashCode() = {
|
|
|
|
val prime = 41
|
|
|
|
prime * (prime * (prime + line.hashCode) + column.hashCode) + filePath.hashCode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object JavaScriptSourceLocation {
|
|
|
|
val JavaScriptPathRegex = """.+/assets/(.+)""".r
|
|
|
|
|
2018-10-25 20:52:51 +00:00
|
|
|
def apply(ir: AstIR, inst: SSAInstruction): JavaScriptSourceLocation = {
|
2016-08-07 11:02:31 +00:00
|
|
|
val (line:Int, col:Int, _, _, relPath:String) = Util.getJavaScriptSourceInfo(ir, inst)
|
2015-10-14 20:01:52 +00:00
|
|
|
new JavaScriptSourceLocation(line, col, relPath)
|
|
|
|
}
|
|
|
|
|
2018-10-25 20:52:51 +00:00
|
|
|
def apply(ir: AstIR, csr: CallSiteReference): JavaScriptSourceLocation = apply(ir, ir.getCalls(csr)(0))
|
2015-10-14 20:01:52 +00:00
|
|
|
|
2018-10-25 20:52:51 +00:00
|
|
|
def apply(ir: AstIR): JavaScriptSourceLocation = apply(ir, ir.getInstructions.find({ i => i != null }).get)
|
2015-10-14 20:01:52 +00:00
|
|
|
}
|