예제 #1
0
        public void AddVariableDeclaration(string name, string typeName)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("A variable name expected.");
            }
            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentException($"A type name for the '{name}' variable expected.");
            }

            if (VariableDeclarations.ContainsKey(name))
            {
                throw new CompilerException($"The '{name}' variable is already declared as the {VariableDeclarations[name].TypeName} type.");
            }

            switch (typeName)
            {
            case "INTEGER": VariableDeclarations.Add(name, VariableDeclaration.CreateIntegerVariableDeclaration(name)); break;

            case "REAL": VariableDeclarations.Add(name, VariableDeclaration.CreateRealVariableDeclaration(name)); break;

            case "CHAR": VariableDeclarations.Add(name, VariableDeclaration.CreateCharVariableDeclaration(name)); break;

            case "BOOLEAN": VariableDeclarations.Add(name, VariableDeclaration.CreateBooleanVariableDeclaration(name)); break;

            case "STRING": VariableDeclarations.Add(name, VariableDeclaration.CreateStringVariableDeclaration(name)); break;

            default:
                throw new CompilerException($"Unknown type '{typeName}' used for the '{name}' variable declaration.");
            }
        }
예제 #2
0
        protected override void PopulateStatement(TextWriter trapFile)
        {
            int child = -1;

            if (Stmt.Declaration != null)
            {
                VariableDeclarations.Populate(cx, Stmt.Declaration, this, child, childIncrement: -1);
            }

            foreach (var init in Stmt.Initializers)
            {
                Expression.Create(cx, init, this, child--);
            }

            if (Stmt.Condition != null)
            {
                Expression.Create(cx, Stmt.Condition, this, 0);
            }

            child = 1;
            foreach (var inc in Stmt.Incrementors)
            {
                Expression.Create(cx, inc, this, child++);
            }

            Statement.Create(cx, Stmt.Statement, this, 1 + Stmt.Incrementors.Count);
        }
예제 #3
0
        public bool IsVariableDeclared(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("A variable name expected.");
            }

            return(VariableDeclarations.ContainsKey(name));
        }
예제 #4
0
        public BlockSyntax GenerateJSImportBody()
        {
            StatementSyntax       invoke      = InvokeSyntax();
            JSGeneratedStatements statements  = JSGeneratedStatements.Create(_marshallers, _context, invoke);
            bool shouldInitializeVariables    = !statements.GuaranteedUnmarshal.IsEmpty || !statements.Cleanup.IsEmpty;
            VariableDeclarations declarations = VariableDeclarations.GenerateDeclarationsForManagedToNative(_marshallers, _context, shouldInitializeVariables);

            var setupStatements = new List <StatementSyntax>();

            BindSyntax(setupStatements);
            SetupSyntax(setupStatements);

            if (!statements.GuaranteedUnmarshal.IsEmpty)
            {
                setupStatements.Add(MarshallerHelpers.Declare(PredefinedType(Token(SyntaxKind.BoolKeyword)), InvokeSucceededIdentifier, initializeToDefault: true));
            }

            setupStatements.AddRange(declarations.Initializations);
            setupStatements.AddRange(declarations.Variables);
            setupStatements.AddRange(statements.Setup);

            var tryStatements = new List <StatementSyntax>();

            tryStatements.AddRange(statements.Marshal);

            tryStatements.AddRange(statements.InvokeStatements);
            if (!statements.GuaranteedUnmarshal.IsEmpty)
            {
                tryStatements.Add(ExpressionStatement(AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
                                                                           IdentifierName(InvokeSucceededIdentifier),
                                                                           LiteralExpression(SyntaxKind.TrueLiteralExpression))));
            }

            tryStatements.AddRange(statements.NotifyForSuccessfulInvoke);
            tryStatements.AddRange(statements.Unmarshal);

            List <StatementSyntax> allStatements     = setupStatements;
            List <StatementSyntax> finallyStatements = new List <StatementSyntax>();

            if (!statements.GuaranteedUnmarshal.IsEmpty)
            {
                finallyStatements.Add(IfStatement(IdentifierName(InvokeSucceededIdentifier), Block(statements.GuaranteedUnmarshal)));
            }

            finallyStatements.AddRange(statements.Cleanup);
            if (finallyStatements.Count > 0)
            {
                // Add try-finally block if there are any statements in the finally block
                allStatements.Add(
                    TryStatement(Block(tryStatements), default, FinallyClause(Block(finallyStatements))));
예제 #5
0
        protected override void PopulateStatement(TextWriter trapFile)
        {
            if (Stmt.Declaration != null)
            {
                VariableDeclarations.Populate(cx, Stmt.Declaration, this, -1, childIncrement: -1);
            }

            if (Stmt.Expression != null)
            {
                Expression.Create(cx, Stmt.Expression, this, 0);
            }

            if (Stmt.Statement != null)
            {
                Statement.Create(cx, Stmt.Statement, this, 1);
            }
        }
예제 #6
0
 protected override void Populate()
 {
     VariableDeclarations.Populate(cx, Stmt.Declaration, this, -1, childIncrement: -1);
     Create(cx, Stmt.Statement, this, 0);
 }
예제 #7
0
 protected override void Populate()
 {
     VariableDeclarations.Populate(cx, Stmt.Declaration, this, 0);
     cx.BindComments(this, Stmt.GetLocation());
 }
예제 #8
0
        public override VariableDeclaration GlobalVariableSearch(string name)
        {
            var declaration = VariableDeclarations.FindByKey(name);

            return(declaration ?? ParentScope?.GlobalVariableSearch(name));
        }
예제 #9
0
 protected override void PopulateStatement(TextWriter trapFile)
 {
     VariableDeclarations.Populate(Context, Stmt.Declaration, this, 0);
     Context.BindComments(this, Stmt.GetLocation());
 }
예제 #10
0
 protected override void PopulateStatement(TextWriter trapFile)
 {
     VariableDeclarations.Populate(Context, Stmt.Declaration, this, -1, childIncrement: -1);
     Create(Context, Stmt.Statement, this, 0);
 }
예제 #11
0
        public void AddTag(string tag, FlowGraph graph)
        {
            VariableDeclarations variableDeclarations = Variables.Graph(graph);

            tags.Add(tag, variableDeclarations);
        }
예제 #12
0
 public void AddVar(VariableDeclarationBase variable)
 {
     VariableDeclarations.Add(variable);
 }