vbnet.atg
来自「SharpDevelop2.0.0 c#开发免费工具」· ATG 代码 · 共 2,331 行 · 第 1/5 页
ATG
2,331 行
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using ICSharpCode.NRefactory.Parser.AST;
using ICSharpCode.NRefactory.Parser.VB;
using ASTAttribute = ICSharpCode.NRefactory.Parser.AST.Attribute;
COMPILER VBNET
private string assemblyName = null;
private Stack withStatements;
private StringBuilder qualidentBuilder = new StringBuilder();
public string ContainingAssembly
{
set { assemblyName = value; }
}
Token t
{
get {
return lexer.Token;
}
}
Token la
{
get {
return lexer.LookAhead;
}
}
/* Return the n-th token after the current lookahead token */
void StartPeek()
{
lexer.StartPeek();
}
Token Peek()
{
return lexer.Peek();
}
Token Peek (int n)
{
lexer.StartPeek();
Token x = la;
while (n > 0) {
x = lexer.Peek();
n--;
}
return x;
}
public void Error(string s)
{
if (errDist >= minErrDist) {
errors.Error(la.line, la.col, s);
}
errDist = 0;
}
public override Expression ParseExpression()
{
lexer.NextToken();
Expression expr;
Expr(out expr);
return expr;
}
bool LeaveBlock()
{
int peek = Peek(1).kind;
return Tokens.BlockSucc[la.kind] && (la.kind != Tokens.End || peek == Tokens.EOL || peek == Tokens.Colon);
}
/* True, if "." is followed by an ident */
bool DotAndIdentOrKw () {
int peek = Peek(1).kind;
return la.kind == Tokens.Dot && (peek == Tokens.Identifier || peek >= Tokens.AddHandler);
}
bool IsEndStmtAhead()
{
int peek = Peek(1).kind;
return la.kind == Tokens.End && (peek == Tokens.EOL || peek == Tokens.Colon);
}
bool IsNotClosingParenthesis() {
return la.kind != Tokens.CloseParenthesis;
}
/*
True, if ident is followed by "="
*/
bool IdentAndAsgn () {
if(la.kind == Tokens.Identifier) {
if(Peek(1).kind == Tokens.Assign) return true;
if(Peek(1).kind == Tokens.Colon && Peek(2).kind == Tokens.Assign) return true;
}
return false;
}
/*
True, if ident is followed by "=" or by ":" and "="
*/
bool IsNamedAssign() {
// if(Peek(1).kind == Tokens.Assign) return true; // removed: not in the lang spec
if(Peek(1).kind == Tokens.Colon && Peek(2).kind == Tokens.Assign) return true;
return false;
}
bool IsObjectCreation() {
return la.kind == Tokens.As && Peek(1).kind == Tokens.New;
}
/*
True, if "<" is followed by the ident "assembly" or "module"
*/
bool IsGlobalAttrTarget () {
Token pt = Peek(1);
return la.kind == Tokens.LessThan && ( string.Equals(pt.val, "assembly", StringComparison.InvariantCultureIgnoreCase) || string.Equals(pt.val, "module", StringComparison.InvariantCultureIgnoreCase));
}
/*
True if the next token is a "(" and is followed by "," or ")"
*/
bool IsDims()
{
int peek = Peek(1).kind;
return la.kind == Tokens.OpenParenthesis
&& (peek == Tokens.Comma || peek == Tokens.CloseParenthesis);
}
bool IsSize()
{
return la.kind == Tokens.OpenParenthesis;
}
/*
True, if the comma is not a trailing one,
like the last one in: a, b, c,
*/
bool NotFinalComma() {
int peek = Peek(1).kind;
return la.kind == Tokens.Comma &&
peek != Tokens.CloseCurlyBrace;
}
/*
True, if the next token is "Else" and this one
if followed by "If"
*/
bool IsElseIf()
{
int peek = Peek(1).kind;
return la.kind == Tokens.Else && peek == Tokens.If;
}
/*
True if the next token is goto and this one is
followed by minus ("-") (this is allowd in in
error clauses)
*/
bool IsNegativeLabelName()
{
int peek = Peek(1).kind;
return la.kind == Tokens.GoTo && peek == Tokens.Minus;
}
/*
True if the next statement is a "Resume next" statement
*/
bool IsResumeNext()
{
int peek = Peek(1).kind;
return la.kind == Tokens.Resume && peek == Tokens.Next;
}
/*
True, if ident/literal integer is followed by ":"
*/
bool IsLabel()
{
return (la.kind == Tokens.Identifier || la.kind == Tokens.LiteralInteger)
&& Peek(1).kind == Tokens.Colon;
}
bool IsNotStatementSeparator()
{
return la.kind == Tokens.Colon && Peek(1).kind == Tokens.EOL;
}
bool IsAssignment ()
{
return IdentAndAsgn();
}
bool IsMustOverride(Modifiers m)
{
return m.Contains(Modifier.Abstract);
}
TypeReferenceExpression GetTypeReferenceExpression(Expression expr, List<TypeReference> genericTypes)
{
TypeReferenceExpression tre = expr as TypeReferenceExpression;
if (tre != null) {
return new TypeReferenceExpression(new TypeReference(tre.TypeReference.Type, tre.TypeReference.PointerNestingLevel, tre.TypeReference.RankSpecifier, genericTypes));
}
StringBuilder b = new StringBuilder();
if (!WriteFullTypeName(b, expr)) {
// there is some TypeReferenceExpression hidden in the expression
while (expr is FieldReferenceExpression) {
expr = ((FieldReferenceExpression)expr).TargetObject;
}
tre = expr as TypeReferenceExpression;
if (tre != null) {
TypeReference typeRef = tre.TypeReference;
if (typeRef.GenericTypes.Count == 0) {
typeRef = typeRef.Clone();
typeRef.Type += "." + b.ToString();
typeRef.GenericTypes.AddRange(genericTypes);
} else {
typeRef = new InnerClassTypeReference(typeRef, b.ToString(), genericTypes);
}
return new TypeReferenceExpression(typeRef);
}
}
return new TypeReferenceExpression(new TypeReference(b.ToString(), 0, null, genericTypes));
}
/* Writes the type name represented through the expression into the string builder. */
/* Returns true when the expression was converted successfully, returns false when */
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */
bool WriteFullTypeName(StringBuilder b, Expression expr)
{
FieldReferenceExpression fre = expr as FieldReferenceExpression;
if (fre != null) {
bool result = WriteFullTypeName(b, fre.TargetObject);
if (b.Length > 0) b.Append('.');
b.Append(fre.FieldName);
return result;
} else if (expr is IdentifierExpression) {
b.Append(((IdentifierExpression)expr).Identifier);
return true;
} else {
return false;
}
}
/*
True, if lookahead is a local attribute target specifier,
i.e. one of "event", "return", "field", "method",
"module", "param", "property", or "type"
*/
bool IsLocalAttrTarget() {
// TODO
return false;
}
/* START AUTOGENERATED TOKENS SECTION */
TOKENS
/* ----- terminal classes ----- */
/* EOF is 0 */
EOL
ident
LiteralString
LiteralCharacter
LiteralInteger
LiteralDouble
LiteralSingle
LiteralDecimal
LiteralDate
/* ----- special character ----- */
"."
"="
","
":"
"+"
"-"
"*"
"/"
"\\"
"&"
"^"
"?"
"{"
"}"
"("
")"
">"
"<"
"<>"
">="
"<="
"<<"
">>"
"+="
"^="
"-="
"*="
"/="
"\\="
"<<="
">>="
"&="
/* ----- keywords ----- */
"AddHandler"
"AddressOf"
"Alias"
"And"
"AndAlso"
"Ansi"
"As"
"Assembly"
"Auto"
"Binary"
"Boolean"
"ByRef"
"Byte"
"ByVal"
"Call"
"Case"
"Catch"
"CBool"
"CByte"
"CChar"
"CDate"
"CDbl"
"CDec"
"Char"
"CInt"
"Class"
"CLng"
"CObj"
"Compare"
"Const"
"CShort"
"CSng"
"CStr"
"CType"
"Date"
"Decimal"
"Declare"
"Default"
"Delegate"
"Dim"
"DirectCast"
"Do"
"Double"
"Each"
"Else"
"ElseIf"
"End"
"EndIf"
"Enum"
"Erase"
"Error"
"Event"
"Exit"
"Explicit"
"False"
"Finally"
"For"
"Friend"
"Function"
"Get"
"GetType"
"GoSub"
"GoTo"
"Handles"
"If"
"Implements"
"Imports"
"In"
"Inherits"
"Integer"
"Interface"
"Is"
"Let"
"Lib"
"Like"
"Long"
"Loop"
"Me"
"Mod"
"Module"
"MustInherit"
"MustOverride"
"MyBase"
"MyClass"
"Namespace"
"New"
"Next"
"Not"
"Nothing"
"NotInheritable"
"NotOverridable"
"Object"
"Off"
"On"
"Option"
"Optional"
"Or"
"OrElse"
"Overloads"
"Overridable"
"Overrides"
"ParamArray"
"Preserve"
"Private"
"Property"
"Protected"
"Public"
"RaiseEvent"
"ReadOnly"
"ReDim"
"RemoveHandler"
"Resume"
"Return"
"Select"
"Set"
"Shadows"
"Shared"
"Short"
"Single"
"Static"
"Step"
"Stop"
"Strict"
"String"
"Structure"
"Sub"
"SyncLock"
"Text"
"Then"
"Throw"
"To"
"True"
"Try"
"TypeOf"
"Unicode"
"Until"
"Variant"
"Wend"
"When"
"While"
"With"
"WithEvents"
"WriteOnly"
"Xor"
"Continue"
"Operator"
"Using"
"IsNot"
"SByte"
"UInteger"
"ULong"
"UShort"
"CSByte"
"CUShort"
"CUInt"
"CULng"
"Global"
"TryCast"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?