/// <summary>
        /// Generates .NET code a constant field decl.
        /// </summary>
        /// <param name="context">Const decl AST.</param>
        /// <returns></returns>
        public override CodeGeneratorBase VisitConstStmt(VisualBasic6Parser.ConstStmtContext context)
        {
            List <SyntaxToken> modifiers = new List <SyntaxToken>();

            VisualBasic6Parser.PublicPrivateGlobalVisibilityContext vis = context.publicPrivateGlobalVisibility();

            if (vis != null)
            {
                if (vis.PUBLIC() != null || vis.GLOBAL() != null)
                {
                    modifiers.Add(SyntaxFactory.Token(SyntaxKind.PublicKeyword));
                }
                else if (vis.PRIVATE() != null)
                {
                    modifiers.Add(SyntaxFactory.Token(SyntaxKind.PrivateKeyword));
                }
            }

            modifiers.Add(SyntaxFactory.Token(SyntaxKind.ConstKeyword));

            foreach (VisualBasic6Parser.ConstSubStmtContext subStmt in context.constSubStmt())
            {
                SimpleAsClauseSyntax asClause = null;

                if (subStmt.asTypeClause() != null)
                {
                    asClause = SyntaxFactory.SimpleAsClause(SyntaxFactory.ParseTypeName(subStmt.asTypeClause().type().GetText()));
                }

                ModifiedIdentifierSyntax identifier  = SyntaxFactory.ModifiedIdentifier(subStmt.ambiguousIdentifier().GetText());
                ExpressionSyntax         initialiser = null;

                string initialiserExpr = subStmt.valueStmt().GetText();

                //ParseExpression can't handle date/time literals - Roslyn bug? - //so handle them manually here
                if (initialiserExpr.StartsWith("#"))
                {
                    string   trimmedInitialiser = initialiserExpr.Trim(new char[] { '#' });
                    DateTime parsedVal          = new DateTime();

                    if (trimmedInitialiser.Contains("AM") || trimmedInitialiser.Contains("PM"))
                    {
                        parsedVal = DateTime.ParseExact(trimmedInitialiser, "M/d/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        parsedVal = DateTime.ParseExact(trimmedInitialiser, "M/d/yyyy", CultureInfo.InvariantCulture);
                    }

                    initialiser = SyntaxFactory.DateLiteralExpression(SyntaxFactory.DateLiteralToken(initialiserExpr, parsedVal));
                }
                else
                {
                    initialiser = SyntaxFactory.ParseExpression(initialiserExpr);
                }

                VariableDeclaratorSyntax varDecl = SyntaxFactory.VariableDeclarator(identifier).WithInitializer(SyntaxFactory.EqualsValue(initialiser));

                if (asClause != null)
                {
                    varDecl = varDecl.WithAsClause(asClause);
                }

                mMainDeclMembers.Add(SyntaxFactory.FieldDeclaration(varDecl).WithModifiers(SyntaxFactory.TokenList(modifiers)));
            }

            return(base.VisitConstStmt(context));
        }
Esempio n. 2
0
 public override object VisitConstStmt([NotNull] VisualBasic6Parser.ConstStmtContext context)
 {
     CreateModel(context);
     return(null);
 }
Esempio n. 3
0
 public override void ExitConstStmt([NotNull] VisualBasic6Parser.ConstStmtContext context)
 {
 }