private void TryFixPartial(ErrorSink /*!*/ errors, Declaration /*!*/ first, Declaration /*!*/ second) { if (!first.IsPartial && !first.IsConditional) { // report error and mark the declaration partial: errors.Add(Errors.MissingPartialModifier, first.SourceUnit, first.Span, first.Declaree.FullName); errors.Add(Errors.RelatedLocation, second.SourceUnit, second.Span); first.IsPartial = true; } }
/// <summary> /// Check is given <paramref name="declarerName"/> and its <paramref name="typeParams"/> are without duplicity. /// </summary> /// <param name="typeParams">Generic type parameters.</param> /// <param name="declarerName">Type name.</param> private void CheckTypeParameterNames(List <FormalTypeParam> typeParams, string /*!*/ declarerName) { if (typeParams == null) { return; } for (int i = 0; i < typeParams.Count; i++) { if (typeParams[i].Name.Equals(declarerName)) { ErrorSink.Add(Errors.GenericParameterCollidesWithDeclarer, SourceUnit, typeParams[i].Position, declarerName); } else if (CurrentScopeAliases.ContainsKey(typeParams[i].Name.Value)) { ErrorSink.Add(Errors.GenericAlreadyInUse, SourceUnit, typeParams[i].Position, typeParams[i].Name.Value); } else { for (int j = 0; j < i; j++) { if (typeParams[j].Name.Equals(typeParams[i].Name)) { errors.Add(Errors.DuplicateGenericParameter, SourceUnit, typeParams[i].Position); } } } } }
public override ScriptCode CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink) { using (var reader = sourceUnit.GetReader()) { try { switch (sourceUnit.Kind) { case SourceCodeKind.SingleStatement: case SourceCodeKind.Expression: case SourceCodeKind.AutoDetect: case SourceCodeKind.InteractiveCode: return(new VBScriptCode( _vbscript, _vbscript.ParseExprToLambda(reader), sourceUnit)); case SourceCodeKind.Statements: case SourceCodeKind.File: return(new VBScriptCode( _vbscript, _vbscript.ParseFileToLambda(sourceUnit.Path, reader), sourceUnit)); default: throw Assert.Unreachable; } } catch (VBScriptCompilerException ex) { VBScriptSourceCodeReader vbscriptReader = reader as VBScriptSourceCodeReader; if (vbscriptReader != null) { ISourceMapper mapper = vbscriptReader.SourceMapper; if (mapper != null) { foreach (VBScriptSyntaxError error in ex.SyntaxErrors) { DocSpan docSpan = mapper.Map(error.Span); error.FileName = docSpan.Uri; error.Span = docSpan.Span; } } } throw ex; } catch (Exception e) { // Real language implementation would have a specific type // of exception. Also, they would pass errorSink down into // the parser and add messages while doing tighter error // recovery and continuing to parse. errorSink.Add(sourceUnit, e.Message, SourceSpan.None, 0, Severity.FatalError); return(null); } } }
private Arguments /*!*/ RequireNoBlockArg(TokenValue arguments) { if (arguments.Block != null) { ErrorSink.Add(_sourceUnit, "block argument should not be given", arguments.Block.Location, -1, Severity.Error); arguments.Block = null; } return(arguments.Arguments); }
void AddError(string message, SourceSpan span, int errorCode, Severity severity) { if (_sourceUnit != null) { ErrorSink.Add(_sourceUnit, message, span, errorCode, severity); } else { ErrorSink.Add(message, null, null, _line, span, errorCode, severity); } }
private List <Expression> /*!*/ CheckHashExpressions(List <Expression> /*!*/ expressions, SourceSpan location) { Assert.NotNull(expressions); if (expressions.Count % 2 != 0) { ErrorSink.Add(_sourceUnit, "odd number list for Hash", location, -1, Severity.Error); expressions.Add(Literal.Nil(SourceSpan.None)); } return(expressions); }
private Expression /*!*/[] /*!*/ PopHashArguments(int argumentCount, SourceSpan location) { if (argumentCount % 2 != 0) { ErrorSink.Add(_sourceUnit, "odd number list for Hash", location, -1, Severity.Error); return(PopArguments(argumentCount, Literal.Nil(SourceSpan.None))); } else { return(PopArguments(argumentCount)); } }
//#region Imports ///// <summary> ///// Import of a particular type or function. ///// </summary> //public void AddImport(Position position, DeclarationKind kind, List<string>/*!*/ names, string aliasName) //{ // QualifiedName qn = new QualifiedName(names, true, true); // Name alias = (aliasName != null) ? new Name(aliasName) : qn.Name; // switch (kind) // { // case DeclarationKind.Type: // if (!sourceUnit.AddTypeAlias(qn, alias)) // errors.Add(Errors.ConflictingTypeAliases, SourceUnit, position); // break; // case DeclarationKind.Function: // if (!sourceUnit.AddFunctionAlias(qn, alias)) // errors.Add(Errors.ConflictingFunctionAliases, SourceUnit, position); // break; // case DeclarationKind.Constant: // if (!sourceUnit.AddConstantAlias(qn, alias)) // errors.Add(Errors.ConflictingConstantAliases, SourceUnit, position); // break; // } //} ///// <summary> ///// Import of a namespace with a qualified name. ///// </summary> //public void AddImport(List<string>/*!*/ namespaceNames) //{ // sourceUnit.AddImportedNamespace(new QualifiedName(namespaceNames, false, true)); //} ///// <summary> ///// Import of a namespace with a simple name. ///// </summary> //public void AddImport(string namespaceName) //{ // sourceUnit.AddImportedNamespace(new QualifiedName(Name.EmptyBaseName, new Name[] { new Name(namespaceName) })); //} public void AddImport(QualifiedName namespaceName) { if (sourceUnit.CompilationUnit.IsPure) { ErrorSink.Add(Warnings.ImportDeprecated, SourceUnit, this.yypos); // deprecated statement sourceUnit.ImportedNamespaces.Add(namespaceName); } else { ErrorSink.Add(Errors.ImportOnlyInPureMode, sourceUnit, this.yypos); // does actually not happen, since T_IMPORT is not recognized outside Pure mode at all } }
internal bool Merge(ErrorSink/*!*/ errors, FormalTypeParam/*!*/ other) { if (this.name != other.Name) { PhpType declaring_type = (PhpType)parameter.DeclaringMember; errors.Add(Errors.PartialDeclarationsDifferInTypeParameter, declaring_type.Declaration.SourceUnit, position, declaring_type.FullName); return false; } attributes.Merge(other.Attributes); return true; }
public override ScriptCode CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink) { try { var lexer = new Lexer(sourceUnit.GetReader().ReadToEnd()); var program = new RilaParser(lexer).Parse().ConstructProgram(rila); return(new RilaScriptCode(program.Compile(), rila, sourceUnit)); } catch (Exception e) { errorSink.Add(sourceUnit, e.Message, SourceSpan.None, 0, Severity.FatalError); } return(null); }
public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity) { // Note that we cannot use "source.SourceUnit" since "source" may be a proxy object, and we will not be able to marshall // "source.SourceUnit" to the current AppDomain string code = null; string line = null; try { code = source.GetCode(); line = source.GetCodeLine(span.Start.Line); } catch (System.IO.IOException) { // could not get source code. } _errorSink.Add(message, source.Path, code, line, span, errorCode, severity); }
private Body /*!*/ MakeBody(Statements /*!*/ statements, List <RescueClause> rescueClauses, ElseIfClause elseIf, SourceSpan elseIfLocation, Statements ensureStatements, SourceSpan location) { Debug.Assert(elseIf == null || elseIf.Condition == null); if (elseIf != null && rescueClauses == null) { ErrorSink.Add(_sourceUnit, "else without rescue is useless", elseIfLocation, -1, Severity.Warning); } return(new Body( statements, rescueClauses, (elseIf != null) ? elseIf.Statements : null, ensureStatements, location )); }
protected bool CheckDeclaration(ErrorSink /*!*/ errors, IDeclaree /*!*/ member, Declaration /*!*/ existing) { Declaration current = member.Declaration; if (existing.IsPartial ^ current.IsPartial) { TryFixPartial(errors, current, existing); TryFixPartial(errors, existing, current); } if ((!existing.IsPartial || !current.IsPartial) && (!existing.IsConditional || !current.IsConditional)) { // report fatal error (do not throw an exception, just don't let the analysis continue): member.ReportRedeclaration(errors); errors.Add(FatalErrors.RelatedLocation, existing.SourceUnit, existing.Span); return(false); } return(true); }
internal static object[] /*!!*/ ToStaticTypeRefs(List <TypeRef> /*!*/ typeRefs, ErrorSink /*!*/ errors, SourceUnit /*!*/ sourceUnit) { if (typeRefs.Count == 0) { return(ArrayUtils.EmptyObjects); } object[] result = new object[typeRefs.Count]; for (int i = 0; i < typeRefs.Count; i++) { result[i] = typeRefs[i].ToStaticTypeRef(errors, sourceUnit); if (result[i] == null) { errors.Add(Errors.GenericParameterMustBeType, sourceUnit, typeRefs[i].Position); result[i] = PrimitiveType.Object; } } return(result); }
// This is all that's needed to run code on behalf of language-independent // DLR hosting. Sympl defines its own subtype of ScriptCode. // public override ScriptCode CompileSourceCode( SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink) { using (var reader = sourceUnit.GetReader()) { try { switch (sourceUnit.Kind) { case SourceCodeKind.SingleStatement: case SourceCodeKind.Expression: case SourceCodeKind.AutoDetect: case SourceCodeKind.InteractiveCode: return(new SymplScriptCode( _sympl, _sympl.ParseExprToLambda(reader), sourceUnit)); case SourceCodeKind.Statements: case SourceCodeKind.File: return(new SymplScriptCode( _sympl, _sympl.ParseFileToLambda(sourceUnit.Path, reader), sourceUnit)); default: throw Assert.Unreachable; } } catch (Exception e) { // Real language implementation would have a specific type // of exception. Also, they would pass errorSink down into // the parser and add messages while doing tighter error // recovery and continuing to parse. errorSink.Add(sourceUnit, e.Message, SourceSpan.None, 0, Severity.FatalError); return(null); } } }
internal static object[] /*!!*/ ToStaticTypeRefs(List <TypeRef> /*!*/ typeRefs, ErrorSink errors, SourceUnit sourceUnit) { if (typeRefs == null || typeRefs.Count == 0) { return(ArrayUtils.EmptyObjects); } object[] result = new object[typeRefs.Count]; for (int i = 0; i < typeRefs.Count; i++) { if ((result[i] = typeRefs[i].ToStaticTypeRef(errors, sourceUnit)) == null) { if (errors != null) { errors.Add(Errors.GenericParameterMustBeType, sourceUnit, typeRefs[i].Span); } result[i] = new PrimitiveTypeName(QualifiedName.Object); } } return(result); }
internal void ReportSyntaxWarning(string message, Node node) { _errorSink.Add(message, _ast._lineLocations, node.StartIndex, node.EndIndex, ErrorCodes.SyntaxError, Severity.Warning); }
internal static object[]/*!!*/ ToStaticTypeRefs(List<TypeRef>/*!*/ typeRefs, ErrorSink/*!*/ errors, SourceUnit/*!*/ sourceUnit) { if (typeRefs.Count == 0) return ArrayUtils.EmptyObjects; object[] result = new object[typeRefs.Count]; for (int i = 0; i < typeRefs.Count; i++) { result[i] = typeRefs[i].ToStaticTypeRef(errors, sourceUnit); if (result[i] == null) { errors.Add(Errors.GenericParameterMustBeType, sourceUnit, typeRefs[i].Position); result[i] = PrimitiveType.Object; } } return result; }
internal bool Merge(ErrorSink/*!*/ errors, PhpType/*!*/ declaringType, TypeSignature other) { if (typeParams.Count != other.typeParams.Count) { errors.Add(Errors.PartialDeclarationsDifferInTypeParameterCount, declaringType.Declaration.SourceUnit, declaringType.Declaration.Position, declaringType.FullName); return false; } bool result = true; for (int i = 0; i < typeParams.Count; i++) result &= typeParams[i].Merge(errors, other.typeParams[i]); return result; }
//#endregion #region Name Resolving /// <summary> /// Resolves a function or type name using aliases and imported namespaces of the source unit. /// </summary> /// <param name="qualifiedName">Function qualified name to resolve. Doesn't resolve special names ("self", "parent").</param> /// <param name="kind">Declaration kind.</param> /// <param name="currentScope">Current scope.</param> /// <param name="alias"> /// <B>null</B>, if the function name is resolved immediately. /// Otherwise, if the <paramref name="qualifiedName"/> is simple and an alias exists, contains its qualified target. /// </param> /// <param name="errors">Error sink or <B>null</B> if errors shouldn't be reported.</param> /// <param name="position">Position where to report an error.</param> /// <param name="mustResolve">Whether name must be resolved if possible.</param> /// <returns> /// Resolved member, the unknown member, or <B>null</B> if error reporting is disabled (errors == null). /// </returns> /// <remarks> /// If the name is simple, is not resolved and has an alias then the run-time resolve should be run on the alias. /// If the name is simple, is not resolved and hasn't an alias, the run-time resolve should be run on the name /// within the naming context of the source unit (i.e. imported namespaces should be considered). /// If the name is fully qualified and is not resolved then then the run-time resolve should be run on the name itself. /// </remarks> private DMember ResolveName(QualifiedName qualifiedName, DeclarationKind kind, Scope currentScope, out QualifiedName?alias, ErrorSink errors, Position position, bool mustResolve) { string full_name = null; DMember result; alias = null; // try exact match: result = ResolveExactName(qualifiedName, ref full_name, kind, currentScope, mustResolve); if (result != null) { return(result); } /* // aliases are resolved in parse-time * // try explicit aliases: * if (qualifiedName.IsSimpleName) * { * QualifiedName alias_qualified_name; * * Dictionary<Name, QualifiedName> aliases = null; * switch (kind) * { * case DeclarationKind.Type: aliases = typeAliases; break; * case DeclarationKind.Function: aliases = functionAliases; break; * case DeclarationKind.Constant: aliases = constantAliases; break; * } * * // try alias: * if (aliases != null && aliases.TryGetValue(qualifiedName.Name, out alias_qualified_name)) * { * // alias exists // * * full_name = null; * result = ResolveExactName(alias_qualified_name, ref full_name, kind, currentScope, mustResolve); * if (result != null) * return result; * * alias = alias_qualified_name; * * switch (kind) * { * case DeclarationKind.Type: result = new UnknownType(full_name); break; * case DeclarationKind.Function: result = new UnknownFunction(full_name); break; * case DeclarationKind.Constant: result = new UnknownGlobalConstant(full_name); break; * } * * return result; * } * } */ // try imported namespaces: if (!qualifiedName.IsFullyQualifiedName && HasImportedNamespaces) { result = null; foreach (QualifiedName imported_ns in importedNamespaces) { QualifiedName combined_qualified_name = new QualifiedName(qualifiedName, imported_ns); full_name = null; DMember candidate = ResolveExactName(combined_qualified_name, ref full_name, kind, currentScope, mustResolve); if (candidate != null) { if (result != null) { if (errors != null) { ErrorInfo error; switch (kind) { case DeclarationKind.Type: error = Errors.AmbiguousTypeMatch; break; case DeclarationKind.Function: error = Errors.AmbiguousFunctionMatch; break; case DeclarationKind.Constant: error = Errors.AmbiguousConstantMatch; break; default: throw null; } errors.Add(error, this, position, result.FullName, candidate.FullName, qualifiedName.Name); } } else { result = candidate; } } } if (result != null) { return(result); } } // unknown qualified name: if (errors != null) { switch (kind) { case DeclarationKind.Type: result = new UnknownType(qualifiedName.ToString()); break; case DeclarationKind.Function: result = new UnknownFunction(qualifiedName.ToString()); break; case DeclarationKind.Constant: result = new UnknownGlobalConstant(qualifiedName.ToString()); break; } return(result); } return(null); }
internal override void ReportCircularDefinition(ErrorSink/*!*/ errors) { errors.Add(Errors.CircularConstantDefinitionGlobal, SourceUnit, Span, FullName); }
protected override void ReportSyntaxError(string message) { ErrorSink.Add(_sourceUnit, message, TokenSpan, -1, Severity.FatalError); throw new InternalSyntaxError(); }
internal void ReportSyntaxError(ErrorInfo error) { ErrorSink.Add(_sourceUnit, error.GetMessage(), GetTokenSpan(), error.Code, Severity.FatalError); throw new InternalSyntaxError(); }
/// <summary> /// Resolves a function or type name using aliases and imported namespaces of the source unit. /// </summary> /// <param name="qualifiedName">Function qualified name to resolve. Doesn't resolve special names ("self", "parent").</param> /// <param name="kind">Declaration kind.</param> /// <param name="currentScope">Current scope.</param> /// <param name="alias"> /// <B>null</B>, if the function name is resolved immediately. /// Otherwise, if the <paramref name="qualifiedName"/> is simple and an alias exists, contains its qualified target. /// </param> /// <param name="errors">Error sink or <B>null</B> if errors shouldn't be reported.</param> /// <param name="position">Position where to report an error.</param> /// <param name="mustResolve">Whether name must be resolved if possible.</param> /// <returns> /// Resolved member, the unknown member, or <B>null</B> if error reporting is disabled (errors == null). /// </returns> /// <remarks> /// If the name is simple, is not resolved and has an alias then the run-time resolve should be run on the alias. /// If the name is simple, is not resolved and hasn't an alias, the run-time resolve should be run on the name /// within the naming context of the source unit (i.e. imported namespaces should be considered). /// If the name is fully qualified and is not resolved then then the run-time resolve should be run on the name itself. /// </remarks> private DMember ResolveName(QualifiedName qualifiedName, DeclarationKind kind, Scope currentScope, out QualifiedName?alias, ErrorSink errors, Text.Span position, bool mustResolve) { string full_name = null; DMember result; alias = null; // try exact match: result = ResolveExactName(qualifiedName, ref full_name, kind, currentScope, mustResolve); if (result != null) { return(result); } // try imported namespaces: if (!qualifiedName.IsFullyQualifiedName && HasImportedNamespaces) { result = null; foreach (QualifiedName imported_ns in this.ImportedNamespaces) { QualifiedName combined_qualified_name = new QualifiedName(qualifiedName, imported_ns); full_name = null; DMember candidate = ResolveExactName(combined_qualified_name, ref full_name, kind, currentScope, mustResolve); if (candidate != null) { if (result != null) { if (errors != null) { ErrorInfo error; switch (kind) { case DeclarationKind.Type: error = Errors.AmbiguousTypeMatch; break; case DeclarationKind.Function: error = Errors.AmbiguousFunctionMatch; break; case DeclarationKind.Constant: error = Errors.AmbiguousConstantMatch; break; default: throw null; } errors.Add(error, this, position, result.FullName, candidate.FullName, qualifiedName.Name); } } else { result = candidate; } } } if (result != null) { return(result); } } // unknown qualified name: if (errors != null) { switch (kind) { case DeclarationKind.Type: result = new UnknownType(qualifiedName.ToString()); break; case DeclarationKind.Function: result = new UnknownFunction(qualifiedName.ToString()); break; case DeclarationKind.Constant: result = new UnknownGlobalConstant(qualifiedName.ToString()); break; } return(result); } return(null); }
public new Tokens GetNextToken() { for (; ;) { inString = false; isCode = false; Tokens token = base.GetNextToken(); UpdateTokenPosition(); switch (token) { #region Comments // ignored tokens: case Tokens.T_WHITESPACE: break; case Tokens.T_COMMENT: this.commentsSink.OnComment(this, this.tokenPosition); break; case Tokens.T_LINE_COMMENT: this.commentsSink.OnLineComment(this, this.tokenPosition); break; case Tokens.T_OPEN_TAG: this.commentsSink.OnOpenTag(this, this.tokenPosition); break; case Tokens.T_DOC_COMMENT: // remember token value to be used by the next token and skip the current: this.lastDocComment = new PHPDocBlock(base.GetTokenString(), this.tokenPosition); this.commentsSink.OnPhpDocComment(this, this.lastDocComment); break; case Tokens.T_PRAGMA_FILE: sourceUnit.AddSourceFileMapping(tokenPosition.FirstLine, base.GetTokenAsFilePragma()); break; case Tokens.T_PRAGMA_LINE: { int?value = base.GetTokenAsLinePragma(); if (value.HasValue) { sourceUnit.AddSourceLineMapping(tokenPosition.FirstLine, value.Value); } else { errors.Add(Warnings.InvalidLinePragma, sourceUnit, tokenPosition); } break; } case Tokens.T_PRAGMA_DEFAULT_FILE: sourceUnit.AddSourceFileMapping(tokenPosition.FirstLine, SourceUnit.DefaultFile); break; case Tokens.T_PRAGMA_DEFAULT_LINE: sourceUnit.AddSourceLineMapping(tokenPosition.FirstLine, SourceUnit.DefaultLine); break; #endregion #region String Semantics case Tokens.T_VARIABLE: // exclude initial $ from the name: Debug.Assert(GetTokenChar(0) == '$'); tokenSemantics.Object = base.GetTokenSubstring(1); goto default; case Tokens.T_STRING: if (inString) { StoreEncapsedString(); } else { tokenSemantics.Object = base.GetTokenString(); } goto default; case Tokens.T_ARRAY: case Tokens.T_LIST: case Tokens.T_ASSERT: tokenSemantics.Object = base.GetTokenString(); // remember the token string, so we can use these tokens as literals later, case sensitively goto default; case Tokens.T_STRING_VARNAME: case Tokens.T_NUM_STRING: case Tokens.T_ENCAPSED_AND_WHITESPACE: case Tokens.T_BAD_CHARACTER: StoreEncapsedString(); goto default; case Tokens.T_INLINE_HTML: tokenSemantics.Object = base.GetTokenString(); goto default; // \[uU]#{0-6} case Tokens.UnicodeCharCode: { Debug.Assert(inString); //if (GetTokenChar(1) == 'u') //{ // if (TokenLength != 2 + 4) // errors.Add(Warnings.InvalidEscapeSequenceLength, sourceFile, tokenPosition.Short, GetTokenString(), 4); //} //else //{ // if (TokenLength != 2 + 6) // errors.Add(Warnings.InvalidEscapeSequenceLength, sourceFile, tokenPosition.Short, GetTokenString(), 6); //} int code_point = GetTokenAsInteger(2, 16); try { if ((code_point < 0 || code_point > 0x10ffff) || (code_point >= 0xd800 && code_point <= 0xdfff)) { errors.Add(Errors.InvalidCodePoint, SourceUnit, tokenPosition, GetTokenString()); StoreEncapsedString("?"); } else { StoreEncapsedString(StringUtils.Utf32ToString(code_point)); } } catch (ArgumentOutOfRangeException) { errors.Add(Errors.InvalidCodePoint, SourceUnit, tokenPosition, GetTokenString()); StoreEncapsedString("?"); } token = Tokens.T_STRING; goto default; } // \C{name} case Tokens.UnicodeCharName: Debug.Assert(inString); StoreEncapsedString(); // N/S token = Tokens.T_STRING; goto default; // b?"xxx" case Tokens.DoubleQuotedString: { bool forceBinaryString = GetTokenChar(0) == 'b'; tokenSemantics.Object = GetTokenAsDoublyQuotedString(forceBinaryString ? 1 : 0, encoding, forceBinaryString); token = Tokens.T_CONSTANT_ENCAPSED_STRING; goto default; } // b?'xxx' case Tokens.SingleQuotedString: { bool forceBinaryString = GetTokenChar(0) == 'b'; tokenSemantics.Object = GetTokenAsSinglyQuotedString(forceBinaryString ? 1 : 0, encoding, forceBinaryString); token = Tokens.T_CONSTANT_ENCAPSED_STRING; goto default; } #endregion #region Numeric Semantics case Tokens.T_CURLY_OPEN: tokenSemantics.Integer = (int)Tokens.T_CURLY_OPEN; goto default; case Tokens.T_CHARACTER: tokenSemantics.Integer = (int)GetTokenChar(0); goto default; case Tokens.EscapedCharacter: tokenSemantics.Integer = (int)GetTokenAsEscapedCharacter(0); token = Tokens.T_CHARACTER; goto default; case Tokens.T_LINE: // TODO: tokenSemantics.Integer = 1; goto default; // "\###" case Tokens.OctalCharCode: tokenSemantics.Integer = GetTokenAsInteger(1, 10); token = Tokens.T_CHARACTER; goto default; // "\x##" case Tokens.HexCharCode: tokenSemantics.Integer = GetTokenAsInteger(2, 16); token = Tokens.T_CHARACTER; goto default; // {LNUM} case Tokens.ParseDecimalNumber: { // [0-9]* - value is either in octal or in decimal if (GetTokenChar(0) == '0') { token = GetTokenAsDecimalNumber(1, 8, ref tokenSemantics); } else { token = GetTokenAsDecimalNumber(0, 10, ref tokenSemantics); } if (token == Tokens.T_DNUMBER) { // conversion to double causes data loss errors.Add(Warnings.TooBigIntegerConversion, SourceUnit, tokenPosition, GetTokenString()); } goto default; } // {HNUM} case Tokens.ParseHexadecimalNumber: { // parse hexadecimal value token = GetTokenAsDecimalNumber(2, 16, ref tokenSemantics); if (token == Tokens.T_DNUMBER) { // conversion to double causes data loss errors.Add(Warnings.TooBigIntegerConversion, SourceUnit, tokenPosition, GetTokenString()); } goto default; } // {BNUM} case Tokens.ParseBinaryNumber: // parse binary number value token = GetTokenAsDecimalNumber(2, 2, ref tokenSemantics); if (token == Tokens.T_DNUMBER) { // conversion to double causes data loss errors.Add(Warnings.TooBigIntegerConversion, SourceUnit, tokenPosition, GetTokenString()); } goto default; // {DNUM}|{EXPONENT_DNUM} case Tokens.ParseDouble: tokenSemantics.Double = GetTokenAsDouble(0); token = Tokens.T_DNUMBER; goto default; #endregion #region Another Semantics // i'xxx' case Tokens.SingleQuotedIdentifier: tokenSemantics.Object = (string)GetTokenAsSinglyQuotedString(1, encoding, false); token = Tokens.T_STRING; goto default; #endregion #region Token Reinterpreting case Tokens.T_OPEN_TAG_WITH_ECHO: this.commentsSink.OnOpenTag(this, this.tokenPosition); token = Tokens.T_ECHO; goto default; case Tokens.T_CLOSE_TAG: this.commentsSink.OnCloseTag(this, this.tokenPosition); token = Tokens.T_SEMI; goto case Tokens.T_SEMI; case Tokens.T_TRUE: case Tokens.T_FALSE: case Tokens.T_NULL: case Tokens.T_GET: case Tokens.T_SET: case Tokens.T_CALL: case Tokens.T_CALLSTATIC: case Tokens.T_WAKEUP: case Tokens.T_SLEEP: case Tokens.T_TOSTRING: case Tokens.T_CONSTRUCT: case Tokens.T_DESTRUCT: case Tokens.T_PARENT: case Tokens.T_SELF: case Tokens.T_AUTOLOAD: token = Tokens.T_STRING; goto case Tokens.T_STRING; case Tokens.T_TRY: case Tokens.T_CATCH: case Tokens.T_FINALLY: case Tokens.T_THROW: case Tokens.T_IMPLEMENTS: case Tokens.T_CLONE: case Tokens.T_ABSTRACT: case Tokens.T_FINAL: case Tokens.T_PRIVATE: case Tokens.T_PROTECTED: case Tokens.T_PUBLIC: case Tokens.T_INSTANCEOF: case Tokens.T_INTERFACE: case Tokens.T_GOTO: case Tokens.T_NAMESPACE: case Tokens.T_NAMESPACE_C: case Tokens.T_NS_SEPARATOR: case Tokens.T_USE: { if ((features & LanguageFeatures.V5Keywords) == 0) { token = Tokens.T_STRING; goto case Tokens.T_STRING; } if (token == Tokens.T_ABSTRACT) { // remember this for possible CLR qualified name: tokenSemantics.Object = base.GetTokenString(); } goto default; } case Tokens.T_LINQ_FROM: case Tokens.T_LINQ_SELECT: case Tokens.T_LINQ_BY: case Tokens.T_LINQ_WHERE: case Tokens.T_LINQ_DESCENDING: case Tokens.T_LINQ_ASCENDING: case Tokens.T_LINQ_ORDERBY: case Tokens.T_LINQ_GROUP: case Tokens.T_LINQ_IN: { if ((features & LanguageFeatures.Linq) == 0) { token = Tokens.T_STRING; goto case Tokens.T_STRING; } goto default; } case Tokens.T_IMPORT: { if (!sourceUnit.CompilationUnit.IsPure) { token = Tokens.T_STRING; goto case Tokens.T_STRING; } goto default; } case Tokens.T_BOOL_TYPE: case Tokens.T_INT_TYPE: case Tokens.T_INT64_TYPE: case Tokens.T_DOUBLE_TYPE: case Tokens.T_STRING_TYPE: case Tokens.T_RESOURCE_TYPE: case Tokens.T_OBJECT_TYPE: case Tokens.T_TYPEOF: { if ((features & LanguageFeatures.TypeKeywords) == 0) { token = Tokens.T_STRING; goto case Tokens.T_STRING; } tokenSemantics.Object = base.GetTokenString(); goto default; } case Tokens.T_PARTIAL: { if (!pure) { token = Tokens.T_STRING; goto case Tokens.T_STRING; } goto default; } #endregion #region Error Tokens case Tokens.ERROR: goto default; case Tokens.ErrorInvalidIdentifier: { // invalid identifier i'XXX': errors.Add(Errors.InvalidIdentifier, SourceUnit, tokenPosition, (string)GetTokenAsSinglyQuotedString(1, encoding, false)); tokenSemantics.Object = GetErrorIdentifier(); token = Tokens.T_STRING; goto default; } case Tokens.ErrorNotSupported: errors.Add(Errors.ConstructNotSupported, SourceUnit, tokenPosition, GetTokenString()); tokenSemantics.Object = GetErrorIdentifier(); token = Tokens.T_STRING; goto default; #endregion case Tokens.T_SEMI: default: if (lastDocComment != null) { // remember PHPDoc for current token if (lastDocCommentRememberTokens.Contains(token)) { tokenSemantics.Object = this.lastDocComment; } // forget last doc comment text if (!lastDocCommentKeepTokens.Contains(token)) { lastDocComment = null; } } return(token); } } }
internal override void ReportCircularDefinition(ErrorSink /*!*/ errors) { errors.Add(Errors.CircularConstantDefinitionGlobal, SourceUnit, Span, FullName); }
public void ReportRedeclaration(ErrorSink /*!*/ errors) { errors.Add(FatalErrors.ConstantRedeclared, SourceUnit, Span, FullName); }
private void TryFixPartial(ErrorSink/*!*/ errors, Declaration/*!*/ first, Declaration/*!*/ second) { if (!first.IsPartial && !first.IsConditional) { // report error and mark the declaration partial: errors.Add(Errors.MissingPartialModifier, first.SourceUnit, first.Position, first.Declaree.FullName); errors.Add(Errors.RelatedLocation, second.SourceUnit, second.Position); first.IsPartial = true; } }
protected bool CheckDeclaration(ErrorSink/*!*/ errors, IDeclaree/*!*/ member, Declaration/*!*/ existing) { Declaration current = member.Declaration; if (existing.IsPartial ^ current.IsPartial) { TryFixPartial(errors, current, existing); TryFixPartial(errors, existing, current); } if ((!existing.IsPartial || !current.IsPartial) && (!existing.IsConditional || !current.IsConditional)) { // report fatal error (do not throw an exception, just don't let the analysis continue): member.ReportRedeclaration(errors); errors.Add(FatalErrors.RelatedLocation, existing.SourceUnit, existing.Position); return false; } return true; }
private void ReportSyntaxError(string message) { ErrorSink.Add(_sourceUnit, message, GetTokenSpan(), -1, Severity.FatalError); throw new InternalSyntaxError(); }
internal static object[]/*!!*/ ToStaticTypeRefs(List<TypeRef>/*!*/ typeRefs, ErrorSink errors, SourceUnit sourceUnit) { if (typeRefs == null || typeRefs.Count == 0) return ArrayUtils.EmptyObjects; object[] result = new object[typeRefs.Count]; for (int i = 0; i < typeRefs.Count; i++) { if ((result[i] = typeRefs[i].ToStaticTypeRef(errors, sourceUnit)) == null) { if (errors != null) errors.Add(Errors.GenericParameterMustBeType, sourceUnit, typeRefs[i].Span); result[i] = new PrimitiveTypeName(QualifiedName.Object); } } return result; }
public void ReportRedeclaration(ErrorSink/*!*/ errors) { errors.Add(FatalErrors.ConstantRedeclared, SourceUnit, Span, FullName); }
internal override void ReportCircularDefinition(ErrorSink /*!*/ errors) { errors.Add(Errors.CircularConstantDefinitionClass, SourceUnit, Span, DeclaringType.FullName, FullName); }
private ForeachStmt /*!*/ CreateForeachStmt(Position pos, Expression /*!*/ enumeree, ForeachVar /*!*/ var1, Position pos1, ForeachVar var2, Statement /*!*/ body) { ForeachVar key, value; if (var2 != null) { key = var1; value = var2; if (key.Alias) { errors.Add(Errors.KeyAlias, SourceUnit, pos1); key.Alias = false; } } else { key = null; value = var1; } return(new ForeachStmt(pos, enumeree, key, value, body)); }
internal override void ReportCircularDefinition(ErrorSink/*!*/ errors) { errors.Add(Errors.CircularConstantDefinitionClass, SourceUnit, Span, DeclaringType.FullName, FullName); }