001 /* Copyright (c) 2005-2008, Torbjorn Ekman 002 * All rights reserved. 003 * 004 * Redistribution and use in source and binary forms, with or without 005 * modification, are permitted provided that the following conditions are met: 006 * 007 * 1. Redistributions of source code must retain the above copyright notice, 008 * this list of conditions and the following disclaimer. 009 * 010 * 2. Redistributions in binary form must reproduce the above copyright notice, 011 * this list of conditions and the following disclaimer in the documentation 012 * and/or other materials provided with the distribution. 013 * 014 * 3. Neither the name of the copyright holder nor the names of its 015 * contributors may be used to endorse or promote products derived from this 016 * software without specific prior written permission. 017 * 018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 021 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 022 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 028 * POSSIBILITY OF SUCH DAMAGE. 029 */ 030 031 aspect PrimitiveTypes { 032 protected static final String ASTNode.PRIMITIVE_PACKAGE_NAME = "@primitive"; 033 034 syn nta TypeDecl PrimitiveCompilationUnit.typeBoolean() { 035 BooleanType type = new BooleanType(); 036 type.setModifiers(new Modifiers(new List().add(new Modifier("public")))); 037 type.setID("boolean"); 038 type.setSuperClass(unknownType().createQualifiedAccess()); 039 return type; 040 } 041 syn nta TypeDecl PrimitiveCompilationUnit.typeByte() { 042 ByteType type = new ByteType(); 043 type.setModifiers(new Modifiers(new List().add(new Modifier("public")))); 044 type.setID("byte"); 045 type.setSuperClass(typeShort().createQualifiedAccess()); 046 return type; 047 } 048 syn nta TypeDecl PrimitiveCompilationUnit.typeShort() { 049 ShortType type = new ShortType(); 050 type.setModifiers(new Modifiers(new List().add(new Modifier("public")))); 051 type.setID("short"); 052 type.setSuperClass(typeInt().createQualifiedAccess()); 053 return type; 054 } 055 syn nta TypeDecl PrimitiveCompilationUnit.typeChar() { 056 CharType type = new CharType(); 057 type.setModifiers(new Modifiers(new List().add(new Modifier("public")))); 058 type.setID("char"); 059 type.setSuperClass(typeInt().createQualifiedAccess()); 060 return type; 061 } 062 syn nta TypeDecl PrimitiveCompilationUnit.typeInt() { 063 IntType type = new IntType(); 064 type.setModifiers(new Modifiers(new List().add(new Modifier("public")))); 065 type.setID("int"); 066 type.setSuperClass(typeLong().createQualifiedAccess()); 067 return type; 068 } 069 syn nta TypeDecl PrimitiveCompilationUnit.typeLong() { 070 LongType type = new LongType(); 071 type.setModifiers(new Modifiers(new List().add(new Modifier("public")))); 072 type.setID("long"); 073 // Float doesn't seem right here, keeping it because the old code does this 074 type.setSuperClass(typeFloat().createQualifiedAccess()); 075 return type; 076 } 077 syn nta TypeDecl PrimitiveCompilationUnit.typeFloat() { 078 FloatType type = new FloatType(); 079 type.setModifiers(new Modifiers(new List().add(new Modifier("public")))); 080 type.setID("float"); 081 type.setSuperClass(typeDouble().createQualifiedAccess()); 082 return type; 083 } 084 syn nta TypeDecl PrimitiveCompilationUnit.typeDouble() { 085 DoubleType type = new DoubleType(); 086 type.setModifiers(new Modifiers(new List().add(new Modifier("public")))); 087 type.setID("double"); 088 type.setSuperClass(unknownType().createQualifiedAccess()); 089 return type; 090 } 091 syn nta TypeDecl PrimitiveCompilationUnit.typeVoid() { 092 VoidType classDecl = new VoidType(); 093 classDecl.setModifiers(new Modifiers(new List().add(new Modifier("public")))); 094 classDecl.setID("void"); 095 return classDecl; 096 } 097 syn nta TypeDecl PrimitiveCompilationUnit.typeNull() { 098 NullType classDecl = new NullType(); 099 classDecl.setModifiers(new Modifiers(new List().add(new Modifier("public")))); 100 classDecl.setID("null"); 101 return classDecl; 102 } 103 syn nta TypeDecl PrimitiveCompilationUnit.unknownType() { 104 ClassDecl classDecl = new UnknownType(); 105 classDecl.setModifiers(new Modifiers(new List().add(new Modifier("public")))); 106 classDecl.setID("Unknown"); 107 MethodDecl methodDecl = new MethodDecl( 108 new Modifiers(new List().add( 109 new Modifier("public") 110 )), 111 new PrimitiveTypeAccess("Unknown"), 112 "unknown", 113 new List(), 114 new List(), 115 new Opt() 116 ); 117 classDecl.addBodyDecl(methodDecl); 118 FieldDeclaration fieldDecl = new FieldDeclaration( 119 new Modifiers(new List().add( 120 new Modifier("public") 121 )), 122 new PrimitiveTypeAccess("Unknown"), 123 "unknown", 124 new Opt() 125 ); 126 classDecl.addBodyDecl(fieldDecl); 127 ConstructorDecl constrDecl = new ConstructorDecl( 128 new Modifiers(new List().add(new Modifier("public"))), 129 "Unknown", 130 new List(), 131 new List(), 132 new Opt(), 133 new Block() 134 ); 135 classDecl.addBodyDecl(constrDecl); 136 return classDecl; 137 } 138 139 /** Creates a compilation unit with primitive types. */ 140 syn nta PrimitiveCompilationUnit Program.getPrimitiveCompilationUnit() { 141 PrimitiveCompilationUnit u = new PrimitiveCompilationUnit(); 142 u.setPackageDecl(PRIMITIVE_PACKAGE_NAME); 143 return u; 144 } 145 146 } 147