Beispiel #1
0
 public AstClassField(
     AstVisibilityModifier visibility,
     AstStaticModifier staticMod,
     AstIdExpression typeDef,
     AstIdExpression name
 )
 {
     Visibility = visibility;
     Static = staticMod;
     TypeDef = typeDef;
     Name = name;
 }
Beispiel #2
0
 public AstClassMethod(
     AstVisibilityModifier visibility,
     AstStaticModifier staticMod,
     AstIdExpression typeDef,
     AstIdExpression name,
     AstArgumentsDefList argumentsDefinition,
     AstStatementsBlock statementsBlock
 )
 {
     Visibility = visibility;
     Static = staticMod;
     TypeDef = typeDef;
     Name = name;
     ArgumentsDefinition = argumentsDefinition;
     StatementsBlock = statementsBlock;
 }
Beispiel #3
0
 public AstAssignStatement(AstIdExpression var, AstExpression newValue)
 {
     Variable = var;
     NewValue = newValue;
 }
Beispiel #4
0
 public AstClass(AstIdExpression name, AstClassBody body)
 {
     Name = name;
     Body = body;
 }
        public override bool Visit(AstIdExpression node)
        {
            if (currStateInsideExpr)
            {
                var s = table.Lookup(node.Id);
                if (s != null)
                {
                    s.Used = true;
                }
                else
                {
                    s = table.LookupFunction(node.Id);
                    if (s != null)
                    {
                        s.Used = true;
                    }
                }
            }

            return true;
        }
Beispiel #6
0
 public AstArrayInitializerStatement(AstIdExpression id, List<AstIntegerValueExpression> values)
 {
     Id = id;
     Values = values;
 }
Beispiel #7
0
 // #TYPE_DEFINITION INT
 private void ConstructIntTypeDefinition()
 {
     var typeDef = new AstIdExpression(BuiltInTypes.INT);
     PushNode(typeDef);
 }
 public override bool Visit(AstIdExpression node)
 {
     return true;
 }
Beispiel #9
0
 // #TYPE_DEFINITION CHAR
 private void ConstructCharTypeDefinition()
 {
     var typeDef = new AstIdExpression(BuiltInTypes.CHAR);
     PushNode(typeDef);
 }
Beispiel #10
0
 public void AddAstIdNode(Token t)
 {
     var node = new AstIdExpression(t.Attribute);
     PushNode(node);
 }
Beispiel #11
0
 // #TYPE_DEFINITION BOOL
 private void ConstructBoolTypeDefinition()
 {
     var typeDef = new AstIdExpression(BuiltInTypes.BOOL);
     PushNode(typeDef);
 }
 private string GetDefaultTypeValue(AstIdExpression node)
 {
     switch (node.Id)
     {
         case BuiltInTypes.INT:
             return "0";
         case BuiltInTypes.BOOL:
             return "0";
         case BuiltInTypes.VOID:
             return "";
         case BuiltInTypes.STRING:
             return "null";
         default:
             throw new NotImplementedException();
     }
 }
        public override bool Visit(AstIdExpression node)
        {
            var symbolTableVariable = table.Lookup(node.Id);
            var type = symbolTableVariable.Type;
            var llvmType = GetLLVMType(symbolTableVariable.Type);
            if (classVariables.Contains(node.Id))
            {
                codeStream.WriteLine(CreateUnnamedVariable() + " = load " + llvmType + "* @" + node.Id);
                if (IsNegative)
                {
                    string positiveVar = GetCurrUnnamedVariable();
                    codeStream.WriteLine(CreateUnnamedVariable() + " = sub " + llvmType + " 0, " + positiveVar);
                }
                if (IsNot)
                {
                    string inverseVal = GetCurrUnnamedVariable();
                    codeStream.WriteLine(CreateUnnamedVariable() + " = xor " + llvmType + " " + inverseVal + ", 1");
                }
            }
            else if (type == BuiltInTypes.STRING)
            {
                codeStream.WriteLine(CreateUnnamedVariable() + " = alloca i8*");
                var id = GetCurrUnnamedVariable();
                codeStream.WriteLine("store i8* %" + GetCurrVariableState(node.Id) + ", i8** " + GetCurrUnnamedVariable());
                codeStream.WriteLine(CreateUnnamedVariable() + " = load i8** " + id);
            }
            else
            {
                if (IsNot)
                {
                    codeStream.WriteLine(CreateUnnamedVariable() + " = xor " + llvmType + " %" + GetCurrVariableState(node.Id) + ", 0");
                }
                else
                {
                    string saveOperation = "add ";
                    if (IsNegative)
                    {
                        saveOperation = "sub ";
                    }
                    codeStream.WriteLine(CreateUnnamedVariable() + " = " + saveOperation + llvmType + " 0, %" + GetCurrVariableState(node.Id));
                }
            }

            SaveArg(llvmType + " " + GetCurrUnnamedVariable());

            return true;
        }
Beispiel #14
0
 public AstExternalMethodCallExpression(AstIdExpression target, AstIdExpression name, AstArgumentsCallList callArgs)
 {
     Target = target;
     Name = name;
     CallArgs = callArgs;
 }
Beispiel #15
0
 // #TYPE_DEFINITION STRING
 private void ConstructStringTypeDefinition()
 {
     var typeDef = new AstIdExpression(BuiltInTypes.STRING);
     PushNode(typeDef);
 }
Beispiel #16
0
 public AstArgumentDef(AstIdExpression typeDef, AstIdExpression name)
 {
     TypeDef = typeDef;
     Name = name;
 }
Beispiel #17
0
 public AstThisMethodCallExpression(AstIdExpression name, AstArgumentsCallList callArgs)
 {
     Name = name;
     CallArgs = callArgs;
 }
 public override bool Visit(AstIdExpression node)
 {
     ErrorIfIsNull(node.Id);
     return true;
 }
 public abstract bool Visit(AstIdExpression node);