-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12885 from tanishiking/semanticdb-signature
Signature information in Semanticdb
- Loading branch information
Showing
53 changed files
with
3,501 additions
and
2,229 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
compiler/src/dotty/tools/dotc/semanticdb/ConstantOps.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dotty.tools | ||
package dotc | ||
package semanticdb | ||
|
||
import dotty.tools.dotc.{semanticdb => s} | ||
|
||
import core.Contexts.Context | ||
import core.Constants._ | ||
|
||
object ConstantOps: | ||
extension (const: Constant) | ||
def toSemanticConst(using Context): s.Constant = const.tag match { | ||
case UnitTag => s.UnitConstant() | ||
case BooleanTag => s.BooleanConstant(const.booleanValue) | ||
case ByteTag => s.ByteConstant(const.byteValue) | ||
case ShortTag => s.ShortConstant(const.shortValue) | ||
case CharTag => s.CharConstant(const.charValue) | ||
case IntTag => s.IntConstant(const.intValue) | ||
case LongTag => s.LongConstant(const.longValue) | ||
case FloatTag => s.FloatConstant(const.floatValue) | ||
case DoubleTag => s.DoubleConstant(const.doubleValue) | ||
case StringTag => s.StringConstant(const.stringValue) | ||
case NullTag => s.NullConstant() | ||
case _ => throw new Error(s"Constant ${const} can't be converted to Semanticdb Constant.") | ||
} |
120 changes: 120 additions & 0 deletions
120
compiler/src/dotty/tools/dotc/semanticdb/Descriptor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package dotty.tools.dotc.semanticdb | ||
|
||
import java.lang.System.{lineSeparator => EOL} | ||
import dotty.tools.dotc.semanticdb.{Descriptor => d} | ||
|
||
class DescriptorParser(s: String) { | ||
var i = s.length | ||
def fail() = { | ||
val message = "invalid symbol format" | ||
val caret = " " * i + "^" | ||
sys.error(s"$message$EOL$s$EOL$caret") | ||
} | ||
|
||
val BOF = '\u0000' | ||
val EOF = '\u001A' | ||
var currChar = EOF | ||
def readChar(): Char = { | ||
if (i <= 0) { | ||
if (i == 0) { | ||
i -= 1 | ||
currChar = BOF | ||
currChar | ||
} else { | ||
fail() | ||
} | ||
} else { | ||
i -= 1 | ||
currChar = s(i) | ||
currChar | ||
} | ||
} | ||
|
||
def parseValue(): String = { | ||
if (currChar == '`') { | ||
val end = i | ||
while (readChar() != '`') {} | ||
readChar() | ||
s.substring(i + 2, end) | ||
} else { | ||
val end = i + 1 | ||
if (!Character.isJavaIdentifierPart(currChar)) fail() | ||
while (Character.isJavaIdentifierPart(readChar()) && currChar != BOF) {} | ||
s.substring(i + 1, end) | ||
} | ||
} | ||
|
||
def parseDisambiguator(): String = { | ||
val end = i + 1 | ||
if (currChar != ')') fail() | ||
while (readChar() != '(') {} | ||
readChar() | ||
s.substring(i + 1, end) | ||
} | ||
|
||
def parseDescriptor(): Descriptor = { | ||
if (currChar == '.') { | ||
readChar() | ||
if (currChar == ')') { | ||
val disambiguator = parseDisambiguator() | ||
val value = parseValue() | ||
d.Method(value, disambiguator) | ||
} else { | ||
d.Term(parseValue()) | ||
} | ||
} else if (currChar == '#') { | ||
readChar() | ||
d.Type(parseValue()) | ||
} else if (currChar == '/') { | ||
readChar() | ||
d.Package(parseValue()) | ||
} else if (currChar == ')') { | ||
readChar() | ||
val value = parseValue() | ||
if (currChar != '(') fail() | ||
else readChar() | ||
d.Parameter(value) | ||
} else if (currChar == ']') { | ||
readChar() | ||
val value = parseValue() | ||
if (currChar != '[') fail() | ||
else readChar() | ||
d.TypeParameter(value) | ||
} else { | ||
fail() | ||
} | ||
} | ||
|
||
def entryPoint(): (Descriptor, String) = { | ||
readChar() | ||
val desc = parseDescriptor() | ||
(desc, s.substring(0, i + 1)) | ||
} | ||
} | ||
|
||
object DescriptorParser { | ||
def apply(symbol: String): (Descriptor, String) = { | ||
val parser = new DescriptorParser(symbol) | ||
parser.entryPoint() | ||
} | ||
} | ||
|
||
sealed trait Descriptor { | ||
def isNone: Boolean = this == d.None | ||
def isTerm: Boolean = this.isInstanceOf[d.Term] | ||
def isMethod: Boolean = this.isInstanceOf[d.Method] | ||
def isType: Boolean = this.isInstanceOf[d.Type] | ||
def isPackage: Boolean = this.isInstanceOf[d.Package] | ||
def isParameter: Boolean = this.isInstanceOf[d.Parameter] | ||
def isTypeParameter: Boolean = this.isInstanceOf[d.TypeParameter] | ||
def value: String | ||
} | ||
object Descriptor { | ||
case object None extends Descriptor { def value: String = "" } | ||
final case class Term(value: String) extends Descriptor | ||
final case class Method(value: String, disambiguator: String) extends Descriptor | ||
final case class Type(value: String) extends Descriptor | ||
final case class Package(value: String) extends Descriptor | ||
final case class Parameter(value: String) extends Descriptor | ||
final case class TypeParameter(value: String) extends Descriptor | ||
} |
Oops, something went wrong.