public void AddField(FieldDef field) { fields.Add(field); }
private void ParseField() { #region Old //bool b = Expect(Token.LeftSquareBracket); //TokenInfo token = Tokenizer.PeekToken(); //if (token.Is(Token.Identifier) || token.Is(Token.ReservedWord)) //{ //} //if (Expect(Token.As)) //{ // token = Tokenizer.PeekToken(); // if (Expect(Token.Identifier)) // { // } // else // { // } //} //else //{ //} //if (Expect(Token.Equality)) //{ // token = Tokenizer.PeekToken(); // if (Expect(Token.Identifier)) // { // } // else // { // } //} //else //{ //} #endregion TokenInfo token; Modifier modifiers; SimpleName name; FullNamedExpression type; Expression expr; modifiers = ParseMethodModifiers(); token = tokenQueue.Dequeue(); name = null; type = null; expr = null; if (token.Is(Token.Identifier)) { name = new SimpleName(statement, token.Value, new SourceData(token.GetSpan(token), SourceFile, statementSymbols)); if (EatOptional(Token.As)) { type = ParseFullName(); } TokenInfo token3 = Tokenizer.PeekToken(); if (EatOptional(Token.Equality)) { EatOptional(Token.EOL); //Set parse context to initializer MethodDef initializer; if ((modifiers & Modifier.Shared) == Modifier.Shared) { initializer = (MethodDef) this.type.GetTypeInitializer(); } else { initializer = (MethodDef) this.type.GetDefaultConstructor(); } //Initalize context method = initializer; block = method.Body; var assignStmt = new ExpressionStatement(initializer.Body); statement = assignStmt; //Parse initialization expression expr = ParseExpression(); //Build initialization expression statement assignStmt.SetExpression( new BinaryExpression(assignStmt, Operator.Assign, new VariableAccess(assignStmt, new SimpleName(assignStmt, name, null), null), expr, null)); //Add statement initializer.Body.AddStatement(assignStmt); //Reset context to null method = null; block = null; statement = null; if (expr == null) { Report.AddItem(VBErrors.ExpressionExpected, SourceFile, token3.GetSpan(token3), statementSymbols); } } TokenInfo token4 = Tokenizer.PeekToken(); if (token4.Is(Token.EOL)) { //GetNextToken(); //* resetStmtTokens(); } else { ExpectEndOfStatementOrEat(); } } else { GetNextToken(); TokenInfo token2 = Tokenizer.PeekToken(); Report.AddItem(VBErrors.IdentifierExpected, SourceFile, new SourceSpan(token.GetSourceLocation(), token2.GetSourceLocation()), statementSymbols); EatToEOL(); } var fieldDef = new FieldDef(this.type, name, type, modifiers); fieldDef.SetInitalizationExpression(expr); ((ClassStructOrModuleDef) this.type).AddField(fieldDef); }