1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 22:22:11 +02:00

[272745] initial commit of XLC parser extensions

This commit is contained in:
Mike Kucera 2009-04-17 18:52:09 +00:00
parent e8477ef98a
commit cb8fe367dd
41 changed files with 11695 additions and 0 deletions

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="parser"/>
<classpathentry kind="src" path="ui"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.core.lrparser.xlc</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,8 @@
#Mon Mar 30 15:50:28 EDT 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5

View file

@ -0,0 +1,22 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Xlc
Bundle-SymbolicName: org.eclipse.cdt.core.lrparser.xlc;singleton:=true
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.cdt.core;bundle-version="5.1.0",
org.eclipse.cdt.core.lrparser;bundle-version="5.1.0",
org.eclipse.core.runtime;bundle-version="3.5.0",
org.eclipse.core.resources;bundle-version="3.5.0",
org.eclipse.cdt.ui;bundle-version="5.1.0",
org.eclipse.ui;bundle-version="3.5.0"
Export-Package: org.eclipse.cdt.core.lrparser.xlc,
org.eclipse.cdt.core.lrparser.xlc.action,
org.eclipse.cdt.core.lrparser.xlc.activator,
org.eclipse.cdt.core.lrparser.xlc.ast,
org.eclipse.cdt.core.lrparser.xlc.preferences,
org.eclipse.cdt.internal.core.lrparser.xlc.ast,
org.eclipse.cdt.internal.core.lrparser.xlc.c,
org.eclipse.cdt.internal.core.lrparser.xlc.cpp
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.eclipse.cdt.core.lrparser.xlc.activator.XlcParserPlugin

View file

@ -0,0 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>April 17, 2009</p>
<h3>License</h3>
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, "Program" will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
being redistributed by another party ("Redistributor") and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
</body></html>

View file

@ -0,0 +1,16 @@
###############################################################################
# Copyright (c) 2009 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
source.. = parser/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,49 @@
<!--
Copyright (c) 2009 IBM Corporation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
IBM Corporation - initial API and implementation
-->
<project name="XLC Parsers" default="c" basedir=".">
<import file="../../org.eclipse.cdt.core.lrparser/grammar/generate.xml"/>
<property name="c_location" value="../parser/org/eclipse/cdt/internal/core/lrparser/xlc/c"/>
<property name="cpp_location" value="../parser/org/eclipse/cdt/internal/core/lrparser/xlc/cpp"/>
<target name="c">
<antcall target="generate_c">
<param name="grammar_name" value="XlcCParser"/>
</antcall>
</target>
<target name="cpp">
<antcall target="generate_cpp">
<param name="grammar_name" value="XlcCPPParser"/>
</antcall>
</target>
<target name="generate_c">
<antcall target="generate">
<param name="grammar_dir" value="xlc"/>
<param name="output_dir" value="${c_location}"/>
<param name="grammar_name" value="${grammar_name}"/>
</antcall>
</target>
<target name="generate_cpp">
<antcall target="generate">
<param name="grammar_dir" value="xlc"/>
<param name="output_dir" value="${cpp_location}"/>
<param name="grammar_name" value="${grammar_name}"/>
</antcall>
</target>
</project>

View file

@ -0,0 +1,60 @@
-----------------------------------------------------------------------------------
-- Copyright (c) 2009 IBM Corporation and others.
-- All rights reserved. This program and the accompanying materials
-- are made available under the terms of the Eclipse Public License v1.0
-- which accompanies this distribution, and is available at
-- http://www.eclipse.org/legal/epl-v10.html
--
-- Contributors:
-- IBM Corporation - initial API and implementation
-----------------------------------------------------------------------------------
%options la=2
%options package=org.eclipse.cdt.internal.core.lrparser.xlc.cpp
%options template=LRParserTemplate.g
$Import
GPPGrammar.g
$End
$Import
XlcGrammarExtensions.g
$End
$Globals
/.
import org.eclipse.cdt.core.lrparser.xlc.action.XlcCPPBuildASTParserAction;
import org.eclipse.cdt.core.dom.lrparser.action.gnu.GPPSecondaryParserFactory;
import org.eclipse.cdt.internal.core.lrparser.xlc.ast.XlcCPPNodeFactory;
./
$End
$Define
$build_action_class /. XlcCPPBuildASTParserAction ./
$parser_factory_create_expression /. GPPSecondaryParserFactory.getDefault() ./
$node_factory_create_expression /. XlcCPPNodeFactory.getDefault() ./
$End
$Start
translation_unit
$End
$Rules
block_declaration
::= vector_declaration
identifier_token
::= 'vector'
| 'pixel'
specifier_qualifier
::= 'typedef'
/. $Build consumeToken(); $EndBuild ./
$End

View file

@ -0,0 +1,67 @@
-----------------------------------------------------------------------------------
-- Copyright (c) 2009 IBM Corporation and others.
-- All rights reserved. This program and the accompanying materials
-- are made available under the terms of the Eclipse Public License v1.0
-- which accompanies this distribution, and is available at
-- http://www.eclipse.org/legal/epl-v10.html
--
-- Contributors:
-- IBM Corporation - initial API and implementation
-----------------------------------------------------------------------------------
%options la=2
%options package=org.eclipse.cdt.internal.core.lrparser.xlc.c
%options template=LRParserTemplate.g
$Import
GCCGrammar.g
$End
$Import
XlcGrammarExtensions.g
$End
$Globals
/.
import org.eclipse.cdt.core.lrparser.xlc.action.XlcCBuildASTParserAction;
import org.eclipse.cdt.core.dom.lrparser.action.gnu.GCCSecondaryParserFactory;
import org.eclipse.cdt.internal.core.lrparser.xlc.ast.XlcCNodeFactory;
./
$End
$Define
$build_action_class /. XlcCBuildASTParserAction ./
$parser_factory_create_expression /. GCCSecondaryParserFactory.getDefault() ./
$node_factory_create_expression /. XlcCNodeFactory.getDefault() ./
$End
$Start
translation_unit
$End
$Rules
declaration
::= vector_declaration
identifier_token
::= 'pixel'
| 'vector'
| 'bool'
declarator_id_name
::= 'pixel'
/. $Build consumeIdentifierName(); $EndBuild ./
| 'vector'
/. $Build consumeIdentifierName(); $EndBuild ./
| 'bool'
/. $Build consumeIdentifierName(); $EndBuild ./
$End

View file

@ -0,0 +1,82 @@
-----------------------------------------------------------------------------------
-- Copyright (c) 2009 IBM Corporation and others.
-- All rights reserved. This program and the accompanying materials
-- are made available under the terms of the Eclipse Public License v1.0
-- which accompanies this distribution, and is available at
-- http://www.eclipse.org/legal/epl-v10.html
--
-- Contributors:
-- IBM Corporation - initial API and implementation
-----------------------------------------------------------------------------------
-- These are additional rules that allow for parsing of GNU extensions.
-- This file is intended to be mixed-in with C99Parser.g or GPPParser.g
$Terminals
vector
pixel
bool
$End
$Rules
type_id
::= vector_type
/. $Build consumeTypeId(false); $EndBuild ./
| vector_type abstract_declarator
/. $Build consumeTypeId(true); $EndBuild ./
vector_declaration
::= vector_type <openscope-ast> init_declarator_list ';'
/. $Build consumeDeclarationSimple(true); $EndBuild ./
vector_type
::= <openscope-ast> no_type_declaration_specifiers_opt 'vector' vector_type_specifier all_specifier_qualifier_list_opt
/. $Build consumeVectorTypeSpecifier(); $EndBuild ./
vector_type_specifier
::= vector_type_specifier_token
/. $Build consumeToken(); $EndBuild ./
vector_type_specifier_token
::= 'pixel'
| 'float'
| 'bool'
| 'signed'
| 'unsigned'
| 'char'
| 'short'
| 'int'
| 'long'
all_specifier_qualifiers
::= vector_type_specifier
| no_type_declaration_specifiers
all_specifier_qualifier_list
::= all_specifier_qualifiers
| all_specifier_qualifier_list all_specifier_qualifiers
all_specifier_qualifier_list_opt
::= all_specifier_qualifier_list
| $empty
no_type_declaration_specifiers_opt
::= no_type_declaration_specifiers
| $empty
$End

View file

@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc;
import java.util.Map;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.lrparser.IParser;
import org.eclipse.cdt.core.dom.lrparser.gnu.GCCLanguage;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ICLanguageKeywords;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.internal.core.lrparser.xlc.c.XlcCParser;
/**
*
* @author Mike Kucera
*/
public class XlcCLanguage extends GCCLanguage {
public static final String ID = "org.eclipse.cdt.core.lrparser.xlc.c"; //$NON-NLS-1$
private static XlcCLanguage DEFAULT = new XlcCLanguage();
public static XlcCLanguage getDefault() {
return DEFAULT;
}
@Override
protected IParser<IASTTranslationUnit> getParser(IScanner scanner, IIndex index, Map<String,String> properties) {
boolean supportVectors = XlcCPPLanguage.supportVectors(properties);
return new XlcCParser(scanner, new XlcCTokenMap(supportVectors), getBuiltinBindingsProvider(), index, properties);
}
public String getId() {
return ID;
}
@Override
protected IScannerExtensionConfiguration getScannerExtensionConfiguration() {
return XlcScannerExtensionConfiguration.getInstance();
}
@SuppressWarnings("unchecked")
@Override
public Object getAdapter(Class adapter) {
if(ICLanguageKeywords.class.equals(adapter))
return XlcKeywords.C;
return super.getAdapter(adapter);
}
}

View file

@ -0,0 +1,85 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc;
import java.util.Map;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.lrparser.IParser;
import org.eclipse.cdt.core.dom.lrparser.LRParserProperties;
import org.eclipse.cdt.core.dom.lrparser.gnu.GPPLanguage;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcLanguagePreferences;
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcPreferenceKeys;
import org.eclipse.cdt.core.model.ICLanguageKeywords;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.internal.core.lrparser.xlc.cpp.XlcCPPParser;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
/**
*
* @author Mike Kucera
*/
public class XlcCPPLanguage extends GPPLanguage {
public static final String ID = "org.eclipse.cdt.core.lrparser.xlc.cpp"; //$NON-NLS-1$
private static XlcCPPLanguage DEFAULT = new XlcCPPLanguage();
public static XlcCPPLanguage getDefault() {
return DEFAULT;
}
public static boolean supportVectors(Map<String,String> properties) {
String path = properties.get(LRParserProperties.TRANSLATION_UNIT_PATH);
System.out.println("path: " + path);
IFile[] file = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(path));
IProject project = null;
if(file != null && file.length > 0) {
project = file[0].getProject();
}
return Boolean.valueOf(XlcLanguagePreferences.getPreference(XlcPreferenceKeys.KEY_SUPPORT_VECTOR_TYPES, project));
}
@Override
protected IParser<IASTTranslationUnit> getParser(IScanner scanner, IIndex index, Map<String,String> properties) {
boolean supportVectors = supportVectors(properties);
XlcCPPParser parser = new XlcCPPParser(scanner, new XlcCPPTokenMap(supportVectors), getBuiltinBindingsProvider(), index, properties);
return parser;
}
public String getId() {
return ID;
}
@Override
protected IScannerExtensionConfiguration getScannerExtensionConfiguration() {
return XlcScannerExtensionConfiguration.getInstance();
}
@SuppressWarnings("unchecked")
@Override
public Object getAdapter(Class adapter) {
if(ICLanguageKeywords.class.equals(adapter))
return XlcKeywords.CPP;
return super.getAdapter(adapter);
}
}

View file

@ -0,0 +1,202 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc;
import static org.eclipse.cdt.core.parser.IToken.*;
import static org.eclipse.cdt.internal.core.lrparser.xlc.cpp.XlcCPPParsersym.*;
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
import org.eclipse.cdt.core.parser.IGCCToken;
import org.eclipse.cdt.core.parser.IToken;
/**
* Maps tokens types returned by CPreprocessor to token types
* expected by the C++ parser.
*
* @author Mike Kucera
*/
public class XlcCPPTokenMap implements IDOMTokenMap {
private final boolean supportVectors;
public XlcCPPTokenMap(boolean supportVectors) {
this.supportVectors = supportVectors;
}
public int getEOFTokenKind() {
return TK_EOF_TOKEN;
}
public int getEOCTokenKind() {
return TK_EndOfCompletion;
}
public int mapKind(IToken token) {
switch(token.getType()) {
case tIDENTIFIER :
if(supportVectors) {
Integer keywordKind = XlcKeywords.CPP.getTokenKind(token.getCharImage());
return keywordKind == null ? TK_identifier : keywordKind;
}
else {
return TK_identifier;
}
case tINTEGER : return TK_integer;
case tCOLONCOLON : return TK_ColonColon;
case tCOLON : return TK_Colon;
case tSEMI : return TK_SemiColon;
case tCOMMA : return TK_Comma;
case tQUESTION : return TK_Question;
case tLPAREN : return TK_LeftParen;
case tRPAREN : return TK_RightParen;
case tLBRACKET : return TK_LeftBracket;
case tRBRACKET : return TK_RightBracket;
case tLBRACE : return TK_LeftBrace;
case tRBRACE : return TK_RightBrace;
case tPLUSASSIGN : return TK_PlusAssign;
case tINCR : return TK_PlusPlus;
case tPLUS : return TK_Plus;
case tMINUSASSIGN : return TK_MinusAssign;
case tDECR : return TK_MinusMinus;
case tARROWSTAR : return TK_ArrowStar;
case tARROW : return TK_Arrow;
case tMINUS : return TK_Minus;
case tSTARASSIGN : return TK_StarAssign;
case tSTAR : return TK_Star;
case tMODASSIGN : return TK_PercentAssign;
case tMOD : return TK_Percent;
case tXORASSIGN : return TK_CaretAssign;
case tXOR : return TK_Caret;
case tAMPERASSIGN : return TK_AndAssign;
case tAND : return TK_AndAnd;
case tAMPER : return TK_And;
case tBITORASSIGN : return TK_OrAssign;
case tOR : return TK_OrOr;
case tBITOR : return TK_Or;
case tBITCOMPLEMENT: return TK_Tilde;
case tNOTEQUAL : return TK_NE;
case tNOT : return TK_Bang;
case tEQUAL : return TK_EQ;
case tASSIGN : return TK_Assign;
case tUNKNOWN_CHAR : return TK_Invalid;
case tSHIFTL : return TK_LeftShift;
case tLTEQUAL : return TK_LE;
case tLT : return TK_LT;
case tSHIFTRASSIGN : return TK_RightShiftAssign;
case tSHIFTR : return TK_RightShift;
case tGTEQUAL : return TK_GE;
case tGT : return TK_GT;
case tSHIFTLASSIGN : return TK_LeftShiftAssign;
case tELLIPSIS : return TK_DotDotDot;
case tDOTSTAR : return TK_DotStar;
case tDOT : return TK_Dot;
case tDIVASSIGN : return TK_SlashAssign;
case tDIV : return TK_Slash;
case t_asm : return TK_asm;
case t_auto : return TK_auto;
case t_bool : return TK_bool;
case t_break : return TK_break;
case t_case : return TK_case;
case t_catch : return TK_catch;
case t_char : return TK_char;
case t_class : return TK_class;
case t_const : return TK_const;
case t_const_cast : return TK_const_cast;
case t_continue : return TK_continue;
case t_default : return TK_default;
case t_delete : return TK_delete;
case t_do : return TK_do;
case t_double : return TK_double;
case t_dynamic_cast: return TK_dynamic_cast;
case t_else : return TK_else;
case t_enum : return TK_enum;
case t_explicit : return TK_explicit;
case t_export : return TK_export;
case t_extern : return TK_extern;
case t_false : return TK_false;
case t_float : return TK_float;
case t_for : return TK_for;
case t_friend : return TK_friend;
case t_goto : return TK_goto;
case t_if : return TK_if;
case t_inline : return TK_inline;
case t_int : return TK_int;
case t_long : return TK_long;
case t_mutable : return TK_mutable;
case t_namespace : return TK_namespace;
case t_new : return TK_new;
case t_operator : return TK_operator;
case t_private : return TK_private;
case t_protected : return TK_protected;
case t_public : return TK_public;
case t_register : return TK_register;
case t_reinterpret_cast : return TK_reinterpret_cast;
case t_return : return TK_return;
case t_short : return TK_short;
case t_sizeof : return TK_sizeof;
case t_static : return TK_static;
case t_static_cast : return TK_static_cast;
case t_signed : return TK_signed;
case t_struct : return TK_struct;
case t_switch : return TK_switch;
case t_template : return TK_template;
case t_this : return TK_this;
case t_throw : return TK_throw;
case t_true : return TK_true;
case t_try : return TK_try;
case t_typedef : return TK_typedef;
case t_typeid : return TK_typeid;
case t_typename : return TK_typename;
case t_union : return TK_union;
case t_unsigned : return TK_unsigned;
case t_using : return TK_using;
case t_virtual : return TK_virtual;
case t_void : return TK_void;
case t_volatile : return TK_volatile;
case t_wchar_t : return TK_wchar_t;
case t_while : return TK_while;
case tFLOATINGPT : return TK_floating;
case tSTRING : return TK_stringlit;
case tLSTRING : return TK_stringlit;
case tUTF16STRING : return TK_stringlit;
case tUTF32STRING : return TK_stringlit;
case tUTF16CHAR : return TK_charconst;
case tUTF32CHAR : return TK_charconst;
case tCHAR : return TK_charconst;
case tLCHAR : return TK_charconst;
case tCOMPLETION : return TK_Completion;
case tEOC : return TK_EndOfCompletion;
case tEND_OF_INPUT : return TK_EOF_TOKEN;
case IGCCToken.t_typeof : return TK_typeof;
case IGCCToken.t___alignof__ : return TK___alignof__;
case IGCCToken.tMAX : return TK_MAX;
case IGCCToken.tMIN : return TK_MIN;
case IGCCToken.t__attribute__ : return TK___attribute__;
case IGCCToken.t__declspec : return TK___declspec;
// GNU supports these but they are not in the C++ spec
case t__Complex : return TK__Complex;
case t__Imaginary : return TK__Imaginary;
case t_restrict : return TK_restrict;
default:
assert false : "token not recognized: " + token.getType(); //$NON-NLS-1$
return TK_Invalid;
}
}
}

View file

@ -0,0 +1,170 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc;
import static org.eclipse.cdt.core.parser.IToken.*;
import static org.eclipse.cdt.internal.core.lrparser.xlc.c.XlcCParsersym.*;
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
import org.eclipse.cdt.core.parser.IGCCToken;
import org.eclipse.cdt.core.parser.IToken;
/**
* Maps tokens types returned by CPreprocessor to token types
* expected by the C99 parser.
*
* @author Mike Kucera
*/
public final class XlcCTokenMap implements IDOMTokenMap {
private final boolean supportVectors;
public XlcCTokenMap(boolean supportVectors) {
this.supportVectors = supportVectors;
}
public int getEOFTokenKind() {
return TK_EOF_TOKEN;
}
public int getEOCTokenKind() {
return TK_EndOfCompletion;
}
public int mapKind(IToken token) {
switch(token.getType()) {
case tIDENTIFIER :
if(supportVectors) {
Integer keywordKind = XlcKeywords.C.getTokenKind(token.getCharImage());
return keywordKind == null ? TK_identifier : keywordKind;
}
else {
return TK_identifier;
}
case tINTEGER : return TK_integer;
case tCOLON : return TK_Colon;
case tSEMI : return TK_SemiColon;
case tCOMMA : return TK_Comma;
case tQUESTION : return TK_Question;
case tLPAREN : return TK_LeftParen;
case tRPAREN : return TK_RightParen;
case tLBRACKET : return TK_LeftBracket;
case tRBRACKET : return TK_RightBracket;
case tLBRACE : return TK_LeftBrace;
case tRBRACE : return TK_RightBrace;
case tPLUSASSIGN : return TK_PlusAssign;
case tINCR : return TK_PlusPlus;
case tPLUS : return TK_Plus;
case tMINUSASSIGN : return TK_MinusAssign;
case tDECR : return TK_MinusMinus;
case tARROW : return TK_Arrow;
case tMINUS : return TK_Minus;
case tSTARASSIGN : return TK_StarAssign;
case tSTAR : return TK_Star;
case tMODASSIGN : return TK_PercentAssign;
case tMOD : return TK_Percent;
case tXORASSIGN : return TK_CaretAssign;
case tXOR : return TK_Caret;
case tAMPERASSIGN : return TK_AndAssign;
case tAND : return TK_AndAnd;
case tAMPER : return TK_And;
case tBITORASSIGN : return TK_OrAssign;
case tOR : return TK_OrOr;
case tBITOR : return TK_Or;
case tBITCOMPLEMENT: return TK_Tilde;
case tNOTEQUAL : return TK_NE;
case tNOT : return TK_Bang;
case tEQUAL : return TK_EQ;
case tASSIGN : return TK_Assign;
case tUNKNOWN_CHAR : return TK_Invalid;
case tSHIFTL : return TK_LeftShift;
case tLTEQUAL : return TK_LE;
case tLT : return TK_LT;
case tSHIFTRASSIGN : return TK_RightShiftAssign;
case tSHIFTR : return TK_RightShift;
case tGTEQUAL : return TK_GE;
case tGT : return TK_GT;
case tSHIFTLASSIGN : return TK_LeftShiftAssign;
case tELLIPSIS : return TK_DotDotDot;
case tDOT : return TK_Dot;
case tDIVASSIGN : return TK_SlashAssign;
case tDIV : return TK_Slash;
case t_auto : return TK_auto;
case t_break : return TK_break;
case t_case : return TK_case;
case t_char : return TK_char;
case t_const : return TK_const;
case t_continue : return TK_continue;
case t_default : return TK_default;
case t_do : return TK_do;
case t_double : return TK_double;
case t_else : return TK_else;
case t_enum : return TK_enum;
case t_extern : return TK_extern;
case t_float : return TK_float;
case t_for : return TK_for;
case t_goto : return TK_goto;
case t_if : return TK_if;
case t_inline : return TK_inline;
case t_int : return TK_int;
case t_long : return TK_long;
case t_register : return TK_register;
case t_return : return TK_return;
case t_short : return TK_short;
case t_sizeof : return TK_sizeof;
case t_static : return TK_static;
case t_signed : return TK_signed;
case t_struct : return TK_struct;
case t_switch : return TK_switch;
case t_typedef : return TK_typedef;
case t_union : return TK_union;
case t_unsigned : return TK_unsigned;
case t_void : return TK_void;
case t_volatile : return TK_volatile;
case t_while : return TK_while;
case tFLOATINGPT : return TK_floating;
case tSTRING : return TK_stringlit;
case tLSTRING : return TK_stringlit;
case tUTF16STRING : return TK_stringlit;
case tUTF32STRING : return TK_stringlit;
case tCHAR : return TK_charconst;
case tLCHAR : return TK_charconst;
case tUTF16CHAR : return TK_charconst;
case tUTF32CHAR : return TK_charconst;
case t__Bool : return TK__Bool;
case t__Complex : return TK__Complex;
case t__Imaginary : return TK__Imaginary;
case t_restrict : return TK_restrict;
case tCOMPLETION : return TK_Completion;
case tEOC : return TK_EndOfCompletion;
case tEND_OF_INPUT : return TK_EOF_TOKEN;
case IGCCToken.t_typeof : return TK_typeof;
case IGCCToken.t___alignof__ : return TK___alignof__;
case IGCCToken.tMAX : return TK_MAX;
case IGCCToken.tMIN : return TK_MIN;
case IGCCToken.t__attribute__ : return TK___attribute__;
case IGCCToken.t__declspec : return TK___declspec;
case t_asm: return TK_asm;
default:
assert false : "token not recognized by the XLC parser: " + token.getType(); //$NON-NLS-1$
return TK_Invalid;
}
}
}

View file

@ -0,0 +1,82 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.core.dom.parser.CLanguageKeywords;
import org.eclipse.cdt.core.model.ICLanguageKeywords;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.CharArrayMap;
import org.eclipse.cdt.internal.core.lrparser.xlc.c.XlcCParsersym;
import org.eclipse.cdt.internal.core.lrparser.xlc.cpp.XlcCPPParsersym;
public class XlcKeywords extends CLanguageKeywords {
public static final XlcKeywords C = new XlcKeywords(ParserLanguage.C);
static {
C.map.put("vector".toCharArray(), XlcCParsersym.TK_vector);
C.map.put("__vector".toCharArray(), XlcCParsersym.TK_vector);
C.map.put("pixel".toCharArray(), XlcCParsersym.TK_pixel);
C.map.put("__pixel".toCharArray(), XlcCParsersym.TK_pixel);
C.map.put("bool".toCharArray(), XlcCParsersym.TK_bool);
}
public static final XlcKeywords CPP = new XlcKeywords(ParserLanguage.CPP);
static {
CPP.map.put("vector".toCharArray(), XlcCPPParsersym.TK_vector);
CPP.map.put("__vector".toCharArray(), XlcCPPParsersym.TK_vector);
CPP.map.put("pixel".toCharArray(), XlcCPPParsersym.TK_pixel);
CPP.map.put("__pixel".toCharArray(), XlcCPPParsersym.TK_pixel);
// bool is already a C++ keyword
}
private final CharArrayMap<Integer> map = new CharArrayMap<Integer>();
private final ParserLanguage language;
private String[] allKeywords = null;
private XlcKeywords(ParserLanguage language) {
super(language, XlcScannerExtensionConfiguration.getInstance());
this.language = language;
}
/**
* Returns the LPG token kind for additional keywords defined by
* the XLC extensions, null otherwise.
*/
public Integer getTokenKind(char[] keyword) {
return map.get(keyword);
}
@Override
public synchronized String[] getKeywords() {
if(allKeywords == null) {
ICLanguageKeywords base = new CLanguageKeywords(language, XlcScannerExtensionConfiguration.getInstance());
String[] baseKeywords = base.getKeywords();
List<String> keywords = new ArrayList<String>();
keywords.addAll(Arrays.asList(baseKeywords));
for(char[] keyword : map.keys()) {
keywords.add(String.valueOf(keyword));
}
allKeywords = keywords.toArray(new String[keywords.size()]);
}
return allKeywords;
}
}

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc;
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
public class XlcScannerExtensionConfiguration extends GCCScannerExtensionConfiguration {
private static XlcScannerExtensionConfiguration instance;
private XlcScannerExtensionConfiguration() {}
public static synchronized XlcScannerExtensionConfiguration getInstance() {
if(instance == null)
instance = new XlcScannerExtensionConfiguration();
return instance;
}
@Override
public boolean supportUTFLiterals() {
return true;
}
}

View file

@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc.action;
import lpg.lpgjavaruntime.IToken;
import org.eclipse.cdt.core.dom.lrparser.action.ISecondaryParserFactory;
import org.eclipse.cdt.core.dom.lrparser.action.ITokenStream;
import org.eclipse.cdt.core.dom.lrparser.action.ScopedStack;
import org.eclipse.cdt.core.dom.lrparser.action.gnu.GCCBuildASTParserAction;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCASTVectorTypeSpecifier;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCNodeFactory;
import org.eclipse.cdt.internal.core.lrparser.xlc.c.XlcCParsersym;
public class XlcCBuildASTParserAction extends GCCBuildASTParserAction {
private IXlcCNodeFactory nodeFactory;
public XlcCBuildASTParserAction(ITokenStream parser,
ScopedStack<Object> astStack, IXlcCNodeFactory nodeFactory,
ISecondaryParserFactory parserFactory) {
super(parser, astStack, nodeFactory, parserFactory);
this.nodeFactory = nodeFactory;
}
/*
* vector_type
* ::= <openscope-ast> sqlist_op 'vector' vector_type_specifier all_specifier_qualifier_list
*/
public void consumeVectorTypeSpecifier() {
IXlcCASTVectorTypeSpecifier declSpec = nodeFactory.newVectorTypeSpecifier();
for(Object specifier : astStack.closeScope()) {
if(specifier instanceof IToken) {
switch(((IToken)specifier).getKind()) {
case XlcCParsersym.TK_pixel :
declSpec.setPixel(true);
continue;
case XlcCParsersym.TK_bool :
declSpec.setBool(true);
continue;
case XlcCParsersym.TK_vector :
continue;
}
}
setSpecifier(declSpec, specifier);
}
setOffsetAndLength(declSpec);
astStack.push(declSpec);
}
}

View file

@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc.action;
import lpg.lpgjavaruntime.IToken;
import org.eclipse.cdt.core.dom.lrparser.action.ITokenStream;
import org.eclipse.cdt.core.dom.lrparser.action.ScopedStack;
import org.eclipse.cdt.core.dom.lrparser.action.cpp.ICPPSecondaryParserFactory;
import org.eclipse.cdt.core.dom.lrparser.action.gnu.GPPBuildASTParserAction;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCPPASTVectorTypeSpecifier;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCPPNodeFactory;
import org.eclipse.cdt.internal.core.lrparser.xlc.cpp.XlcCPPParsersym;
public class XlcCPPBuildASTParserAction extends GPPBuildASTParserAction {
private IXlcCPPNodeFactory nodeFactory;
public XlcCPPBuildASTParserAction(ITokenStream parser,
ScopedStack<Object> astStack, IXlcCPPNodeFactory nodeFactory,
ICPPSecondaryParserFactory parserFactory) {
super(parser, astStack, nodeFactory, parserFactory);
this.nodeFactory = nodeFactory;
}
/*
* vector_type
* ::= <openscope-ast> sqlist_op 'vector' vector_type_specifier all_specifier_qualifier_list
*/
public void consumeVectorTypeSpecifier() {
IXlcCPPASTVectorTypeSpecifier declSpec = nodeFactory.newVectorTypeSpecifier();
for(Object specifier : astStack.closeScope()) {
if(specifier instanceof IToken) {
switch(((IToken)specifier).getKind()) {
case XlcCPPParsersym.TK_pixel :
declSpec.setPixel(true);
continue;
case XlcCPPParsersym.TK_vector :
continue;
}
}
setSpecifier(declSpec, specifier);
}
setOffsetAndLength(declSpec);
astStack.push(declSpec);
}
}

View file

@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc.activator;
import org.eclipse.core.runtime.Plugin;
public class XlcParserPlugin extends Plugin {
public static final String PLUGIN_ID = "org.eclipse.cdt.core.lrparser.xlc";
}

View file

@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc.ast;
import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
public interface IXlcCASTVectorTypeSpecifier extends ICASTDeclSpecifier {
public boolean isPixel();
public void setPixel(boolean isPixel);
public boolean isBool();
public void setBool(boolean isBool);
}

View file

@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc.ast;
import org.eclipse.cdt.core.dom.ast.c.ICNodeFactory;
public interface IXlcCNodeFactory extends ICNodeFactory {
public IXlcCASTVectorTypeSpecifier newVectorTypeSpecifier();
}

View file

@ -0,0 +1,21 @@
/*************************************************import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
ration and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc.ast;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
public interface IXlcCPPASTVectorTypeSpecifier extends ICPPASTDeclSpecifier {
public boolean isPixel();
public void setPixel(boolean isPixel);
}

View file

@ -0,0 +1,19 @@
/*************************************************import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory;
Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc.ast;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory;
public interface IXlcCPPNodeFactory extends ICPPNodeFactory {
public IXlcCPPASTVectorTypeSpecifier newVectorTypeSpecifier();
}

View file

@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc.preferences;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
public class PreferenceInitializer extends AbstractPreferenceInitializer {
@Override
public void initializeDefaultPreferences() {
XlcLanguagePreferences.initializeDefaultPreferences();
}
}

View file

@ -0,0 +1,108 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc.preferences;
import org.eclipse.cdt.core.lrparser.xlc.activator.XlcParserPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.service.prefs.Preferences;
/**
* TODO trigger the indexer?
*
* @author Mike Kucera
*/
public class XlcLanguagePreferences {
private static final String QUALIFIER = XlcParserPlugin.PLUGIN_ID;
private static final String XLC_PREFERENCES_NODE = "xlc.preferences";
public static void initializeDefaultPreferences() {
Preferences prefs = getDefaultPreferences();
prefs.putBoolean(XlcPreferenceKeys.KEY_SUPPORT_VECTOR_TYPES, true);
}
public static void setProjectPreference(String key, String value, IProject project) {
getProjectPreferences(project).put(key, value);
}
public static void setWorkspacePreference(String key, String value) {
getWorkspacePreferences().put(key, value);
}
public static String getProjectPreference(String key, IProject project) {
return getProjectPreferences(project).get(key, null);
}
public static String getWorkspacePreference(String key) {
return getWorkspacePreferences().get(key, null);
}
public static String getDefaultPreference(String key) {
return getDefaultPreferences().get(key, null);
}
/**
* Returns the preference for the given key.
*
* @param project If null then just the workspace and default preferences will be checked.
*/
public static String getPreference(String key, IProject project) {
Preferences[] prefs;
if(project == null) {
prefs = new Preferences[] {
getWorkspacePreferences(),
getDefaultPreferences()
};
}
else {
prefs = new Preferences[] {
getProjectPreferences(project),
getWorkspacePreferences(),
getDefaultPreferences()
};
}
return Platform.getPreferencesService().get(key, null, prefs);
}
private static Preferences getDefaultPreferences() {
return getPreferences(new DefaultScope());
}
private static Preferences getWorkspacePreferences() {
return getPreferences(new InstanceScope());
}
private static Preferences getProjectPreferences(IProject project) {
return getPreferences(new ProjectScope(project));
}
private static Preferences getPreferences(IScopeContext scope) {
return scope.getNode(QUALIFIER).node(XLC_PREFERENCES_NODE);
}
}

View file

@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.lrparser.xlc.preferences;
public final class XlcPreferenceKeys {
private XlcPreferenceKeys() {}
/**
* Type: boolean
* Default: false
*/
public static final String KEY_SUPPORT_VECTOR_TYPES = "vectorTypes";
}

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.lrparser.xlc.ast;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCASTVectorTypeSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.c.CASTSimpleDeclSpecifier;
public class XlcCASTVectorTypeSpecifier extends CASTSimpleDeclSpecifier implements IXlcCASTVectorTypeSpecifier {
private boolean isPixel;
private boolean isBool;
public XlcCASTVectorTypeSpecifier() {
super();
}
@Override
public XlcCASTVectorTypeSpecifier copy() {
XlcCASTVectorTypeSpecifier copy = new XlcCASTVectorTypeSpecifier();
copySimpleDeclSpec(copy);
copy.isPixel = isPixel;
copy.isBool = isBool;
return copy;
}
public boolean isPixel() {
return isPixel;
}
public void setPixel(boolean isPixel) {
this.isPixel = isPixel;
}
public boolean isBool() {
return isBool;
}
public void setBool(boolean isBool) {
this.isBool = isBool;
}
}

View file

@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.lrparser.xlc.ast;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCASTVectorTypeSpecifier;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCNodeFactory;
import org.eclipse.cdt.internal.core.dom.parser.c.CNodeFactory;
public class XlcCNodeFactory extends CNodeFactory implements IXlcCNodeFactory {
private static final XlcCNodeFactory DEFAULT_INSTANCE = new XlcCNodeFactory();
public static XlcCNodeFactory getDefault() {
return DEFAULT_INSTANCE;
}
public IXlcCASTVectorTypeSpecifier newVectorTypeSpecifier() {
return new XlcCASTVectorTypeSpecifier();
}
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.lrparser.xlc.ast;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCPPASTVectorTypeSpecifier;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
public class XlcCPPASTVectorTypeSpecifier extends CPPASTSimpleDeclSpecifier implements IXlcCPPASTVectorTypeSpecifier {
private boolean isPixel;
public XlcCPPASTVectorTypeSpecifier() {
super();
}
@Override
public XlcCPPASTVectorTypeSpecifier copy() {
XlcCPPASTVectorTypeSpecifier copy = new XlcCPPASTVectorTypeSpecifier();
copySimpleDeclSpec(copy);
copy.isPixel = isPixel;
return copy;
}
public boolean isPixel() {
return isPixel;
}
public void setPixel(boolean isPixel) {
this.isPixel = isPixel;
}
}

View file

@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.lrparser.xlc.ast;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCPPASTVectorTypeSpecifier;
import org.eclipse.cdt.core.lrparser.xlc.ast.IXlcCPPNodeFactory;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
public class XlcCPPNodeFactory extends CPPNodeFactory implements IXlcCPPNodeFactory {
private static final XlcCPPNodeFactory DEFAULT_INSTANCE = new XlcCPPNodeFactory();
public static XlcCPPNodeFactory getDefault() {
return DEFAULT_INSTANCE;
}
public IXlcCPPASTVectorTypeSpecifier newVectorTypeSpecifier() {
return new XlcCPPASTVectorTypeSpecifier();
}
}

View file

@ -0,0 +1,230 @@
/*******************************************************************************
* Copyright (c) 2006, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*********************************************************************************/
// This file was generated by LPG
package org.eclipse.cdt.internal.core.lrparser.xlc.c;
public interface XlcCParsersym {
public final static int
TK_auto = 32,
TK_break = 50,
TK_case = 51,
TK_char = 39,
TK_const = 27,
TK_continue = 52,
TK_default = 53,
TK_do = 54,
TK_double = 55,
TK_else = 102,
TK_enum = 65,
TK_extern = 33,
TK_float = 40,
TK_for = 56,
TK_goto = 57,
TK_if = 58,
TK_inline = 34,
TK_int = 41,
TK_long = 42,
TK_register = 35,
TK_restrict = 29,
TK_return = 59,
TK_short = 43,
TK_signed = 44,
TK_sizeof = 20,
TK_static = 30,
TK_struct = 66,
TK_switch = 60,
TK_typedef = 36,
TK_union = 67,
TK_unsigned = 45,
TK_void = 61,
TK_volatile = 28,
TK_while = 48,
TK__Bool = 62,
TK__Complex = 63,
TK__Imaginary = 64,
TK_integer = 21,
TK_floating = 22,
TK_charconst = 23,
TK_stringlit = 19,
TK_identifier = 2,
TK_Completion = 11,
TK_EndOfCompletion = 6,
TK_Invalid = 103,
TK_LeftBracket = 37,
TK_LeftParen = 1,
TK_LeftBrace = 18,
TK_Dot = 72,
TK_Arrow = 87,
TK_PlusPlus = 16,
TK_MinusMinus = 17,
TK_And = 15,
TK_Star = 10,
TK_Plus = 13,
TK_Minus = 14,
TK_Tilde = 24,
TK_Bang = 25,
TK_Slash = 73,
TK_Percent = 74,
TK_RightShift = 69,
TK_LeftShift = 70,
TK_LT = 75,
TK_GT = 76,
TK_LE = 77,
TK_GE = 78,
TK_EQ = 81,
TK_NE = 82,
TK_Caret = 83,
TK_Or = 84,
TK_AndAnd = 85,
TK_OrOr = 88,
TK_Question = 89,
TK_Colon = 49,
TK_DotDotDot = 86,
TK_Assign = 71,
TK_StarAssign = 90,
TK_SlashAssign = 91,
TK_PercentAssign = 92,
TK_PlusAssign = 93,
TK_MinusAssign = 94,
TK_RightShiftAssign = 95,
TK_LeftShiftAssign = 96,
TK_AndAssign = 97,
TK_CaretAssign = 98,
TK_OrAssign = 99,
TK_Comma = 46,
TK_RightBracket = 100,
TK_RightParen = 47,
TK_RightBrace = 68,
TK_SemiColon = 31,
TK_typeof = 12,
TK___alignof__ = 26,
TK___attribute__ = 8,
TK___declspec = 9,
TK_MAX = 79,
TK_MIN = 80,
TK_asm = 7,
TK_vector = 5,
TK_pixel = 3,
TK_bool = 4,
TK_ERROR_TOKEN = 38,
TK_EOF_TOKEN = 101;
public final static String orderedTerminalSymbols[] = {
"",
"LeftParen",
"identifier",
"pixel",
"bool",
"vector",
"EndOfCompletion",
"asm",
"__attribute__",
"__declspec",
"Star",
"Completion",
"typeof",
"Plus",
"Minus",
"And",
"PlusPlus",
"MinusMinus",
"LeftBrace",
"stringlit",
"sizeof",
"integer",
"floating",
"charconst",
"Tilde",
"Bang",
"__alignof__",
"const",
"volatile",
"restrict",
"static",
"SemiColon",
"auto",
"extern",
"inline",
"register",
"typedef",
"LeftBracket",
"ERROR_TOKEN",
"char",
"float",
"int",
"long",
"short",
"signed",
"unsigned",
"Comma",
"RightParen",
"while",
"Colon",
"break",
"case",
"continue",
"default",
"do",
"double",
"for",
"goto",
"if",
"return",
"switch",
"void",
"_Bool",
"_Complex",
"_Imaginary",
"enum",
"struct",
"union",
"RightBrace",
"RightShift",
"LeftShift",
"Assign",
"Dot",
"Slash",
"Percent",
"LT",
"GT",
"LE",
"GE",
"MAX",
"MIN",
"EQ",
"NE",
"Caret",
"Or",
"AndAnd",
"DotDotDot",
"Arrow",
"OrOr",
"Question",
"StarAssign",
"SlashAssign",
"PercentAssign",
"PlusAssign",
"MinusAssign",
"RightShiftAssign",
"LeftShiftAssign",
"AndAssign",
"CaretAssign",
"OrAssign",
"RightBracket",
"EOF_TOKEN",
"else",
"Invalid"
};
public final static boolean isValidForParser = true;
}

View file

@ -0,0 +1,290 @@
/*******************************************************************************
* Copyright (c) 2006, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*********************************************************************************/
// This file was generated by LPG
package org.eclipse.cdt.internal.core.lrparser.xlc.cpp;
public interface XlcCPPParsersym {
public final static int
TK__Complex = 24,
TK__Imaginary = 25,
TK_restrict = 32,
TK_asm = 7,
TK_auto = 34,
TK_bool = 15,
TK_break = 85,
TK_case = 86,
TK_catch = 129,
TK_char = 16,
TK_class = 50,
TK_const = 30,
TK_const_cast = 52,
TK_continue = 87,
TK_default = 88,
TK_delete = 78,
TK_do = 89,
TK_double = 26,
TK_dynamic_cast = 53,
TK_else = 132,
TK_enum = 65,
TK_explicit = 35,
TK_export = 90,
TK_extern = 36,
TK_false = 54,
TK_float = 17,
TK_for = 91,
TK_friend = 37,
TK_goto = 92,
TK_if = 93,
TK_inline = 38,
TK_int = 18,
TK_long = 19,
TK_mutable = 39,
TK_namespace = 68,
TK_new = 79,
TK_operator = 12,
TK_private = 113,
TK_protected = 114,
TK_public = 115,
TK_register = 40,
TK_reinterpret_cast = 55,
TK_return = 94,
TK_short = 20,
TK_signed = 21,
TK_sizeof = 56,
TK_static = 41,
TK_static_cast = 57,
TK_struct = 66,
TK_switch = 95,
TK_template = 49,
TK_this = 58,
TK_throw = 73,
TK_try = 81,
TK_true = 59,
TK_typedef = 42,
TK_typeid = 60,
TK_typename = 22,
TK_union = 67,
TK_unsigned = 23,
TK_using = 71,
TK_virtual = 33,
TK_void = 27,
TK_volatile = 31,
TK_wchar_t = 28,
TK_while = 84,
TK_integer = 61,
TK_floating = 62,
TK_charconst = 63,
TK_stringlit = 44,
TK_identifier = 1,
TK_Completion = 4,
TK_EndOfCompletion = 11,
TK_Invalid = 133,
TK_LeftBracket = 74,
TK_LeftParen = 5,
TK_Dot = 130,
TK_DotStar = 100,
TK_Arrow = 116,
TK_ArrowStar = 99,
TK_PlusPlus = 47,
TK_MinusMinus = 48,
TK_And = 14,
TK_Star = 13,
TK_Plus = 45,
TK_Minus = 46,
TK_Tilde = 10,
TK_Bang = 51,
TK_Slash = 101,
TK_Percent = 102,
TK_RightShift = 96,
TK_LeftShift = 97,
TK_LT = 69,
TK_GT = 80,
TK_LE = 103,
TK_GE = 104,
TK_EQ = 105,
TK_NE = 106,
TK_Caret = 107,
TK_Or = 108,
TK_AndAnd = 109,
TK_OrOr = 110,
TK_Question = 117,
TK_Colon = 77,
TK_ColonColon = 6,
TK_DotDotDot = 98,
TK_Assign = 82,
TK_StarAssign = 118,
TK_SlashAssign = 119,
TK_PercentAssign = 120,
TK_PlusAssign = 121,
TK_MinusAssign = 122,
TK_RightShiftAssign = 123,
TK_LeftShiftAssign = 124,
TK_AndAssign = 125,
TK_CaretAssign = 126,
TK_OrAssign = 127,
TK_Comma = 76,
TK_RightBracket = 128,
TK_RightParen = 75,
TK_RightBrace = 83,
TK_SemiColon = 43,
TK_LeftBrace = 70,
TK_typeof = 29,
TK___alignof__ = 64,
TK___attribute__ = 8,
TK___declspec = 9,
TK_MAX = 111,
TK_MIN = 112,
TK_vector = 3,
TK_pixel = 2,
TK_ERROR_TOKEN = 72,
TK_EOF_TOKEN = 131;
public final static String orderedTerminalSymbols[] = {
"",
"identifier",
"pixel",
"vector",
"Completion",
"LeftParen",
"ColonColon",
"asm",
"__attribute__",
"__declspec",
"Tilde",
"EndOfCompletion",
"operator",
"Star",
"And",
"bool",
"char",
"float",
"int",
"long",
"short",
"signed",
"typename",
"unsigned",
"_Complex",
"_Imaginary",
"double",
"void",
"wchar_t",
"typeof",
"const",
"volatile",
"restrict",
"virtual",
"auto",
"explicit",
"extern",
"friend",
"inline",
"mutable",
"register",
"static",
"typedef",
"SemiColon",
"stringlit",
"Plus",
"Minus",
"PlusPlus",
"MinusMinus",
"template",
"class",
"Bang",
"const_cast",
"dynamic_cast",
"false",
"reinterpret_cast",
"sizeof",
"static_cast",
"this",
"true",
"typeid",
"integer",
"floating",
"charconst",
"__alignof__",
"enum",
"struct",
"union",
"namespace",
"LT",
"LeftBrace",
"using",
"ERROR_TOKEN",
"throw",
"LeftBracket",
"RightParen",
"Comma",
"Colon",
"delete",
"new",
"GT",
"try",
"Assign",
"RightBrace",
"while",
"break",
"case",
"continue",
"default",
"do",
"export",
"for",
"goto",
"if",
"return",
"switch",
"RightShift",
"LeftShift",
"DotDotDot",
"ArrowStar",
"DotStar",
"Slash",
"Percent",
"LE",
"GE",
"EQ",
"NE",
"Caret",
"Or",
"AndAnd",
"OrOr",
"MAX",
"MIN",
"private",
"protected",
"public",
"Arrow",
"Question",
"StarAssign",
"SlashAssign",
"PercentAssign",
"PlusAssign",
"MinusAssign",
"RightShiftAssign",
"LeftShiftAssign",
"AndAssign",
"CaretAssign",
"OrAssign",
"RightBracket",
"catch",
"Dot",
"EOF_TOKEN",
"else",
"Invalid"
};
public final static boolean isValidForParser = true;
}

View file

@ -0,0 +1,18 @@
###############################################################################
# Copyright (c) 2009 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
Bundle-Name.0 = LR Parser Plug-in
Bundle-Vendor.0 = Eclipse.org
Bundle-Name.1 = LR Parser Plug-in
# built-in languages
language.name.c99= C99
language.name.isocpp= ISO C++

View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.cdt.core.language">
<language
class="org.eclipse.cdt.core.lrparser.xlc.XlcCLanguage"
id="c"
name="XLC C">
</language>
<language
class="org.eclipse.cdt.core.lrparser.xlc.XlcCPPLanguage"
id="cpp"
name="XLC C++">
</language>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="org.eclipse.cdt.core.lrparser.xlc.preferences.PreferenceInitializer">
</initializer>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
class="org.eclipse.cdt.internal.core.lrparser.xlc.ui.preferences.XlcLanguageOptionsPreferencePage"
id="org.eclipse.cdt.core.lrparser.xlc.ui.XlcLanguagePreferencePage"
name="XLC Language Options">
</page>
</extension>
<extension
point="org.eclipse.ui.propertyPages">
<page
category="org.eclipse.cdt.ui.newui.Page_head_general"
class="org.eclipse.cdt.internal.core.lrparser.xlc.ui.preferences.XlcLanguageOptionsPreferencePage"
id="org.eclipse.cdt.core.lrparser.xlc.ui.XlcLanguagePropertyPage"
name="XLC Language Options">
</page>
</extension>
</plugin>

View file

@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.lrparser.xlc.ui.preferences;
import org.eclipse.osgi.util.NLS;
public class PreferenceMessages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.lrparser.xlc.ui.preferences.PreferenceMessages"; //$NON-NLS-1$
private PreferenceMessages() {}
static {
NLS.initializeMessages(BUNDLE_NAME, PreferenceMessages.class);
}
public static String
XlcLanguageOptionsPreferencePage_link,
XlcLanguageOptionsPreferencePage_group,
XlcLanguageOptionsPreferencePage_preference_vectors;
}

View file

@ -0,0 +1,4 @@
XlcLanguageOptionsPreferencePage_link=These settings are project-specific. The settings listed here override <a href="org.eclipse.cdt.core.lrparser.xlc.ui.XlcLanguagePreferencePage">workspace-wide</a> language settings.
XlcLanguageOptionsPreferencePage_group=Support For XL C/C++ Language Extensions
XlcLanguageOptionsPreferencePage_preference_vectors=Support vector types

View file

@ -0,0 +1,130 @@
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.lrparser.xlc.ui.preferences;
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcLanguagePreferences;
import org.eclipse.cdt.core.lrparser.xlc.preferences.XlcPreferenceKeys;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.IWorkbenchPropertyPage;
import org.eclipse.ui.dialogs.PreferencesUtil;
/**
* TODO trigger reindex?
*
*/
public class XlcLanguageOptionsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, IWorkbenchPropertyPage {
private IAdaptable element;
private Button button_vectors;
public IAdaptable getElement() {
return element;
}
public void setElement(IAdaptable element) {
this.element = element;
}
public boolean isPropertyPage() {
return element != null;
}
public void init(IWorkbench workbench) {
// TODO Auto-generated method stub
}
@Override
protected Control createContents(Composite parent) {
Composite page = ControlFactory.createComposite(parent, 1);
if(isPropertyPage()) {
Link link = new Link(page, SWT.NONE);
link.setText(PreferenceMessages.XlcLanguageOptionsPreferencePage_link);
link.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
PreferencesUtil.createPreferenceDialogOn(getShell(), event.text, null, null).open();
}
});
}
Composite group = ControlFactory.createGroup(page, PreferenceMessages.XlcLanguageOptionsPreferencePage_group, 1);
button_vectors = ControlFactory.createCheckBox(group, PreferenceMessages.XlcLanguageOptionsPreferencePage_preference_vectors);
initCheckbox(button_vectors, XlcPreferenceKeys.KEY_SUPPORT_VECTOR_TYPES);
return page;
}
private void initCheckbox(Button checkbox, String prefKey) {
String preference = null;
if(isPropertyPage()) {
IProject project = getProject();
preference = XlcLanguagePreferences.getProjectPreference(prefKey, project);
}
else {
preference = XlcLanguagePreferences.getWorkspacePreference(prefKey);
}
if(preference == null) {
preference = XlcLanguagePreferences.getDefaultPreference(prefKey);
}
checkbox.setSelection(Boolean.valueOf(preference));
}
@Override
protected void performDefaults() {
button_vectors.setSelection(Boolean.valueOf(XlcLanguagePreferences.getDefaultPreference(XlcPreferenceKeys.KEY_SUPPORT_VECTOR_TYPES)));
super.performDefaults();
}
@Override
public boolean performOk() {
setPreference(XlcPreferenceKeys.KEY_SUPPORT_VECTOR_TYPES, button_vectors.getSelection(), getProject());
return true;
}
private IProject getProject() {
return isPropertyPage() ? (IProject)element.getAdapter(IProject.class) : null;
}
private static void setPreference(String key, boolean val, IProject project) {
if(project != null)
XlcLanguagePreferences.setProjectPreference(key, String.valueOf(val), project);
else
XlcLanguagePreferences.setWorkspacePreference(key, String.valueOf(val));
}
}